?? rank.asm
字號(hào):
$mod51
latch equ p2 ;port for providing feedback
keys equ p0 ;input stage port
dline equ p1 ;8-bit databus for LCD
restart equ p3.0 ;flag for next question/round
rs equ p3.3 ;register select for LCD
rw equ p3.2 ;read/write for LCD
en equ p3.1 ;LCD enable pin
buzzer equ p3.4 ;pin for sounding buzzer
mode equ p3.6 ;'fff' or 'race' selection pin
flag equ p3.5 ;flag to check 'done in time' or 'time out'
org 0000h
sjmp main
org 000bh ;timer0 interrupt vector address
clr tr0 ;clear timer0 run bit
mov tl0,#00h
mov th0,#00h ;reload timer0 with initial count
djnz r5,a1 ;left buzzer on unless r5=0
setb buzzer ;stop buzzer
a1: djnz r7,return
mov r7,#136
djnz r6,return
mov r6,#3
mov r5,#20
clr buzzer ;make buzzer on
mov a,#0c0h
acall command
mov dptr,#timeout
acall read ;display 'timeout'
acall dispdly ;keep on displaying for sometime
setb buzzer ;stop buzzer
setb flag
return: reti ;return from interrupt service routine
main: mov ie,#00h
setb ea
setb et0 ;enable timer0 interrupt
mov tmod,#01h ;timer0 configured in mode 1
mov tcon,#00h
mov tl0,#00h
mov th0,#00h ;set initial count to 0000H
mov r7,#136
mov r6,#3
mov r5,#20
mov latch,#0 ;initialize input stage
mov keys,#0ffh ;initialize input stage
acall lcdly
acall lcd_int ;initialize LCD
mov dptr,#welcome
acall read ;display 'welcome to all'
mov a,#0c0h ;starting address for 2nd line
acall command
jnb mode,race1 ;jump to race1 when 'race' mode selected
mov dptr,#welcome1
sjmp fff1
race1: mov dptr,#welcome2
fff1: acall read
acall dispdly
mov a,#80h
acall command
mov dptr,#plrname
acall read ;display player names
mov a,#0c0h
acall command
jnb mode,race2
mov dptr,#firstqtn
sjmp fff2
race2: mov dptr,#firstrnd
fff2: acall read
here: clr flag
mov latch,#0 ;initialize input stage
mov keys,#0ffh ;initialize input stage
acall lcdly
mov 04h,#48 ;ASCII code of '0' is loaded into r4
blankrank: mov r0,#31h ;point the first location of rank table
again: mov @r0,#'-' ;initialize rank table by '-'
inc r0
cjne r0,#39h,again
chk: mov a,keys ;mov status of input into accumulator
cjne a,#0ffh,first ;check if any switch is pressed
sjmp chk
first: clr buzzer ;sound buzzer
next_rank: inc 04h ;load r4 with ASCII code of next rank
mov r0,#31h ;point the first location of rank table
chk1: jb flag,result1
setb tr0 ;make timer0 run
mov a, keys ;mov status of input into accumulator
cpl a
xrl a,latch
cjne a,#0,scan ;check for any change in previous status
sjmp chk1
scan: jb acc.0,store ;now start scanning for the pressed switch from here
inc r0 ;point to next address in rank table (32H)
jb acc.1,store
inc r0 ;point to next address in rank table (33H)
jb acc.2,store
inc r0 ;point to next address in rank table (34H)
jb acc.3,store
inc r0 ;point to next address in rank table (35H)
jb acc.4,store
inc r0 ;point to next address in rank table (36H)
jb acc.5,store
inc r0 ;point to next address in rank table (37H)
jb acc.6,store
inc r0 ;point to next address in rank table (38H)
jb acc.7,store
store: mov @r0,04h ;move ASCII code of current rank to the pointed location
orl a,latch
mov latch,a
cjne r4,#56,next_rank ; 56 is ASCII code for '8'
sjmp result
result: clr tr0
mov tl0,#00h
mov th0,#00h ;reload timer0 with initial count
mov r7,#136
mov r6,#3
mov r5,#20
clr buzzer ;stop buzzer
mov a,#0c0h
acall command
jnb mode,race4
mov dptr,#intime
sjmp fff4
race4: mov dptr,#intime1
fff4: acall read
acall dispdly
setb buzzer
result1: clr tr0
mov r0,#31h ;reinitialize rank table pointer
mov a,#0c0h
acall command
show: mov a,@r0
acall display ;display the rank below name
mov a,#' '
acall display ;provide a space between ranks
inc r0
cjne r0,#39h,show ;keep on displying upto the rank of 'H'
stay: jb restart,stay ;now stay here unless a remote-key is pressed
mov r1,#4
s1: mov r2,#200
djnz r2,$
djnz r1,s1
jb restart,stay ;recheck if p3.0 is high
nxt_Ques: mov a,#0c0h
acall command
jnb mode,race3
mov dptr,#nxtqtn
sjmp fff3
race3: mov dptr,#nxtrnd
fff3: acall read ;display 'next question (or round)'
jmp here ;get ready for next question/round
read: clr a
movc a,@a+dptr
jz down
acall display
inc dptr
sjmp read
down: ret
lcd_int: mov a,#38h ;2 line disp, 8bits/ch, 5x7 matrix
acall command ;write into the LCD command register
mov a,#0ch ;display on, cursor off
acall command
mov a,#01h ;clr screen & bring cursor home (80H)
acall command
mov a,#06h ;right shifting for cursor movement
acall command
ret
command: mov dline,a
clr rs ;select command register of LCD
nop
nop
clr rw ;select write mode for LCD
nop
nop
setb en
acall lcdly1
clr en ;now write into command register
acall lcdly1
ret
display: mov dline,a
setb rs ;select data register of LCD
nop
nop
clr rw ;select write mode for LCD
nop
nop
setb en
acall lcdly
clr en ;now write into data register
acall lcdly
ret
lcdly: mov r1,#0ah
lp1: mov r2,#0ffh
djnz r2,$
djnz r1,lp1
ret
lcdly1: mov r1,#3fh
lp2: mov r2,#0ffh
djnz r2,$
djnz r1,lp2
ret
dispdly: mov r1,#255
d1: mov r2,#255
d2: mov r3,#30
djnz r3,$
djnz r2,d2
djnz r1,d1
ret
;Look up table starts from here
plrname: db 'A',' ','B',' ','C',' ','D',' ','E',' ','F',' ','G',' ','H',0
welcome: db ' WELCOME TO ALL ',0
welcome1: db ' THE PLAYERS ',0
welcome2: db ' THE RACERS ',0
firstqtn: db ' FIRST QUESTION ',0
firstrnd: db ' FIRST ROUND ',0
nxtqtn: db ' NEXT QUESTION ',0
nxtrnd: db ' NEXT ROUND ',0
intime: db ' DONE IN TIME ',0
intime1: db 'COVERED IN TIME ',0
timeout: db ' TIME OUT ',0
end
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -