HiI have been using STM8 and SDCC for about 2 months now.I'm facing an issue these last two days that I can't seem to figure out. The code is supposed to read an input port, confirm the key is pressed for 8 seconds, then call another routine for further 3 key inputs.There's a tim2 interrupt(overflow) - not shown in the code below - that runs every 125 mS. The interrupt is used to keep track of key pressed duration and to flash an LED when needed.
This is my code: //defines #define UPKey_Pin 6 //c6#define LU_PIN 5 //c5 //led thats supposed to be ON when the key is pressed in keypress function. #define upval 0xaa //up key value //variableschar tixnow, ticks, itix, six8cnt, ticker8, keyval; void main(void){ PC_CR1 |= (1 << UPKey_Pin); //define PortC6 as input port... <snip> if(!(PC_IDR & (1 << UPKey_Pin))) { //wait for timer tick delay to confirm key press, tixnow=ticks; while(tixnow==ticks); //ticks increases 8 times a second, in a tim2 interrupt, which also updates ticker15 and ticker8 if(!(PC_IDR & (1 << UPKey_Pin))) { //key press confirmed, timer started to verify, wait till key released, then run key function six8cnt=ticker8; //ticker8 changes every 8 seconds while(!(PC_IDR & (1 << UPKey_Pin))); //wait till key released if (ticker8!=six8cnt)keypress(); //if the count is more than 8 seconds long, run the function//Till here the code works just as it should, the key pressed for 8 seconds is recognized and the keypress function is called } } ....<snip>// Here the keyval returned is further processed.}//------------------------------------------------void keypress(void){ itix=ticker15; //ticker15 changes every 15 seconds while(itix==ticker15) { //The program reaches till here, I checked by switching ON another free test port bit. if(!(PC_IDR & (1 << UPKey_Pin))) { //wait for tick delay to confirm key press, tixnow=ticks; while(tixnow==ticks); if(!(PC_IDR & (1 << UPKey_Pin))) { PC_ODR |= (1 << LU_PIN); //set Led ON while(!(PC_IDR & (1 << UPKey_Pin))); //wait till key released keyval=upval; PC_ODR &= ~(1 << LU_PIN); //set LU OFF return; } }...<snip>//Here some other key press checks, with ditto code as above, which also don't get recognized.... } } Thanks and Warm Regards Shiv
_______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user