Hello,
Well, I've got my first microcontroller project *almost* working :) So this should be some kind of burglar alarm. It is otherwise working well, but it tends to freeze when it's counting either arming or alarm delay. It doesn't freeze everytime, but often, say, averagely every other time.
The program code below might be pretty long and complicated to analyze, but if someone would bother to tell why does that freeze, I'd be extremely grateful =)
The freezing happens when in "arming" or "triggered" loop on the main program, the variables "armDelay and "alarmDelay" are decremented by Timer 1 overflow interrupt.
Btw, as I'm still a newbie on both programming and using microcontrollers, I know that the program might be _far_ from ideal/optimal design, but I'm currently mostly interested just about that why does it freeze.
Thanks in advance for everyone having any thought...
#include #include #include #include #include #include #asm .equ __lcd_port=0x15 ;PORTC #endasm #define BLINKERS PORTA.0 //Blinkers (turn signals) control relay #define HORN PORTA.1 //Horn control relay #define CALL PORTA.2 //Call -signal for attached cell phone #define IGNITION PORTA.3 //Ignition relay #define SENSOR PINB.7 //Sensor input #define POWER PINB.6 //Ignition lock state input (1-active)
// global variables char key='A'; //tells the number of pressed key int m=4; //keypad row multiplexer unsigned char intToChar[4]={'A'}; //integer to be displayed is converted to char in this variable eeprom int correctCode[4]={2,3,4,5}; //the correct code is stored in this table int code[4]={'A','A','A','A'}; //entered code is stored in this table int newCode[4]={'A','A','A','A'}; //fed new code is stored in this table before verification int p; //code input pointer int t; //code comparison pointer char c; //code[4] resetting pointer bit enterCode=0; //if 0, "enter code" displayed bit correct=0; //turns 1 when correct code entered int okKey=0; //tells what to do when # (OK-key) pressed: //if 0, code[4] will be compared to correctCode and correct=1 if matched //if 1, code[4] string will be converted to integer and stored in setAlarmDelay //if 2, code[4] string will be converted to integer and stored in setArmDelay //if 3, code[1] will be stored in autoArm //if 4, code[4] will be stored to newCode[4] and re- entering requested //if 5, code[4] will be compared to newCode and stored in correctCode if matched bit horn=0; //horn cycler int hornCycle=3; //horn on-off cycle interval, to be decremented by timer int callTime=0; //call-signal pulse timing eeprom int setArmDelay=20; //delay before arming int armDelay=0; //variable to be decremented by timer eeprom int setAlarmDelay=30; //Delay before activating alarm int alarmDelay=0; //variable to be decremented by timer eeprom int arming=0; //sets 1 when in "arming" -loop eeprom int armed=0; //sets 1 when in "armed" -loop eeprom int triggered=0; //sets 1 when in "triggered" -loop eeprom int alarm=0; //sets 1 when in "alarm" -loop bit settingsCodeQuery=0; //sets 1 when in "settings code query" -loop of settings entry bit cancel=0; //if 1, settings will be cancelled bit settingsEntry=0; //sets 1, when in settings mode bit settings=0; //sets 1, when correct code entered in settingsCodeQuery eeprom int autoArm=1; //sets 1, if "auto arming" -feature is enabled, 0 if disabled bit noAutoArm=1; //Turns 1 when disarming, reset to 0 when POWER==1. if 1, //auto arming temporarily disabled until reset //(in order to prevent auto arming right after disarming before ignition //has been turned on one time) int n; //number of digits fed in code[4] in delay settings long int r; //calculated (n-t)th power of 10 //(used when converting a string into an integer in delaysettings) int e=0; //the exponent of 10 of a digit being calculated (n-t) //(used when converting a string into an integer in delay settings)
void nollaus() //resets code[4], its display, and input pointer p { for(c=0;c