PDA

View Full Version : PIC16F684 - Turn ON LED on RC1 when a Switch is Pressed on RA1



rohitk
- 14th October 2010, 18:27
Hello,

just a simple program that wud'nt work!!!

I would appreciate if someone would help me debug.

Thanks,
Rohit

My Code:
#include <htc.h>
#define _XTAL_FREQ 4000000 // oscillator frequency for _delay()

/***** CONFIGURATION *****/
// ext reset, no code or data protect, no brownout detect,
// no watchdog, power-up timer enabled, 4MHz int clock

__CONFIG(MCLRDIS & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);

/***** MAIN PROGRAM *****/

void main()
{
TRISA = 0b00000010; // RA1 = Switch Input - Switch is pulled high externally to 5V
ANSEL = 0b00000000; // RA1 = Digital Input
TRISC = 0b00000000; // RC1 = Output
PORTC = 0b00000000; // Initially led off
for(; ;)
{
if (RA1==1) //
PORTC = 0b00000010; // led on - RC1
}
}

ScaleRobotics
- 14th October 2010, 18:33
I get a lot of errors trying to compile it with PicBasic. But it looks like it is written in C. There are a lot of C forums out there though. You probably will have much better luck there.

WARNING Line 23: Bad token "{".
WARNING Line 29: Bad token "{".
WARNING Line 32: Bad token "}".
WARNING Line 33: Bad token "}".
ERROR Line 11: Syntax error. (Untitled.pbp)
ERROR Line 12: Syntax error. (Untitled.pbp)
WARNING Line 12: 4000000 Numeric overflow, value truncated. (Untitled.pbp)
ERROR Line 14: Syntax error. (Untitled.pbp)
ERROR Line 15: Syntax error. (Untitled.pbp)
ERROR Line 16: Syntax error. (Untitled.pbp)
ERROR Line 18: Syntax error. (Untitled.pbp)
ERROR Line 20: Syntax error. (Untitled.pbp)
ERROR Line 22: Syntax error. (Untitled.pbp)
ERROR Line 24: Syntax error. (Untitled.pbp)
ERROR Line 25: Syntax error. (Untitled.pbp)
ERROR Line 26: Syntax error. (Untitled.pbp)
ERROR Line 27: Syntax error. (Untitled.pbp)
ERROR Line 28: Syntax error. (Untitled.pbp)
ERROR Line 30: Bad expression. (Untitled.pbp)
ERROR Line 30: Bad expression or missing THEN. (Untitled.pbp)
ERROR Line 30: IF without a matching ENDIF. (Untitled.pbp)
ERROR Line 31: Syntax error. (Untitled.pbp)