单片机打铃器设计

时间:2013-03-12来源:网络


fycz: dec r23
brne gzcsxs1
rcall EERead
cpi r16,0
brne fycz1
inc r22
cpi r22,4
brmi fycz2
clr r22
fycz1: inc r25
cpi r25,32
brmi fycz2
clr r25
fycz2: rjmp gncs

bzcz: dec r24
brne gzcsxs1
cpi r22,0
brne bzcz2
bzcz1: rcall EERead
cpi r16,0
breq bzcz11
clr r16
rjmp bzcz12
bzcz11: ldi r16,1
bzcz12: rcall EEWrite
rjmp gncs
bzcz2: add r17,r22
rcall EERead
inc r16
cpi r22,1
breq bzcz21
cpi r16,60
brmi bzcz22
clr r16
rjmp bzcz22
bzcz21: cpi r16,24
brmi bzcz22
clr r16
bzcz22: rcall EEWrite
sub r17,r22
rjmp gncs

;****显示子程序************************************************
;*
;* 功能:将SRAM显示缓冲区存放的数送数码管显示
;* 入口:DISBUF---显示缓冲区起始地址(SRAM)
;* Y--显示缓冲区的指针
;* DISTBL---显示字符编码表起始地址(FLASH)
;* LEDSXW---LED闪显寄存器位设置
;* XSDBZ----小数点设置
;* 出口:Y--显示缓冲区的指针,指向高地址
;*
;****程序段
display: nop
push temp
push temp1
push temp2
push temp3
push temp4
push r6
ldi temp1,6
ldi temp3,0b11011111
ldi yl,low(DISBUF)
ldi yh,high(DISBUF)
ldi xl,low(XSDBZ)
clr xh
ld r6,x
disp1: ld temp,y+
ldi zl,low(DISTBL)
ldi zh,high(DISTBL)
add zl,temp
lsl zl
rol zh
lpm
lsr r6
brcc disp2
ldi temp4,0b10000000
or r0,temp4
disp2: out PORTC,r0
in temp2,PORTA
ori temp2,0b00111111
and temp2,temp3
out PORTA,temp2
sec
ror temp3
rcall delay
in temp2,PORTA
ori temp2,0b00111111
out PORTA,temp2 ;关显示
dec temp1
brne disp1
pop r6
pop temp4
pop temp3
pop temp2
pop temp1
pop temp
ret

;****时钟显示子程序************************************************
colodis: push temp
ldi yl,low(DISBUF) ;设置显示缓冲区起始地址
clr yh
ldi xl,low(TIMEDIS) ;设置时钟时分秒存放单元
clr xh
ldi zl,low(XSDBZ)
clr zh
ldi temp,0b00001010 ;b0-5对应LED自左到右1-6位的小数点,置“1”在该位置小数点。
st z,temp
rcall ram6ram
rcall display
pop temp
ret

;****延时子程序**************************************************

delay: nop ;延时子程序
push temp2
push temp1
ldi temp2,$ff
lp1: ldi temp1,$f
lp2: dec temp1
brne lp2
dec temp2
brne lp1
pop temp1
pop temp2
ret ;子程序返回

;****写EEPRON子程序************************************************
;*
;*功能:将EEDWR(r16)内容写入以EEAWR(r18:r17)内容为地址的EEPRON单元内。
;*
;****程序段
EEWrite:sbic EECR,EEWE
rjmp EEWrite
out EEARH,EEawrh
out EEARL,EEawr
out EEDR,EEdwr
sbi EECR,EEMWE
sbi EECR,EEWE
ret

;****读EEPRON子程序*************************************
;*
;*功能:从以EEARD(r18:r17)内容为地址的EEPRON单元读区内容送EEDRD(r16)寄存器。
;*
;****程序段
EERead: sbic EECR,EEWE
rjmp EERead
out EEARH,EEardh
out EEARL,EEard
sbi EECR,EERE
sbi EECR,EERE
in EEdrd,EEDR
ret

;****6字节SRAM内容传送子程序************************************************************
;*
;* 功能:将SRAM内连续6字节由BLOCK1传送到BLOCK2
;* x---欲传送6字节起始地址(SRAM)指针
;* y---欲放置6字节起始地址(SRAM)指针
;*
;****程序段
ram6ram:push temp1
push temp2
ldi temp1,$06
ramd1: ld temp2,x+
st y+,temp2
dec temp1
brne ramd1
pop temp2
pop temp1
ret

;****8位二进制数转3位BCD数子程序********************************************************
;*
;*功能:把一个8位无符号二进制数转换为3位BCD码数。
;*入口:r16---内装8位无符号二进制数。
;*出口:BCD码放在r2:r3:r4,r2存放百位。
;*
;****程序段

bt push r16
clr r2
clr r3
clr r4
rjmp bto2
bto1: inc r2
bto2: subi r16,100
brpl bto1
ldi temp,100
add r16,temp
rjmp bto4
bto3: inc r3
bto4: subi r16,10
brpl bto3
ldi temp,10
add r16,temp
mov r4,r16
pop r16
ret
;****时钟0中断服务程序******************************************************

.org $0bf0
TIM0_OVF: push temp
ldi temp,256-195
out tcnt0,temp ;重装T0时间常数
inc cntms
mov temp,cntms
cpi temp,40
brne timecunt
clr cntms
inc second
mov temp,second
cpi temp,60
brne timecunt
clr second
ldi TIM0INT,1
inc minute
mov temp,minute
cpi temp,60
brne timecunt
clr minute
inc hour
mov temp,hour
cpi temp,24
brne timecunt
clr hour
timecunt: ldi xl, low(TIMEDIS)
clr xh
mov r16,hour
rcall bto
st x+,r3
st x+,r4
mov r16,minute
rcall bto
st x+,r3
st x+,r4
mov r16,second
rcall bto
st x+,r3
st x+,r4
pop temp
reti

;****字形表**********************************************
.cseg
.org DISTBL
.dw 0x003f,0x0006,0x005b,0x004f,0x0066,0x006d,0x007d,0x0007,0x007f,0x006f
.dw 0x0077,0x007c,0x0039,0x005e,0x0079,0x0071,0x0073,0x0076,0x0058,0x0038
.dw 0x005c,0x0067,0x0050,0x006e,0x0078,0x0000,0x0054,0x0040,0x0074,0x0000

1 2 3

关键词: 单片机 打铃器 AT90S8515

加入微信
获取电子行业最新资讯
搜索微信公众号:EEPW

或用微信扫描左侧二维码

相关文章

查看电脑版