adc for pic16f877a problem

Status
Not open for further replies.

kishan s m

Newbie level 5
Joined
Mar 31, 2011
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,351
hello friends;
i am new learner of pic.
i am using mplab 8.56v and HI-TECH C compiler.
i have done simple led blinking program.
now,i want to do programming of adc of pic16f877a.
i want to use simple 1 bit input as RA0 and output as PORTB or PORTD.
i want to display my output on hyper terminal.
please,send me the pgoram.
thank you.
kishan
 

i am not getting the output.
here is my code:
#include<pic.h>
void serial()
{
SPBRG=25;
SYNC=0;
BRGH=1;
SPEN=1;
TXEN=1;
}
int ADCvalue = 0;
void main(void)
{

serial();
TRISA =0x0FF;
TRISD=0x00;
TRISE=0x00;
ADCON0 = 0x05;
ADCON1 = 0x0CE;
while(1)
{
PORTA=0X01;
PORTD=0X00;
PORTE=0X03;
ADON=1;
GODONE=1;
while(GODONE!=0);
ADCvalue = (ADRESH*256) + ADRESL;
if(ADCvalue >= 204)
{ TXREG = '1';
while(TXIF==0);
}
else
{
TXREG = '1';
while(TXIF==0);
TXREG = 'L';
while(TXIF==0);
}
if(ADCvalue >= 409)
{
TXREG = '2';
while(TXIF==0);
}
else
{
TXREG = '2';
while(TXIF==0);
TXREG = 'L';
while(TXIF==0);
}
if(ADCvalue >= 614)
{
TXREG = '3';

while(TXIF==0);
}
else
{ TXREG = '3';
while(TXIF==0);
TXREG = 'L';
while(TXIF==0);
}
if(ADCvalue >= 819)
{
TXREG = '4';
while(TXIF==0);
}
else
{
TXREG = '4';
while(TXIF==0);
TXREG = 'L';
while(TXIF==0);
}
if(ADCvalue >= 1023)
{ TXREG = '5';
while(TXIF==0);
}
else
{
TXREG = '5';
while(TXIF==0);
TXREG = 'L';
while(TXIF==0);
}
ADON=0;
}
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…