I've been learning about how to use the a/d ports on a 16F877A . I have enabled the analog ports and have put two power supply (0-5V) on RA0 and RA1 . The result of the A/D conversion has then been placed upon a 2 Line lcd display. But for some reason when you adjust RA0 it also adjust RA1 and vice versa. They never seems to be two independant readings . I have a 10K resistor to ground on each port and a 1k resistor upon the incoming voltage but can'nt get them to work as two independant channels.
Heres my the code
Code: Select all
#include <system.h>
unsigned char ADCRESL@0x9e; // control reg for A/D
unsigned char ADCRESH@0x1e;
char display1_value (int value,int position) // value of a/d result and position
{
unsigned char hunds, tens, units;
// first get the digits
units = value % 100 ;
hunds = value / 100 ;
tens = units / 10 ;
units = units % 10 ;
// now display them
if(portd==00000110b)// if press closed and RF ON
{
lcd_cursor(position,1);// Compacting numbers for more space on screen //
lcd_print_ch ( '0' + hunds ) ;
lcd_print_ch ( '0' + tens ) ;
lcd_print_ch ( '0' + units ) ;
}
else
{
lcd_cursor(5,1);
lcd_print (clear) ;
}
}
int read_adc0 (char adcon_0 ) // Main A/D conversion sub
{
unsigned char h, l =0;
int result=0;
adcon0 = adcon_0; /* enable the converter and start */
while ( adcon0 & 0x04 );//spin while the conversion runs
h = ADCRESH;
l = ADCRESL;
//m movwf _l_read_adc0;
result = (256 * h) + l; // Add high byte-to-low
return result;
}
char ad_Channel_0() //Channel_0 of A/D PORT RA0 Set for forward power readback
{
int CH0_adcon0=0x05;
int result=0;
result= read_adc0(CH0_adcon0);// Send A/D channel for conversio and get result
display1_value(result,5); // Send a/d result and where to place upon the screen
}
char ad_Channel_1 () //Channel_0 of A/D PORT RA1 Set for reflected power readback
{
int CH1_adcon0=0x0d;
int result=0;
result= read_adc0(CH1_adcon0);// Send A/D channel for conversio and get result
display1_value(result,13); // Send a/d result TO LCD display and position on screen
}