I have encountered some very serious problem in Megawin MG84FG516 controller using C51 compiler.
In my code I am using three interrupts in the priority as follows:
1 - Serial port 0 2 - Timer 0 to generate 300 us interrupt. 3 - Timer 1 to generate 5 ms interrupt.
Actually there are few functions like keypad scanning , battery power checkup, and other hardware related functionalities which are carried out in the 5 ms timer 1 interrupt.the status of these hardware functions are checked by the status of the global variable in the main program and accordingly the task is done.the values of global variable gets set with the continuous polling of status of pins in 5 ms interrupt routine.
The serial port job is only to get the data and to transmit the data without loosing any of it and therefore has been provided the top priority.
Now I have two arrays of 200 bytes size each for the serial port.
Now the problem which I am getting is that my global variables values are getting set in the program which is a very abnormal behaviour.
Actually this is like this suppose I have a logic like this:
Initialize(void) {
MsgCtr = 0;
................... .......................
}
if(MsgCtr!=0) {
MsgCtr --; ...............
............... do so and so
and
if(WorkCode == 6) { MsgCtr = 11;
SO what here has to happen actually is that the message counter variable gets initialized only when workcode condition gets satisfied and rest of time it remains 0.
but in my code when I saw in the debugger mode I got that the value of the message counter variable gets set without entering into the workcode which is impossible case as this is the only route to change or initialise the MsgCtr t0 11.
What I got is that it gets initialised to some garbage variables randomly like sometimes to 0x64 or to 0xFF or to 0x04 and so on as many times I run the debugger.
So can you tell me that why this is happening actually.
why my global variables locations are not safe and picks up the garbage values without any logic.
Thanks
Hi WesterMark
Thanks for your reply.
the buffer in the UART ISR is well under limit like this:
void serial_int(void) interrupt 4 { if(RI0) {
RI0 = 0; if(temp<MAX_SIZE) {
array_msg[temp]= S0BUF; temp++;
if(temp>(MAX_SIZE-5)) temp = 0; } }
So I think the array buffer would not overflow.
and for your next option I would say yes there are warnings like:
warning L15: Multiple calls to functions. in the build menu
So is this the problem or something else there would be.
Also I want to ask that I want to see the memory mapping of functions and the global variables memory addresses , so what procedure should I follow and how can I locate the address of each variables and functions in teh source file as I can get the address of array in the debugger watch window but not of global variables.