單片機(jī)匯編實(shí)驗(yàn)五-2:單片機(jī)與PC機(jī)串行通信實(shí)驗(yàn)
//This is the fifth_2programof homework
//This is made by WQ Data:2013/3/4/
ORG 0000H
AJMP MAIN
ORG 0023H //0023H 串口中斷程序的入口地址
AJMP Transfer
ORG 000BH //000BH 計(jì)時(shí)器程序T0入口地址
AJMP WT0
MAIN:
MOV TMOD,#21H //定時(shí)器的工作方式寄存器
MOV TH0,#4CH //定時(shí)器0
MOV TL0,#00H //定時(shí)器0
MOV R3,#40 //R3做一個(gè)計(jì)數(shù)器
SETB EA //開總中斷
SETB ET0 //允許計(jì)時(shí)器
SETB TR0 //開啟計(jì)時(shí)器0
MOV TH1,#0FDH
MOV SCON,#50H ;傳口工作方式1,允許中斷接受
SJMP $
ORG 0100H
WT0: MOV TH0,#4CH //計(jì)時(shí)器0置數(shù)
MOV TL0,#00H
DJNZ R3,RETN //1秒鐘到來了
MOV R3,#50
SETB ES //打開串口中斷
SETB TR1 //打開定時(shí)器1
MOV R1,#30H
MOV @R1,#89H
MOV R1,#030H
MOV A,@R1
MOV SBUF,A //將內(nèi)存中的數(shù)據(jù)傳送給計(jì)算機(jī)
RETN:RETI //中斷子程序的返回指令
Transfer:
JNB TI,$
CLR TI
MOV P1,A
RETI
END
評(píng)論