I am using the simulator of the uvision2. According to the debugger the value of c doesn't change (I am using the serial peripheral) and the debugger never execute the Start_bit = 1; even though the SBUF = 0x46.
char c ; void SerialPort(void) interrupt 4 using 2 { if (RI == 1) { c = SBUF; if(SBUF==0x46) Start_bit = 1; RI = 0; } }
The 8051 has a lot of special registers. Each of these has a name: R0 for register 0, A for accumulator, B for the B-register, and C for the carry flag. When you display or watch the variable c, you are actually watching the carry flag. To watch your variables that have the same name as 8051 registers, you must escape them with a back-quote ('). For example: 'c Could this be the problem behind c never changing? Jon
This is the extention of the first interrupt function, but steel according to the simulator debugger ArrLen and chr stay with their init values after the assignment ArrLen = SBUF; void SerialPort(void) interrupt 4 using 2 { if (RI == 1) { if(ArrLenFlag==0) // The first value. { ArrLen = SBUF; ArrLenFlag = 1; } else { if(SBUF=='S') // The start char. { Start_bit = 1; SaveData(1000); SaveData(1000); } else { chr = SBUF; SaveData(chr) // Save the data. } } RI = 0; } } Thank for your help Kobi
what is IE ? what id SCON ?
The SCON = 0x50; IE = 1; Thank you very much for your help
IE = 1 guarantees that you will not get any interrupts. Have a look at <a href="" target="_blank">http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_PROG_GUIDE_1.pdf">the proframmers reference manual</a> and set the SFRs ciorrectly. Erik
Hi I finnaly understood that the local variable is changed to zero and didn't stay at zero (which means that it doesn't succcefuly read the SBUF???). here are all my init values.
TMOD = 0x20; TH1 = 0xFB; // baud ~19200; TR1 = 1; SCON = 0x50; IE=0x90; EA = 1; ES = 1; REN = 1; RI = 0; void SerialPort(void) interrupt 4 using 2 { while(!RI) { if(ArrLenFlag==0) { ArrLen = _getkey (); ArrLenFlag = 1; } else { if(_getkey()=='S') { Start_bit = 1; SaveData(1000); SaveData(1000); } else { chr = _getkey (); SaveData(chr); } } RI = 0; TI = 0; } }