Hello,I have a huge problem and I can't fix it for a days so I desided to ask you for help.My program is very simple but as you said before it's not imune for errors.I'm having this message: *** error 65: access violation at C:0xFF00 : no 'execute/read' permission. And this is my code:
#include <REG2051.H>
#define SL P1_4 #define SR P1_5
#define A P1_6 #define EN P1_7
unsigned char F = 0x00; unsigned char PF = 0;
void Go_To_Sleep (void) { PCON = 0x01; }
void main (void) { IT0 = 0; EX0 = 1; EA = 1; Go_To_Sleep (); } void Ext_Int (void) interrupt 0
{ F=~F; if(F==0x00) { A=0; } else { A=1; } while(PF==0) { EN=1; if(A==0) { if(SR==1) { PF=1; } } else { if(SL==1) { PF=1; } } } EN=0; PF=0; } Thank you!
"when he finishes with interrupt and try to go back to Go_To_Sleep"
But, surely, when he "goes back" to Go_To_Sleep, he will go to the line after PCON=0x01 - won't he...?
Yes,that's right. So,is there any solution? Sorry about my english,I'm trying.
Have you placed a bucket or something below the main() function? Exactly what do you think will happen when your processor falls out from the main() function? Who/what do you expect to catch it?
Your processor does not have a desktop or a command line that will magically appear when main() ends. At least add an infinite loop around the sleep command.
"Yes,that's right. So,is there any solution?"
Yes - think about it: the problem is that the code returns from Go_To_Sleep, but you actually want it to repeat the PCON=0x01 instruction, don't you?
Read your processor's datasheet carefully - some require a few instructions before they will go back to sleep...
Yes,I wanted to but it never happened. I salved the problem, instead of using the Go_To_Sleep function I put the PCON=0x01 into the while loop and it's working good.At least I think so.
void main (void) { IT0 = 0; // Configure interrupt 0 for rising edge on /INT0 (P3.2) EX0 = 1; // Enable EX0 Interrupt EA = 1; // Enable Global Interrupt Flag while(1) { PCON=0x01; } }