CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

Usar PINES RA0- RA5 para ADC Pic16f877a

 
Post new topic   Reply to topic    CCS Forum Index -> CCS ICD / Mach X / Load-n-Go
View previous topic :: View next topic  
Author Message
SMF7



Joined: 07 Nov 2021
Posts: 4

View user's profile Send private message

Usar PINES RA0- RA5 para ADC Pic16f877a
PostPosted: Mon Nov 08, 2021 6:37 am     Reply with quote

I would like to know how I can activate the pins of a 16f877 such as RA0 to RA5 to function as inputs that allow me to capture the value of 2 respective sensors to store them in separate variables that later will be evaluated or used in relevant conditionals.

I have tried with the following code, but I only get reading through RA0.
Code:

#include<16f877a.h>
#device *=16
#device adc=10
#include <lcd.c>
#use delay(clock=4M)

#use fast_io(a)
#use fast_io(b)

float TempAmbiente, SRefe;


void main(){

//transform temperature and separate data receiving channels

set_tris_b(0b00000000); // I configure the pins for input or output, being 1 input and 0 output.
setup_adc_ports(RA0_ANALOG); // I allow the input of the data provided by the TempAmbiente sensor.
setup_adc_ports(RA1_ANALOG); // I try to read the reference signal
setup_adc(ADC_CLOCK_INTERNAL);
setup_COUNTERS(RTCC_internal.rtcc_div_1); // voltage division

// Turn on the LCD

lcd_init();
lcd_gotoxy(5,1); //posiciono
printf(lcd_putc, "Temperatura");
delay_ms(350);
lcd_init(); //Delete the display leaving it clean or initialized again.

while (true){

  TempAmbiente=(float) read_adc()/2; // here I read the PIN2.AN0 where is the ambient sensor
  lcd_gotoxy(5,1);
  printf(lcd_putc,"%f" , TempAmbiente); // I show the ambient temperature
  lcd_gotoxy(14,1);
  printf(lcd_putc,"Grados");
  delay_ms(200);

// I set the conditions for closing the loop

  if(TempAmbiente>=SRefe&& TempAmbiente<=SRefe){
    output_high(pin_b1); // Command a 1 to turn on the Red Led
    output_high(pin_b2); // Command a 1 to turn on the FanMotor V1
    output_low(pin_b4); // Command a 0 to turn off the Green Led

    // I print a message to let people know what is happening.
    lcd_gotoxy(5,2);
    printf(lcd_putc, "Disipando calor");
    delay_ms(200);
    }
  else{
    output_low(pin_b1); // Command a 0 to turn off the Red Led
    output_low(pin_b2);// I turn off the V1 Fan
    output_high(pin_b4);// I turn on the Green led
    //I am sending again a message to let you know what is going on.
    lcd_gotoxy(5,2);
    printf(lcd_putc, "Disipando Frio");
    delay_ms(200);
   }

  }
}

I'm really new to this and little by little is that with the manual and other information I try to get the project forward, since the assembly for the simulation is there but I lack that detail in the code, I would appreciate all the help possible.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> CCS ICD / Mach X / Load-n-Go All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group