hey, im trying to brush up my skills by doing a couple of small exercises. I keep getting stuck on this one. Im trying to program my pic 16f688 such that it lights and LED when a switch is pressed. this is the code i have written.
#include <htc.h>
#define _XTAL_FREQ 4000000
#define SWITCH RC2
#define LED RC0
__CONFIG(MCLREN & UNPROTECT &WDTDIS);
void main()
{
TRISC = 0b00000100; //set rc2 as input and the rest as output
for(;
{
// PORTC = 0b00000000; //turn off everything. all low
if(RC2 == 1){
PORTC =0b00000001;
}
else{
PORTC =0b00000000;
}
}
}
The code compiles well, but when i put the chip on a breadboard and conect up everything according to this link (pg 22) https://www.electro-tech-online.com/custompdfs/2009/08/PIC_Base_C_1.pdf
the led just stays on forever. regardless of where the switch is connected.
Any suggestions?
Thanks heaps
im using a 16f688...if that helps.thanks!
#include <htc.h>
#define _XTAL_FREQ 4000000
#define SWITCH RC2
#define LED RC0
__CONFIG(MCLREN & UNPROTECT &WDTDIS);
void main()
{
TRISC = 0b00000100; //set rc2 as input and the rest as output
for(;
{
// PORTC = 0b00000000; //turn off everything. all low
if(RC2 == 1){
PORTC =0b00000001;
}
else{
PORTC =0b00000000;
}
}
}
The code compiles well, but when i put the chip on a breadboard and conect up everything according to this link (pg 22) https://www.electro-tech-online.com/custompdfs/2009/08/PIC_Base_C_1.pdf
the led just stays on forever. regardless of where the switch is connected.
Any suggestions?
Thanks heaps
im using a 16f688...if that helps.thanks!
Last edited: