org 0000h
jmp start
org 03h
jmp int_ext0
org 0bh
jmp int_timer0
org 13
jmp loop
org 1bh
jmp loop
org 23h
jmp int_uart
org 2bh
jmp loop
org 30h
start:
mov p1,#0ffh
mov dptr,#0000h
mov a,#1
initmm:
setb ti
movx @dptr,a
inc dptr
mov r0,dph
cjne r0,#09h,initmm
acall delay
acall init_int
clr a
movx a,@dptr
mov p1,a
mov dptr,#stringspace
mov r0,#10
acall printrom
jmp loop
backr:
acall backreceive
loop:
cjne r7,#10h,backr
jmp loop
delay:
setb rs0
setb rs1
mov r7,a
mov a,#1h
delay1:
jz enddelay
mov r1,#0ffh
delloop1:
mov r2,#0ffh
delloop2:
nop
nop
nop
nop
djnz r2,delloop2
djnz r1,delloop1
dec a
sjmp delay1
enddelay:
mov a,r7
clr rs0
clr rs1
ret
init_int:
setb it0 ;下降沿触发外部中断0
setb ex0
;mov tmod,#01 ;16bit定时器0
;mov th0,#69h ;定时32ms
;mov tl0,#0ffh
mov tmod,#05h ;计数器0
mov th0,#0ffh ;计数3次
mov tl0,#0fch
setb et0
setb tr0
setb pt0
clr sm0
setb sm1
setb ren
clr rb8
clr tb8
mov a,pcon
anl a,#0fh
orl a,#080h
mov pcon,a ;波特率加倍
mov a,tmod
anl a,#0fh
orl a,#20h
mov tmod,a ;8bit定时器1,自动装置
mov th1,#0fah ;波特率为9600(晶振频率假设为11.0592MHz)
mov tl1,#0fah
setb tr1
setb es
setb ea
mov r7,#10h
ret
int_ext0:
cpl p1.7
clr ie0
reti
int_timer0:
cpl p1.6
mov th0,#0ffh
mov tl0,#0fch
reti
int_uart:
jnb ri,int_uart_end
inc r7
mov a,r7
acall save_case
mov r1,a
mov a,sbuf
movx @r1,a
acall back_case
clr ri
jmp int_uart_end
int_uart_end:
reti
backreceive:
uart_busy:
jnb ti,uart_busy
mov a,r7
mov r1,a
movx a,@r1
mov sbuf,a
clr ti
dec r7
ret
printrom:
;first address in dptr
;size in r0
mov r1,#0
printrom_loop:
mov a,r1
movc a,@a+dptr
acall send_b
inc r1
djnz r0,printrom_loop
ret
send_b:
;data in a
jnb ti,send_b ;busy
mov sbuf,a
clr ti
ret
save_case:
clr rs0
setb rs1
ret
back_case:
clr rs1
ret
stringspace:
db "hello word"
end
|