?? rs232.asm
字號:
;Commulication Between 89C2051 and PC by RS232
;fosc=12Mhz,BPS=2400
;1Bit START,8Bit DATA,1Bit STOP
;Time count N=230=E6H
DELY1 EQU 0BH
DELY2 EQU 0CH
DELY3 EQU 0DH
DELY4 EQU 0EH
ORG 0000H
AJMP MAIN ;Initial program
ORG 0023H
AJMP SERVE ;Serve port interrupt routine
MAIN: MOV TMOD, #20H ;T1 setup mode 2 (auto reload)
MOV TH1, #0E6H ;time count n=E6H
MOV TL1, #0E6H
MOV SCON, #50H ;serve port setup mode 1 (8bit)
MOV PCON, #80H ;SMOD=1
SETB TR1 ;start timer T1
SETB EA ;enable interrupt
SETB ES ;enable serve port interrupt
MOV P1, #7FH
CLR RI
;Rwait: JNB RI, Rwait
; MOV A, SBUF
; CLR RI
; CPL P1.6
; CPL A
; MOV SBUF, A
; AJMP Rwait
; MOV A, #78H
;Msend: jb p3.5, Msend
; clr ti
; MOV SBUF, A ;send bake data to PC
; cpl p1.6
;Mwait: JNB TI, Mwait ;if sender no empty,wait
; CLR TI
; ACALL D.2S
; acall d.2s
; acall d.2s
MEND: AJMP Mend
SERVE: CLR EA ;off interrupt
CLR RI ;clear recrive interrupt flag
PUSH DPH ;bakeup state
PUSH DPL
PUSH ACC
Recrive:MOV A, SBUF ;recrive PC data
CPL A
CPL P1.6
Send: MOV SBUF, A ;send bake data to PC
Wait: JNB TI, Wait ;if sender no empty,wait
CLR TI
Return: POP ACC ;restore state
POP DPL
POP DPH
SETB EA ;on interrupt
RETI ;return
D.2S: MOV DELY1, #20
D.2S_1: MOV DELY2, #248
D.2S_2: DJNZ DELY2, D.2S_2
DJNZ DELY1, D.2S_1
RET
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -