TIMER0在MODE2的计数工作方式程序
org 00h
jmp start
start: MOV sp,#60h ;设置堆栈
MOV scon,#50h ;uart工作在mode1
MOV tmod,#20h ;timer1工作在mode2
MOV th1,#0e6h ;波特率为1200
setb tr1 ;启动timer1
sCAN0: MOV r3,#0f7h ;键盘扫描初始值
scan: jb ri,uart ;是否有接收tnc的数据
MOV r1,#00h ;table取码指针
scan1: MOV a,r3 ;输出行扫描
MOV p1,a
MOV a,p1
MOV r4,a
setb c
MOV r5,#04h ;扫描4列
l1: rlc a
jnc keyin ;c=0表有键按下
inc r1 ;c不等于0,未按则取码指针加1
djnz r5,l1 ;扫描下一列
MOV a,r3 ;扫描下一行
setb c
rrc a
MOV r3,a
jc scan1 ;4行扫描完?
jmp scan0
keyin: MOV r7,#200 ;消除抖动
d2: MOV r6,#248
djnz r6,$
djnz r7,d2
d3: MOV a,p1 ;按键放开否?
xrl a,r4
jz d3
MOV dptr,#table
MOV c a,@a+dptr
MOV 20h,a ;暂存入ram(20h)
xrl a,#45h ;是否按"e"键
jz trans1 ;是则发送一串字码
MOV a,20h ;将按键值ascii码发送给tnc
MOV sbuf,a
cpl a
MOV p2,a ;输出至p2显示
jmp scan0
uart: MOV a,sbuf ;接收到tnc的数据,将sbuf载入aCC
cpl a
MOV p0,a ;输出至p0显示
clr ri ;清除ri
jmp scan
trans1: MOV r0,#00h ;设定本机站号
MOV r1,#09
call again
call delay
jmp trans2
trans2: MOV r0,#09 ;设定呼叫站号
MOV r1,#15
call again
call delay
jmp trans3
trans3: MOV r0,#24 ;设定交谈模式
MOV r1,#05
call again
call delay
jmp scan0
again: MOV a,r0 ;至table1取码
MOV dptr,#table1
MOV c a,@a+dptr
MOV sbuf,a ;发送给tnc
cpl a
MOV p2,a ;输出至p2显示
wait: jbc ti,ok ;发送完毕否?是则跳至ok并清除ti
jmp wait
ok: inc r0 ;取下一个码
djnz r1,again
ret
delay: MOV r5,#200
d1: MOV r6,#248
djnz r6,$
djnz r5,d1
ret
table: db 30h,31h,32h,33h ;0,1,2,3
db 34h,35h,36h,37h ;4,5,6,7
db 38h,39h,41h,42h ;8,9,a,b
db 43h,44h,45h,0dh ;c,d,e,entet
table1: db 4dh,59h,20h,42h ;mybu2FP
db 56h,32h,46h,50h,0dh
db 4dh,59h,43h,41h,4ch,4ch ;mycall bu2fp-1(enter)
db 20h,42h,56h,32h,46h,50h
db 2dh,31h,0dh
db 43h,4fh,4eh,56h,0dh ;conv(enter)
end