8051如何从串口接收数据?我有4位数码管,如从串口发送1234,则数码管上显示1234。请给出程序,不会复杂的吧
ORG 0000h
AJMP Init
ORG 0030h
;---------------------------------------
; Initiation
;---------------------------------------
Init:
MOV TMOD, #022h
MOV SCON, #040h
MOV TH1, #0F3h
MOV PCON, #80h
MOV P0, #0ffh
SETB TR1
SETB REN
;---------------------------------------
; Event Check
;---------------------------------------
EvtChk:
JBC RI, RcvData
CLR RI
JMP EvtChk
;---------------------------------------
; Reveive Data
;---------------------------------------
RcvData:
MOV A, SBUF
Out1: CJNE A, #00110001b, Out2 ;Check ASSII code of 1
MOV P0, #11000000b ;Display '1' to 7segment
AJMP Dly
Out2: CJNE A, #00110001b, Out3 ;Check ASSII code of 2
MOV P0, #10110110b ;Display '2' to 7segment
AJMP Dly
Out3: CJNE A, #00110000b, Out4 ;Check ASSII code of 3
MOV P0, #11100110b ;Display '3' to 7segment
AJMP Dly
Out4: CJNE A, #00110001b, OutErr ;Check ASSII code of 4
MOV P0, #11001010b ;Display '4' to 7segment
AJMP Dly
OutErr: MOV P0,#00111111b ;Display 'E' to 7segment
AJMP Dly
Dly:
; CALL Delay
; Add your delay here if you want
LJMP EvtChk
;---------------------------------------
; End
;---------------------------------------
END
搂主,上面的刚写,知道在学校不易,多改改 跑跑就好了。
Display '3 ' to 7segment 的东西要根据你的输出来定
还有这里没有用中断,你也可以用中断来写