Hi,
To start off with I am using PIC12F629 and Hi-tech C Compiler in MPLAB. My other code does work with blinking of light and stuff. I am using a Wouter chip instead of Promate to place Hex file on the chip. That is why in my config I and my config bits with 0x31ff which is required by wouter.
Now I am trying to create a very simple program that starts off in Sleep mode, wakes up when watch dog timer overflows, turns on gpio1 for couple of seconds and then goes back into sleep mode until the next wdt overflow occurs. It is of course not working. I would really appreciate it if someone can take a look at my few lines of code and tell me what I am doing wrong here. What I have read so far is that before going into sleep next instruction is prefetched hence when pic (12f629) is woken up it starts at the instruction after sleep. In my case that would be the function call.
Code:
#include <pic.h>
__CONFIG(0x0012 & 0x31FF); //Config bits--wd on, inter osc
unsigned int counter = 0;
unsigned int wake_limit = 10000;
void WakeUp()
{
counter = 0;
GPIO = 0b00000010;
while (counter < wake_limit)
{
counter++;
}
}
void main()
{
OPTION = 0b00001111; //assign prescaler to wdt
TRISIO = 0x00;
GPIO = 0x00;
for(;
{
GPIO = 0b00000001;
CLRWDT();
SLEEP();
WakeUp();
}
}
To start off with I am using PIC12F629 and Hi-tech C Compiler in MPLAB. My other code does work with blinking of light and stuff. I am using a Wouter chip instead of Promate to place Hex file on the chip. That is why in my config I and my config bits with 0x31ff which is required by wouter.
Now I am trying to create a very simple program that starts off in Sleep mode, wakes up when watch dog timer overflows, turns on gpio1 for couple of seconds and then goes back into sleep mode until the next wdt overflow occurs. It is of course not working. I would really appreciate it if someone can take a look at my few lines of code and tell me what I am doing wrong here. What I have read so far is that before going into sleep next instruction is prefetched hence when pic (12f629) is woken up it starts at the instruction after sleep. In my case that would be the function call.
Code:
#include <pic.h>
__CONFIG(0x0012 & 0x31FF); //Config bits--wd on, inter osc
unsigned int counter = 0;
unsigned int wake_limit = 10000;
void WakeUp()
{
counter = 0;
GPIO = 0b00000010;
while (counter < wake_limit)
{
counter++;
}
}
void main()
{
OPTION = 0b00001111; //assign prescaler to wdt
TRISIO = 0x00;
GPIO = 0x00;
for(;
{
GPIO = 0b00000001;
CLRWDT();
SLEEP();
WakeUp();
}
}