#include
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000
#endif
__CONFIG(FOSC_INTRCCLK & WDTE_OFF & MCLRE_OFF);
void main(void)
{
GPIO=0;
CMCON = 0x07; // turn off comparators
TRISIO=0b00001000;
char eepromvar;
//int state=0;
char effect[4] = {0x00,0x04,0x02,0x06};
//int toggle=0;
eepromvar=EEPROM_READ(0x00);
GPIO=effect[eepromvar];
int enterthedragon=0;
while(1){
//__delay_ms(10);
if(GP3==0)
{
if(enterthedragon==0)
{
for(int i=0;i<2000;i++)
{
__delay_ms(1);
}
//__delay_ms(2000);
eepromvar=EEPROM_READ(0x00);
eepromvar++;
//state++;
if(eepromvar>0x03){
eepromvar=0;
}
EEPROM_WRITE(0x00,eepromvar);
enterthedragon=1;
//__delay_ms(10);
}
while(GP3==0);
}
if(GP3==1)
{
enterthedragon=0;
eepromvar=EEPROM_READ(0x00);
GPIO=effect[eepromvar];
//__delay_ms(10);
}
}
}
___________________________________________________________________
Hi!! I want to write a program for PIC 12F629 chip and I completely new to this. Well, I actually know programming in general but I don't know how exactly I should program for PIC chip. Either way, I want to write a program that flashes particular LEDs in a sequence. There are 4 LEDs connected to the chip and all LEDs are controlled by a switch that is connected to 1 input pin in PIC chip.
Here's the idea: when button is pressed for less than 2 seconds, nothing gets switched but if the button is held for at least 2 seconds, another pattern on LEDs gets switched to the next one.
This is my code that doesn't really work. Everything goes, sometimes program automatically switches pattern on its own after 2 seconds, sometimes it resets to 0 and so on..... I use MPLAB IDE Hi Tech C Compiler. Here's what the unstable code looks like right now:
Anyone have any ideas how I should implement a timer that works properly or what changes I should do?? Please for reply. Any advices are strongly appreciated!! Many thanks in advance!!