发送代码:
ORG 0000H
LJMP START
start:
MOV SCON, #0x50;0101 0000usart mode 1
ANL PCON, #0x7F;smod=0
MOV TMOD, #0x20;timer1 works as Baud rate producer
MOV TH1, #0xFD;SET Baud rete=9600,as core rate@11.0592MHz
MOV TL1, #0xFD;
SETB TR1; start timer counter
MOV (61H),P2 ;STORE P2 TO 61H
LOOP:
MOV A,(61H)
MOV (60H),P2;STORE P2 AT 98H
CJNE A,(60H),SEND ;A AND P2 DIFFER,JUM TO SEND
LJMP LOOP
SEND:
MOV A,(60H);UPDATE VALUE
MOV (61H),A;STORE A
MOV SBUF, A
JNB TI, $ ;WAITING FOR SENDING
CLR TI
LJMP LOOP
END
接收代码:
ORG 0000H
LJMP START
org 0023H;receive int add
LJMP RECEIVE
start:
MOV SCON, #0x50;0101 0000usart mode 1
ANL PCON, #0x7F;smod=0
MOV TMOD, #0x20;timer1 works as Baud rate producer
MOV TH1, #0xFD;Baud rete=9600,as core rate@11.0592MHz
MOV TL1, #0xFD;
MOV IE,#10010000B;enable all interrupt and usart interrupt
SETB TR1; start timer counter
SJMP $ ;wait
RECEIVE:
JB RI,HANDL ;RI==1,jmp to handel to change p1
RETI
HANDL:
MOV P1,SBUF
CLR RI ;clear flag
RETI
END
实验电路:
说明:
单片机U1发送给单片机U2,调整拨码开关,数据将发送给U2并改变U2的P1端口状态。
github:
github
原理推荐文章:
推荐