The problem I am having is getting the device to exit power down mode with the keyboard interrupt. The board comes out of IDLE mode fine but when I set PCON=0x02 instead of PCON=0x01 (i.e. power down mode instead of IDLE mode), the unit will not respond to a keyboard interrupt. (The program does not get past having the first 3 LEDS on). I am using the KEIL MCB900 board.
// Program to illustrate problem with device eaving POWER DOWN mode #include <REG932.H> void keypad() interrupt 7 // wake unit up! { int count=60000; int count2=8; KBCON=0; // reset the keyboard interrupt bit PCON=0x00; // return to NORMAL mode of operation EKBI=0; // disbale keypad interrupt P2=0x08; // set 4th LED on while (--count2) // simple delay to allow user to see 4th LED while (--count); } void main() { P2M1=0; // set all of port 2 to quasi - bidirectional mode P2M2=0; P0M1=0; // set port 0 to quasi - bidirectional P0M2=0; P2=0x07; // turn first three LEDS on port 2 on P0=0xFF; // set all of port 0 high, ready to be pulled low KBCON=0; // set test to be not equal to the pattern in KBPATN=0xFF; // pattern to be tested against. KBMASK=0xFF; // set which pins can cause an interrupt EA=1; // set overall interrupt bit EKBI=1; // enable the keyboard interrupt specifically PCON=0x01; // enter idle mode (0x01) or power down mode(0x02) while(1) { P2=0x01; // if execution reaches here, light LED 1 } }
P.S. Thanks in advance for any help.
Not being familiar with your derivative I can only think that there might be some bit somewhere in some SFR that needs to be modified to enable wakeup from powerdown in response to this interrupt? Have you tried getting it to wake in response to one of the 'standard' external interrupts? Why do you disable the keyboard interrupt in the ISR?
int count=60000; int count2=8; ..... while (--count2) // simple delay to allow user to see 4th LED while (--count
"the above gives you a delay of 60008" No it doesn't!
isn't it amazing what tricks a "smart coding style" can play on you. Now I see the "missing semicolon" and, of course, you are right Stefan. Why on earth is it so difficult to do
while (--count2) while (--count); // simple delay to allow user to see 4th LED or while (--count2)// simple delay to allow user to see 4th LED { while (--count); }
"OK, go ahead an say "you should have seen it"" No, I had to look pretty hard at it to convince myself it was right. I didn't comment on it myself as I imagine he just threw it in as a quick test - as nobody would normally use a delay loop in an ISR in 'real' code. They wouldn't. Would they?
They would, you know...