|
org 0000h
sjmp start
org 000bh
ljmp time0
org 0030h
start:
mov sp,#70h;initialize stack
mov scon,#40h ;选择串口工作于方式1
mov tmod,#21h ;定时器T1 设置为工作方式2,用作波特率发生器 ,time0 use mode 0
mov tl1,#0f4h ;按照波特率为2400 计算初值
mov th1,#0f4h ;把计数初值送入常数缓冲器
mov th0,#3ch;
mov tl0,#0b0h; 50ms
xor a,#0ffh;
mov 20h,a ;time0 interrupt times
mov pcon,#80h ;smod=1,波特率变成4800
setb tr1 ;启动定时器T1
setb tr0; setup time0
setb ea;enable globla interrupt
setb et0;enable time0 interrup
;以下判断是否按键k0 按下
wait1: jb p3.4,wait1 ;k0 没有按下,等待
acall del10ms ;延时10ms 去抖动
jb p3.4,wait1 ;再次查询k0,是抖动返回
wait2: jnb p3.4,wait2 ;等待按键弹起
mov a,p1 ; p1口送到a
mov sbuf,a ;发送信息,传送的一帧信息为:0+P1+1
ajmp wait1 ;返回继续查询k0 是否按下
del10ms: mov r7,#20 ;延时10ms 子程序
del1: mov r6,#0ffh
del2: djnz r6,del2
djnz r7,del1
ret
time0:
nop
nop
push a;
push psw;
mov th0,#3ch;
mov tl0,#0b0h; 50ms
mov a,20h;
inc a;
cjne a,#200,ne; 10s
mov a,p0;
mov sbuf,a;
nop
nop
mov a,p1;
mov sbuf,a;
nop
nop
mov a,p2;
mov sbuf,a;
mov 20h,#00h ;reset counter
pop psw;
pop a;
reti
ne:
mov 20h,a
pop psw;
pop a;
reti
end
几年没写51汇编了,自己检查一下错误 |
|