Hello!
I've had some experience in PIC programming, but want to do more complex stuff (take over the world! ). I took some classes in Boulder, CO with SparkFun's summer school but I wanted to get started in PICs now (they did arduino). It took me more than a couple years to understand everything, when I had time, but now I think things are starting to click. This is intense stuff, and very complex. I've been messing around with LEDs and stuff, which has been very fun, and now I'm working on an automatic PIC switch. I found this tutorial on Gooligum which worked for me!
https://www.electro-tech-online.com/custompdfs/2010/11/PIC_Mid_C_3.pdf
I'm doing a mobile project, which will basically turn on a device (turn on a relay to turn on device). Since I found that tutorial, I've bought the 12F629, because that's what they use. But I want to have the PIC sleeping while it's waiting for the pushbutton switch to be pressed. I'm using Hi Tech compiler:
That doesn't work (go figure....) so could anyone PLEASE help me?
I've had some experience in PIC programming, but want to do more complex stuff (take over the world! ). I took some classes in Boulder, CO with SparkFun's summer school but I wanted to get started in PICs now (they did arduino). It took me more than a couple years to understand everything, when I had time, but now I think things are starting to click. This is intense stuff, and very complex. I've been messing around with LEDs and stuff, which has been very fun, and now I'm working on an automatic PIC switch. I found this tutorial on Gooligum which worked for me!
https://www.electro-tech-online.com/custompdfs/2010/11/PIC_Mid_C_3.pdf
I'm doing a mobile project, which will basically turn on a device (turn on a relay to turn on device). Since I found that tutorial, I've bought the 12F629, because that's what they use. But I want to have the PIC sleeping while it's waiting for the pushbutton switch to be pressed. I'm using Hi Tech compiler:
Code:
#include <htc.h>
#define _XTAL_FREQ 4000000
/***** CONFIGURATION *****/
// ext reset, no code or data protect, no brownout detect,
// no watchdog, power-up timer enabled, 4MHz int clock
__CONFIG(MCLREN & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);
#define nB_LED 1 // indicator LED on GP1
#define nBUTTON 2 // switch on GP2
unsigned char sGPIO; // shadow copy of GPIO
void main()
{
TRISIO = ~(1<<nB_LED); // configure LED pin (only) as an output
IOCB |= 1<<nBUTTON; // Enable IOC nBUTTON intput
GPIO = 0; // start with LED off
sGPIO = 0; // update shadow
GPIE = 1; // enable port change interrupt
ei(); // enable global interrupts
while(1)
{
GPIO = sGPIO;
SLEEP();
}
}
void interrupt isr(void)
{
GPIO;
GPIF = 0;
if(GPIO & 1<<nBUTTON)
{
sGPIO = 0x02;
_delay(100000);
sGPIO = 0x00;
_delay(100000);
}
}
That doesn't work (go figure....) so could anyone PLEASE help me?