📄 slavr738.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 + -