电子乒乓球游戏机
**********************
初始化
**********************
lw bit 20h.0
rw bit 20h.1
speed bit 20h.2
sd bit 20h.3
fs bit 20h.4
jq bit 20h.5
zy bit 20h.6
fq bit 20h.7
date equ p0
led equ p1
rp equ p3.0
lp equ p3.3
ks equ p3.2
spe equ p3.1
bw equ p2.3
qw equ p2.2
gw equ p2.1
sw equ p2.0
state equ 30h
ball equ 31h
lcode equ 32h
rcode equ 33h
sdbuf equ 34h
;.............................
org 000h
ljmp main
org 000bh
ljmp int50ms
;.....................
main:
clr p3.4
mov led,#0ffh
mov lcode,#00h
mov rcode,#00h
mov state,#00h
clr speed
setb gw
setb sw
setb bw
setb qw
mov ball,#0ffh
mov tmod,#01h
mov th0,#3ch
mov tl0,#0b0h
setb ea
setb et0
setb tr0
mov r7,#8
mov r6,#20
mov r0,#10
mov r1,#5
mov sdbuf,#00h
;*********************
main1:
lcall dis
lcall key
jb lw,lwdo
jnb rw,main1
clr rw
inc rcode
lcall rsd
mov a,rcode
cjne a,#21,main1
lcall gofs; 比分为21分,分闪
ljmp main1
;.................
lwdo: ;左得分
clr lw
inc lcode
lcall lsd ;左得分,灯闪
mov a,lcode
cjne a,#21,main1
lcall gofs
ljmp main1[page]
;************************************
int50ms:
;中断,,包含移位,发球标志
mov th0,#3ch
mov tl0,#0b0h
lcall key
mov a,state
cjne a,#2,back
mov a,sdbuf
cjne a,#00h,sd1
djnz r6,back
mov r6,#20
sjmp spback
sd1:
cjne a,#01h,sd2
djnz r0,back
mov r0,#10
sjmp spback
sd2:
djnz r1,back
mov r1,#5
spback: clr jq
jnb zy,ldo
rdo:
mov a,ball
cjne a,#0feh,rmove
setb lw
mov state,#00h
sjmp back
rmove:
mov a,ball
rr a
mov led,a
mov ball,a
cjne a,#0feh,back
setb jq
reti
;......................
ldo:
mov a,ball
cjne a,#07fh,lmove
setb rw
mov state,#00h
sjmp back
lmove:
mov a,ball
rl a
mov led,a
mov ball,a
cjne a,#07fh,back
setb jq
back:reti
;****键盘程序**************
key:
setb p3.0
setb p3.1
setb p3.2
setb p3.3
mov a,p3
anl a,#0fh
cjne a,#0fh,key1
sjmp kse
;键扫描
key1:
jnb ks,jks
jnb lp,jlp
jnb rp,jrp
jnb spe,jspe
ljmp kse
;加速键处理
jspe: lcall del20ms
jb spe,kse
inc sdbuf
lcall sdled
ret
jks: ;开始键处理
lcall del20ms
jb ks,kse
clr fs
clr sd
cpl fq
mov led,0ffh
mov state,#01h
jb fq,ks1 ;发球标志为1,右发球
mov ball,#07fh
mov led,ball
sjmp ks2
ks1:
mov ball,#0feh
mov led,ball
ks2:
clr c
mov a,lcode
cjne a,#21,ks3
ljmp gofs
ks3:
clr c
mov a,#rcode
cjne a,#21,kse
ljmp gofs
kse:ret
;**************左拍处理
jlp:
mov a,state
cjne a,#01,lp1
jb fq,lpe
mov state,#02
setb zy ;移位 为1,球右移
sjmp lpe
lp1:
cjne a,#2,lpe
jb zy,lpe ;移位标致为0,球左移
jnb jq,lp2
setb zy
sjmp lpe
lp2:
setb rw
mov state,#00h
lpe:ret
;......右拍..................
jrp:
mov a,state
cjne a,#01,rp1
jnb fq,rpe
mov state,#02
clr zy
sjmp rpe
rp1:
cjne a,#2,rpe
jnb zy,rpe
jnb jq,rp2
clr zy
sjmp rpe
rp2:
setb lw
mov state,#00h
rpe:ret
;.............
sdled:
mov a,sdbuf
cjne a,#01h,sdled1
clr p2.5
setb p2.4
setb p2.6
ret
sdled1:
cjne a,#02h,sdled2
clr p2.6
setb p2.5
setb p2.4
ret
sdled2:
mov sdbuf,#00h
clr p2.4
setb p2.6
setb p2.5
ret
;*********
;**********分显******************
dis:
mov a,rcode
mov b,#10
div ab
mov dptr,#xstab
xch a,b
movc a,@a+dptr
mov p0,a
clr gw
lcall delms
setb gw
xch a,b
movc a,@a+dptr
mov p0,a
clr sw
lcall delms
setb sw
mov a,lcode
mov b,#10
div ab
xch a,b
movc a,@a+dptr
mov p0,a
clr bw
lcall delms
setb bw
xch a,b
movc a,@a+dptr
mov p0,a
clr qw
lcall delms
setb qw
ret
;......................得分灯闪
rsd: mov r5,#6
mov led,#0feh
gosd2: cpl led.0
lcall del20ms
lcall del20ms
djnz r5,gosd2
mov r5,#6
ret
lsd: mov r5,#6
mov led,#07fh
lsd2: cpl led.7
lcall del20ms
lcall del20ms
djnz r5,lsd2
mov r5,#6
ret
delms:
mov r4,#100
mov r5,#10
delms1: djnz r4,$
mov r4,#100
djnz r5,delms1
mov r5,#6
ret
del20ms:
mov r3,#200
mov r2,#10
del20ms1: djnz r2,$
mov r2,#200
djnz r3,del20ms1
ret
;..........................
gofs:
mov r5,#6
gofs1: mov p3,#00h
lcall del20ms
mov p3,#0ffh
djnz r5,gofs1
mov r5,#6
mov lcode,#00h
mov rcode,#00h
ret
xstab:DB 3FH,05H,5BH,4FH ;"0","1","2","3"
DB 65H,6eH,7eH,07H ;"4","5","6","7"
DB 7FH,6FH,
;**************
上一篇:基于51单片机的遥控智能小车实作心得
下一篇:如何做一台自己的手机蓝牙遥控车
推荐阅读最新更新时间:2024-03-16 14:01