Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.

Latest threads

New Articles From Microcontroller Tips

Back
Top