I've got a problem. I've posted it yesterday but it was probably lost in text.
static void Nastav_seriovy_kanal (void) { SCON = 0x50; TMOD = TMOD | 0x20; TH1 = 0xF4; TL1 = 0xF4; ES = 1; TR1 = 1; } static void Preruseni_seriovy_kanal (void) interrupt 4 { if (RI == 1) { RI = 0; if(SBUF == 'A') putchar('Q'); } if (TI == 1) TI = 0; }
"I've posted it yesterday but it was probably lost in text." Rather than just re-post it, how about supplying more information? That way someone might be able to offer some informed help! Like specifying the toolset, for a start! "it doesn't work?" Does it build without errors and warnings? What do you think it should do? What does it actually do? How have you tested it?
Putchar procedure doesn't work as I expected. In my opinion and I hope it's clearly said in that source code I've posted, it should work as follows. When 'A' character is received through serial port of x51 processor it sends a 'Q' character back. But it won't send anything back. There are no errors or warnings. Serial port is functional.
I could simply change it as follows.
if(SBUF == 'A') SBUF = 'Q';
In my opinion and I hope it's clearly said in that source code I've posted, It doesn't say anything in your source code, as there are no comments. Someone who actually goes through the trouble of trying to understand the source code might figure it out. However, please be aware that understanding uncommented source code is very difficult - and even more so for someone who is not the author of the code. That aside, let's look at the problem. Did you set a breakpoint in the ISR to see if it is actually called ? Your code excerpt does not show the EA bit being set anywhere, but I would guess that you've thought of that and do it somewhere else in your code. Did you have a look at the source code of the putchar function ? It should be in C51/lib somewhere. Do you call putchar() from anywhere else in the program ? The function is _not_ reentrant, so if you call it in the normal program and in an ISR without taking some precautions, problems are pretty much guaranteed.
"It doesn't say anything in your source code, as there are no comments." Even the function names aren't in English!
View all questions in Keil forum