ORG 00H;
LJMP MAIN;
TEST EQU P3.5; ; TEST equals PORT3 bit 5. WILL this code ever be run??? the program jumps over it
MAIN:
MOV TMOD,#20H; ; TMOD: timer 1, mode 2, 8-bit reload
MOV TH1,#-3; ; TIMER 1 baud rate reload value
MOV SCON, #50H; ; MODE 1, 8 bits, enable receiver
SETB TR1; ; TIMER1 run
RECEIVE:
JNB RI,RECEIVE; ; jump to RECEIVE until RI = 1, when TI = 1 run code below
CLR RI; ; clear the RI flag
CLR TEST; ; clear TEST to 0
RET ; return RETURN from a call ???
END
I tested the the TEST variable and it worked, I can make sure that. About the RET, I tried to replace it with SJMP RECEIVE but nothing happened. One more thing as I mentioned above, I also tried to run the code and the sketch of other person who was successful in running the circuit with his code. But it did not work when I run in my laptop. Do you have any ideas about that ?Code:ORG 00H; LJMP MAIN; TEST EQU P3.5; ; TEST equals PORT3 bit 5. WILL this code ever be run??? the program jumps over it MAIN: MOV TMOD,#20H; ; TMOD: timer 1, mode 2, 8-bit reload MOV TH1,#-3; ; TIMER 1 baud rate reload value MOV SCON, #50H; ; MODE 1, 8 bits, enable receiver SETB TR1; ; TIMER1 run RECEIVE: JNB RI,RECEIVE; ; jump to RECEIVE until RI = 1, when TI = 1 run code below CLR RI; ; clear the RI flag CLR TEST; ; clear TEST to 0 RET ; return RETURN from a call ??? END
RECEIVE:
JNB RI,RECEIVE
CLR RI
CPL TEST ; change to compliment instead of clear
AJMP RECEIVE
I tried to replace CLR with CPL instruction and AJMP like your code but it still did not work... My circuit includes of a AT89C52 and a Virtual Terminal. TXD of terminal to RXD of 89C52. Still, I have no idea why my code did not work. I mean everything else about the instruction that I programmed for 8051 is fine and even the transmitter of UART. But it seem like the RI flag did not work ?? the SCON was set up in a right way to enable read.gram will just do this one time, because there is no loop to run. Not having Proteus to test the program I don't know why it doesn't work in Proteus. Regarding trying to get it to jump to receive at the end, to make a loop,
I fixed it by replacing it with a SJMP to make a loop. And I tried toggle the port as FenTrac mentioned above but it did not work too. The problem is that even if I run the sample code that works on the Youtube and worked with their circuit, it's still a no for my simulation on my laptop. The version of both Keil C and Proteus is not too old, I can make sure that. May be it's about my laptop. Thanks for your help!I'm no expert in AT89C52 code but if I understand your program, "RECEIVE" is a subroutine and it ends with a RET instruction to return back to wherever it was call from. You seem to jump to it though instead of calling it. If you jump to a subroutine the return address is not held on the stack so it won't know where to resume from. I suspect your code appears to work in real life because it crashes and resets rather than doing as you intended.
Brian.
cpl 0x85
.ORG 0x0000
LJMP MAIN; ; 02 00 03
MAIN:
MOV TMOD,#20H ; 75 89 20
MOV TH1, #-3 ; 75 8D FD
MOV SCON, #50H ; 75 98 50
SETB TR1 ; D2 8E
RECEIVE:
JNB RI,RECEIVE ; 30 98 FD
CLR RI ; C2 98
CPL 0x85 ; B2 B5
AJMP RECEIVE ; 01 0E
;END:
:03 0000 00 02 08 00 -crc-F3
:0C 0800 00 78 7F E4 F6 D8 FD 75 81 07 02 00 00 -crc-47
:10 0000 00 02 00 03 75 89 20 75 8D FD 75 98 50 D2 8E 30 98 -crc-49
:07 0010 00 FD C2 98 B2 85 01 0E -crc-4C
:00000001FF
0000 LJMP 0800 ;02 08 00
0800 MOV RO #7FH ;78 7F
CLR A ;E4
MOV @RO,A ;F6
DJNZ FD ;D8 FD
MOV 0X81, 07 ;75 81 07 (R0.1)
LJMP 0000 ;02 0000
; heres where the examples code listing begins
0000 LJMP 0003 ;02 00 03
MAIN:
MOV TMOD, #20H ;75 89 20
MOV TH1, #-3 ;75 8D FD
MOV SCON, #50H ;75 98 50
SETB TR1 ;D2 8E
RECEIVE:
JNB RI, RECEIVE ;30 98 FD
0011 CLR RI ;C2 98
CPL 0X85 ;B2 B5 (R3.5)
AJMP RECEIVE ;01 OE
The clock frequency that I modified for AT89C52 is 11.0592Mhz and baud rate in the code is 9600 which means 0% difference in reality. I think the problem is about my 8051 on Proteus because with all the possible way above (I think) are not worked.Hi,
Maybe a hardware problem? Microcontroller clock frequency?
Klaus
The clock frequency that I modified for AT89C52 is 11.0592Mhz and baud rate in the code is 9600 which means 0% difference in reality. I think the problem is about my 8051 on Proteus because with all the possible way above (I think) are not work.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?