PIC16f877 error

Status
Not open for further replies.

flemmard

New Member
Hi, can you guys tell me what's wrong in this C code.

Code:
#include <pic1687x.h>
#include<pic.h>


void main(void)
{
 
 TRISA = 0xFF; //analog input
 TRISE = 0xFF; //analog input
 TRISB = 0x00;
 TRISC = 0x00;
 TRISD = 0x00;
 ADCON1 = 0x00; //port A and E as analog io
 ADCON0 = 0x00;
 ADGO = 1;
 while(ADGO)
 continue;
 RBIE = 1;				// enable Port B change interrupt
 PEIE = 1;				// enable peripheral interrupt
  GIE = 1;
 PORTB = 0x00;
 PORTC = 0x00;
 PORTD = 0x00;

 while(1)
{
 if(RA0 == 1)  //INPUT FROM PUSH BUTTON
{
  RC0=1;      // OUTPUT TO LED 
  RC1=1;
}
else
{
PORTC =0x00;   
}
}
}

I'm trying to output LED when input from push button is one .
 
You configured AN0 as analog input, while it should be a digital input. Change the ADCON1 settings.

Remove the following lines:
Code:
ADGO = 1;
while(ADGO==1)
         continue;

You must add proper configuration settings too.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…