INCLUDE 89C51.MC ;---------------------MAX232------------------------------- ; Register definitions. rBUFFER EQU 00h ; read data register wBUFFER EQU 01h ; send data register ;---------------------------------------------------------- (0000H): JMP on_reset ;-----------------------Serial Interrupt------------------- (0023H): JNB RI,ser_down MOV rBUFFER,SBUF ; read data CLR RI JMP int_end ser_down: MOV SBUF,wBUFFER ; send data CLR TI int_end: RETI ;---------------------------------------------------------- (00FFH): on_reset: ;Initialize Timer ;Baud rate table ;Fosc = 11.0592 MHz ;Baud rate TH1 TH1(hex) SMOD(PCON.7) ;300 160 A0 0 ;1200 232 E8 0 ;2400 244 F4 0 ;4800 250 FA 0 ;9600 253 FD 0 ;19200 253 FD 1 ;28800 255 FF 0 MOV TH1,#FDH ; baud rate 9600 MOV TMOD,#20H ; timer-1 in 8-bit auto reload MOV SCON,#50H ; receive enable CLR PCON.7 ; SMOD = 0 ; MOV IE,#90H ; Serial Interrupt 10010000b ENDLESS: CALL get_byte MOV A,rBUFFER MOV wBUFFER,A CALL send_byte JMP ENDLESS ;---------------------------------------------------------- ;Without interrupt ;---------------------------------------------------------- send_byte: MOV SBUF,wBUFFER ; send data SETB TR1 RS232BACK: JNB SCON.1,RS232BACK ; wait for TI CLR TF1 CLR SCON.1 RET ;---------------------------------------------------------- get_byte: SETB TR1 RS232B: JNB SCON.0,RS232B ; wait for RI MOV rBUFFER,SBUF ; get data CLR TF1 CLR SCON.0 RET ;-----------------------------------------------------------