SMF7
Joined: 07 Nov 2021 Posts: 4
|
How use RA to RA5 pins for ADC in PIC16F877A |
Posted: Mon Nov 08, 2021 6:39 am |
|
|
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. |
|