| ??? 02/24/03 02:32 Read: times |
#39869 - fixed -- serial port Hello World problem Responding to: ???'s previous message |
Thanks Michael and Raghu! Turns out the solution was a little of both -- the max232 was indeed not wired up correctly (I can't count pins, evidently) and I think there may have been some problems in the code. Here's my final code, and it works great. The only thing that's weird is sometimes I need to turn it off and on a time or two to get HyperTerminal's attention. Not sure what that's about... --Sam
;8052 Serial port HELLO WORLD program
;Ran on a ATMEL AT89C52 at 11.059MHz wired to a MAX232CPE chip
;output to PC in HyperTerminal at 300 baud 8/N/1 with no flow control
.org 0x0000
mov PCON, #00H ;clear SMOD - baud rate NOT doubled
; so K = 1 in baud equation below
mov TMOD, #22H ;set Timers 1 and 0 to 8-bit auto-reload
mov TH1, #0xA0H ;sets timer 1 for 300 baud assuming 11.059MHz clock
; TH1 = 256 - ((K * OscFreq)/(384 * BaudRate))
; = 256 - ((1 * 11059000)/(384 * 300))
; = 256 - 95.99826388888
; = 160 = #0xA0H
setb TCON.6 ;same as setb TR1 - starts timer 1 running
mov SCON, #50H ;Serial port mode 1 - 8bit with variable baud
;receive enabled
;clears Transmit interrupt flag
start:
mov dptr, #message ;point the data pointer to the start of the message
clr a
movc a, @a+dptr ;get first letter to display
loop:
clr TI ;clear the "transmitted" bit
mov SBUF, a ;send the letter to the serial port
acall wait ;wait for letter to finish sending
inc dptr ;increment data pointer
clr a
movc a, @a+dptr ;get next letter to display
jz start ;jump back to the start of the message if we hit the end
sjmp loop ;otherwise send the next letter
wait:
jnb TI, wait ;loop until TI is set
ret
message:
.db "HELLO WORLD! ", 0 ;the zero is an end-of-string marker
|
| Topic | Author | Date |
| serial port Hello World problem | 01/01/70 00:00 | |
| RE: serial port Hello World problem | 01/01/70 00:00 | |
| It will work now | 01/01/70 00:00 | |
| fixed -- serial port Hello World problem | 01/01/70 00:00 | |
| Also try 9600 + baud | 01/01/70 00:00 | |
RE: Also try 9600 + baud | 01/01/70 00:00 |



