?? 按鈕猜數.asm
字號:
;************* 應用筆記 按鈕猜數.asm ************************
;*
;* 標題:程序猜數
;* 版本: 1.0
;*最后更新日期: 2000.08.08
;*
;* 支援 E-mail: gzsl@sl.com.cn
;*
;* 描述
;* AT90S8515 A口、C口接8X8LED摸塊,PB0接按鈕開關作為猜數啟動,8X8LED摸塊先
;* 顯示有變化的大小方塊,然后顯示0到9的隨機數,最后停下僅顯示0~9之間一個數。
;* 作者: GRC.
;* 掌握隨機數、0~9數字的產生程序編制方法,及AVR AT90S8515單片機
;* 與8X8 LED模塊的連接,程序注釋更詳細資料見<<按鈕猜數>>一文
;*
;*
;***************************************************************************
.include "8515def.inc"
.def peed =r16
.def dspn =r17
.def temp2 =r18
.def temp1 =r19
.def temp =r20
.def scndp =r21
.def cnt =r22
.def rdata =r23
.def rdata9 =r24
.equ dpfstb =0x01e0
.equ randtb =0x0210
.equ numbertb=0x0240
.org $0000
rjmp RESET ;Reset Handle
.cseg
.org $0010
RESET: ldi peed,high(RAMEND)
out SPH,peed
ldi peed,low(RAMEND)
out SPL,peed
ldi peed,0xff
out ddra,peed
out ddrc,peed
ldi peed,0xfd
out ddrd,peed
ldi peed,0xff
out portd,peed
ldi peed,0x13
start: ldi dspn,0x06
ldi zh,high(dpfstb*2)
ldi zl,low(dpfstb*2)
dspfm: rcall ldtb8
ldi temp2,0xa0
dspfm1: rcall scan1
sbis pind,01
rjmp getseed
dec temp2
brne dspfm1
dec dspn
brne dspfm
rjmp start
getseed:inc temp
sbis pind,01
rjmp getseed
andi temp,0x1f
ldi zh,high(randtb*2)
ldi zl,low(randtb*2)
add zl,temp
lpm
mov rdata,r0
next: ldi dspn,0x08
repeet: rcall randm
rcall dspnumber
dec dspn
brne repeet
rcall randm
guess1: rcall dspnumber
sbic pind,01
rjmp guess1
wait: rcall dspnumber
sbis pind,01
rjmp wait
ldi rdata9,0x03
start0: ldi dspn,0x06
ldi zh,high(dpfstb*2)
ldi zl,low(dpfstb*2)
dspfm0: rcall ldtb8
ldi temp2,0xa0
dspfm1a:rcall scan1
dec temp2
brne dspfm1a
dec dspn
brne dspfm0
dec rdata9
brne start0
rjmp next
dspnumber:
ldi zh,high(numbertb*2)
ldi zl,low(numbertb*2)
add zl,rdata9
rcall ldtb8
ldi temp2,0xa0
dspn1: rcall scan1
dec temp2
brne dspn1
ret
scan1: push xl
ldi temp,0b01111111
mov scndp,temp
ldi cnt,0x08
col1: out portc,scndp
ld r1,x+
out porta,r1
rcall delay
sec
ror scndp
dec cnt
brne col1
pop xl
ret
ldtb8: ldi xl,0x80
ldi xh,0x00
ldi temp1,0x08
push xl
nexld1: lpm
st x+,r0
ld r0,z+
dec temp1
brne nexld1
pop xl
ret
delay: push peed
del0: push peed
del1: dec peed
brne del1
pop peed
dec peed
brne del0
pop peed
ret
randm: mov temp,rdata
mov temp1,rdata
swap temp1
eor temp,temp1
rol temp1
eor temp,temp1
rol temp1
eor temp,temp1
rol temp
rol rdata
mov rdata9,rdata
andi rdata9,0x0f
cpi rdata9,0x0a
brsh randm
lsl rdata9
lsl rdata9
lsl rdata9
ret
.cseg
.org dpfstb;
;small o
.db 0b00000000,0b00000000,0b00000000,0b00011000
.db 0b00011000,0b00000000,0b00000000,0b00000000
.db 0b00000000,0b00000000,0b00111100,0b00100100
.db 0b00100100,0b00111100,0b00000000,0b00000000
.db 0b00000000,0b01111110,0b01000010,0b01000010
.db 0b01000010,0b01000010,0b01111110,0b00000000
;big o
.db 0b11111111,0b10000001,0b10000001,0b10000001
.db 0b10000001,0b10000001,0b10000001,0b11111111
.db 0b00000000,0b01111110,0b01000010,0b01000010
.db 0b01000010,0b01000010,0b01111110,0b00000000
.db 0b00000000,0b00000000,0b00111100,0b00100100
.db 0b00100100,0b00111100,0b00000000,0b00000000
.cseg
.org randtb
.db 0x5a,0x7b,0x5b,0x4f,0x66,0x6d,0x7d,0x07
.db 0x3b,0x8c,0x67,0x9a,0x99,0x7e,0x2d,0x3e
.db 0x5c,0x6d,0x5b,0x7e,0xf6,0xe7,0x4c,0xc8
.db 0x69,0x9c,0xe2,0x75,0x6c,0xd3,0xe8,0x9a
.cseg
.org numbertb
;0
.db 0b00111000,0b01000100,0b01000100,0b01000100
.db 0b01000100,0b01000100,0b01000100,0b00111000
;1
.db 0b00010000,0b00011000,0b00010000,0b00010000
.db 0b00010000,0b00010000,0b00010000,0b00111000
;2
.db 0b00011100,0b00100010,0b00100000,0b00010000
.db 0b00001000,0b00000100,0b00000010,0b00111110
;3
.db 0b00111100,0b00010000,0b00001000,0b00010000
.db 0b00100000,0b00100000,0b00100010,0b00011100
;4
.db 0b00100000,0b00110000,0b00101000,0b00100100
.db 0b00100010,0b11111110,0b00100000,0b00100000
;5
.db 0b01111110,0b00000010,0b00111110,0b01000000
.db 0b01000000,0b01000000,0b01000010,0b00111100
;6
.db 0b00110000,0b00001000,0b00000100,0b00111100
.db 0b01000100,0b01000100,0b01000100,0b00111000
;7
.db 0b01111100,0b01000000,0b00100000,0b00010000
.db 0b00001000,0b00001000,0b00001000,0b00001000
;8
.db 0b00111000,0b01000100,0b01000100,0b00111000
.db 0b01000100,0b01000100,0b01000100,0b00111000
;9
.db 0b00111000,0b01000100,0b01000100,0b01111000
.db 0b01000000,0b01000000,0b01000100,0b00111000
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -