Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 10th September 2007, 08:03 AM   (permalink)
Default PIC16f877 error

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 .
flemmard is offline  
Old 10th September 2007, 10:50 AM   (permalink)
Default

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 by eng1; 11th September 2007 at 04:40 PM.
eng1 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Need help with Intel Assembly Language and PIC16F877 avinsinanan Micro Controllers 10 4th March 2008 11:02 AM
Pspice LED Error kogula14 Electronic Projects Design/Ideas/Reviews 3 14th March 2007 05:03 AM
Need some help with a code provided by ATMEL ikalogic Micro Controllers 1 23rd January 2007 03:46 PM
Z8 Encore Error index out of range mootaccount Micro Controllers 2 17th October 2006 03:23 PM
Help in programming PIC16F877..... Azhar Ali chohan Micro Controllers 3 24th June 2003 12:08 PM



All times are GMT. The time now is 06:49 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker