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!
#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; }
If you're running in the Simulator, are you sure that this actually works in the Simulator...?
You need to adopt a consistent style for indenting!
In particular, whether the braces are indented to the same column as the code they enclose, like this:
(personally, I hate this)
Or whether the braces are indented to the same column as the controlling code, like this:
(personally, I much prefer this)
I think it would also be better to reduce the size of each indenting "step"; eg, 4 characters instead of 8...
Ok,it's like this. When I run the program in the main he calls Go_To_Sleep when he shuts down the device,and stays that way. Than when I trigger the P3.2 pin he goes to interrupt code and do everything that I wanted to do,but when he finishes with interrupt and try to go back to Go_To_Sleep and do the line with PCON=0x01; disassembly windows apears with message ***error 65...
"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; } }