hi, i am newbie in programming. I want to make a program in c for pic 16f887. In this program i am using port A RA0 pin as analog input and switching led. Here my intention is to apply sin wave of 5v to analog pin and comparing it with 3v and if its greater than it then led will be on. I made a program with microC Pro and its giving errors kindly help me in making this program functional.
My program
My program
Rich (BB code):
led sfr sbit porta.ra1 // declaring port A pin 1 as led
unsigned char val; // declaring 8 bit variable val
void main()
{
porta=0x00; // clearing port A
ansel=0x01; // making Port A pin 0 as analog input
trisa=0x01; // making Port A pin 0 as input and other output
while(1)
{
adcon1=0x00; // cleared all bits of adcon1
adcon0=0b11000001; // using internal rc of pic and enabling adc
adresh=0x00; // adresh register is cleared
godone=1; // starting conversion
while(godone=1); // waiting till conversion is complete
val=adresh; // putting the value of conversion into val
if(val<3) // comparing with 3 volts
led=0;
else
led=1;
}
Last edited by a moderator: