hex_bcd9: adc data_bufh,data_bufh
brhs hex_bcdh1
brlo hex_bcdh2
ldi ah,$66 ;h=0 c=0
add ah,data_bufh
brhs hex_bcdh0
brlo hex_bcdh60
rjmp hex_bcdh9
hex_bcdh0: brlo hex_bcdh66
rjmp hex_bcdh06
hex_bcdh1: brlo hex_bcdh66 ;h=1 c=?
ldi ah,$60 ;h=1 c=0
add ah,data_bufh
brlo hex_bcdh66
rjmp hex_bcdh06
hex_bcdh2: ldi ah,$06 ;h=0 c=1
add ah,data_bufh
brhs hex_bcdh66
rjmp hex_bcdh60
hex_bcdh06: ldi ah,$06
add data_bufh,ah
ldi ah,$60
add ah,data_bufh
brlo hex_bcdh60
rjmp hex_bcdh9
hex_bcdh60: ldi ah,$60
add data_bufh,ah
sec
rjmp hex_bcdh9
hex_bcdh66: ldi ah,$66
add data_bufh,ah
sec
hex_bcdh9: dec data_buf0
ldi ah,$00
cpse ah,data_buf0
rjmp hex_bcd_loop
ret
display:
ori r_portd,$ff
andi disp_num,$03
sbrc disp_num,0
rjmp display_13
display_02: ldi zh,high(led02_reg*2)
ldi zl,low(led02_reg*2)
sbrc disp_num,1
rjmp display_2
display_0: andi r_portd,$fe ;portd_bit0(display high_byte)
mov al,disp_bufh
swap al
rcall display_4
bst r_bit0,working_bit1
bld r0,6
display_0c: in al,pina
ldi zh,high(key0)
ldi zl,low(key0)
ld ah,z
lsl ah
bst al,0
bld ah,0
st z,ah
cpi ah,$00
brne display0c1
sbrc r_key0,0
rcall key0_deal
rjmp display0c2
display0c1: cpi ah,$ff
brne display0c2
sbr r_key0,key0_bit
display0c2: ldi zl,low(key1)
ldi zh,high(key1)
ld ah,z
lsl ah
bst al,1
bld ah,0
st z,ah
cpi ah,$00
brne display0c3
sbrc r_key0,1
rcall key1_deal
rjmp display0c4
display0c3: cpi ah,$ff
brne display0c4
sbr r_key0,key1_bit
display0c4: ldi zl,low(key2)
ldi zh,high(key2)
ld ah,z
lsl ah
bst al,2
bld ah,0
st z,ah
cpi ah,$00
brne display0c5
sbrc r_key0,2
rcall key2_deal
rjmp display0c6
display0c5: cpi ah,$ff
brne display0c6
sbr r_key0,key2_bit
display0c6: out portb,r0
out portd,r_portd
ret
display_2: andi r_portd,$fb
mov al,disp_bufl
swap al
rcall display_4
in al,pina
ldi zh,high(key6)
ldi zl,low(key6)
ld ah,z
lsl ah
bst al,0
bld ah,0
st z,ah
cpi ah,$00
brne display2c1
sbrc r_key0,6
rcall key6_deal
rjmp display2c2
display2c1: cpi ah,$ff
brne display2c2
sbr r_key0,key6_bit
display2c2: ldi zl,low(key7)
ldi zh,high(key7)
ld ah,z
lsl ah
bst al,1
bld ah,0
st z,ah
cpi ah,$00
brne display2c3
sbrc r_key0,7
rcall key7_deal
rjmp display2c4
display2c3: cpi ah,$ff
brne display2c4
sbr r_key0,key7_bit
display2c4: ldi zl,low(key8)
ldi zh,high(key8)
ld ah,z
lsl ah
bst al,2
bld ah,0
st z,ah
cpi ah,$00
brne display2c5
sbrc r_key1,0
rcall key8_deal
rjmp display2c6
display2c5: cpi ah,$ff
brne display2c6
sbr r_key1,key8_bit
display2c6: out portb,r0
out portd,r_portd
ret
display_13: ldi zh,high(led13_reg*2)
ldi zl,low(led13_reg*2)
sbrc disp_num,1
rjmp display_3
display_1: andi r_portd,$fd
mov al,disp_bufh
rcall display_4
bst r_bit0,time_bit
bld r0,1
in al,pina
ldi zh,high(key3)
ldi zl,low(key3)
ld ah,z
lsl ah
bst al,0
bld ah,0
st z,ah
cpi ah,$00
brne display1c1
sbrc r_key0,3
rcall key3_deal
rjmp display1c2
display1c1: cpi ah,$ff
brne display1c2
sbr r_key0,key3_bit
display1c2: mov ah,sw5
cpi ah,$00
brne display1c21
sbrc r_key1,4
rcall sw5_deal
rjmp display1c22
display1c21:cpi ah,$ff
brne display1c22
sbr r_key1,sw5_bit
display1c22:ldi zl,low(key4)
ldi zh,high(key4)
ld ah,z
lsl ah
bst al,1
bld ah,0
st z,ah
cpi ah,$00
brne display1c3
sbrc r_key0,4
rcall key4_deal
rjmp display1c4
display1c3: cpi ah,$ff
brne display1c4
sbr r_key0,key4_bit
display1c4: ldi zl,low(key5)
ldi zh,high(key5)
ld ah,z
lsl ah
bst al,2
bld ah,0
st z,ah
cpi ah,$00
brne display1c5
sbrc r_key0,5
rcall key5_deal
rjmp display1c6
display1c5: cpi ah,$ff
brne display1c6
sbr r_key0,key5_bit
display1c6: out portb,r0
out portd,r_portd
ret
display_3: andi r_portd,$ef
mov al,disp_bufl
rcall display_4
bst r_bit0,auto_bit
bld r0,1
in al,pina
ldi zh,high(key9)
ldi zl,low(key9)
ld ah,z
lsl ah
bst al,1
bld ah,0
st z,ah
ldi zl,low(dl_5l)
ldi zh,high(dl_5l)
ld xl,z+
ld xh,z
or xl,xh
brne display_31
sbrs r_bit0,working_bit1
rcall key9_deal
display_31: ldi zl,low(keya)
ldi zh,high(keya)
in al,pina
ld ah,z
lsl ah
bst al,0
bld ah,0
st z,ah
cpi ah,$00
brne display3c3
sbrc r_key1,2
rcall keya_deal
rjmp display3c4
display3c3: cpi ah,$ff
brne display3c4
sbr r_key1,keya_bit
display3c4: ldi zl,low(keyb)
ldi zh,high(keyb)
ld ah,z
lsl ah
bst al,2
bld ah,0
st z,ah
cpi ah,$00
brne display3c5
sbrc r_key1,3
rcall keyb_deal
rjmp display3c6
display3c5: cpi ah,$ff
brne display3c6
sbr r_key1,keyb_bit
display3c6: out portb,r0
out portd,r_portd
ret
display_4: andi al,$0f
add zl,al
ldi al,$00
adc zh,al
lpm
ret
led02_reg: .db $b7,$a0,$3b,$ba,$ac,$9e,$9f,$b0,$bf,$bc,$3d,$ab,$07,$08,$00,$00
led13_reg: .db $ed,$05,$dc,$5d,$35,$79,$f9,$0d,$fd,$3d,$bc,$d5,$e0,$10,$00,$00
tim0_ovf: push al
push ah
in al,sreg
push al
push zl
push zh
ldi al,$ff ;(4mhz)250us*2=0.5ms
out tcnt0,al
ldi al,$ff
out porta,al
in al,pina
lsl sw2
bst al,4
bld sw2,0
lsl sw3
bst al,3
bld sw3,0
ldi al,$03
and sw3,al
in al,pind
lsl sw1
bst al,7
bld sw1,0
lsl sw5
bst al,6
bld sw5,0
lsl sw4
bst al,5
bld sw4,0
ldi al,$07
and timer_n,al
inc timer_n
cp timer_n,al
brne tim0_next4
ldi al,$06 ;0.5*5=2.5ms
mov timer_n,al
cpi disp_num,$03
brne tim0_next
y5_clr: cbi portc,y2
rcall delay_deal ;2.5*4=10ms
rjmp tim0_next3
tim0_next: cpi disp_num,$02
brne tim0_next1
rcall disp_setup
rjmp tim0_next3
tim0_next1: cpi disp_num,$01
brne tim0_next2
sbrc r_bit0,time_bit
rjmp tim0_next3
sbrs r_bit0,5
rjmp tim0_next3
cbr r_bit0,$20
rcall eeprom_w
rjmp tim0_next3
tim0_next2:
;rcall eeprom_r
tim0_next3: rcall display
inc disp_num
tim0_next4: pop zh
pop zl
pop al
out sreg,al
pop ah
pop al
reti
eeprom_r: ldi zh,high(dl_pre_1l)
ldi zl,low(dl_pre_1l)
ldi ah,$00
ldi al,$00
out eearh,al
out eearl,al
eeprom_r_loop:
in al,eecr
sbrc al,eewe
rjmp eeprom_r_loop
sbi eecr,eere
nop
nop
in al,eedr
st z+,al
inc ah
out eearl,ah
cpi ah,13
brne eeprom_r_loop
ld al,-z
mov mode_num,al
ret
eeprom_w: ldi al,$00
out eearh,al
mov al,dl_num
dec al
add al,al
out eearl,al
ldi zh,high(dl_pre_1l)
ldi zl,low(dl_pre_1l)
add zl,al
ldi al,$00
adc zh,al
eeprom_w_loop:
in al,eecr
sbrc al,eewe
rjmp eeprom_w_loop
ld al,z+
out eedr,al
sbi eecr,eemwe
sbi eecr,eewe
eeprom_w_loop1:
in al,eecr
sbrc al,eewe
rjmp eeprom_w_loop1
in al,eearl
inc al
out eearl,al
ld al,z
out eedr,al
sbi eecr,eemwe
sbi eecr,eewe
ret
delay_deal:
dec ring_timer
mov al,ring_timer
cpi al,230
brne delay_deal1
cbi portc,speaker
delay_deal1:cpi al,0
brne delay_deal2
cbr r_bit0,$04
delay_deal2:ldi zh,$00
ldi zl,dl_1l
rcall delay_deal3
rcall delay_deal3
rcall delay_deal3
rcall delay_deal3
rcall delay_deal3
rcall delay_deal3
ret
delay_deal3:ld al,z
ldd ah,z+1
cpse al,ah
rjmp delay_deal4
cpi al,$00
breq delay_deal5
delay_deal4:sbiw al,$01
st z,al
std z+1,ah
delay_deal5:adiw zl,$02
ret
key0_deal: cbr r_key0,key0_bit
rcall ring_setup
stop_start: cbr r_bit0,$04
sbrc r_bit0,working_bit1
rjmp stop_deal
ldi al,$40 ;stop/start
eor r_bit0,al
sbr r_bit0,$01
clr step_num
ret
stop_deal: ldi al,$41
eor r_bit0,al
clr step_num
ret
key1_deal: cbr r_key0,key1_bit
rcall ring_setup
ldi al,$02 ;auto/1cycle
eor r_bit0,al
ret
key2_deal: cbr r_key0,key2_bit ;add_key +
rcall ring_setup
sbrc r_bit0,mode_bit
rjmp key2_mode
sbrc r_bit0,time_bit
rjmp key2_time
sbrc r_bit0,dl_num_bit
rjmp key2_dl_num
ldi zl,low(counter_l)
ldi zh,high(counter_l)
ldi al,$00
st z+,al
st z,al
key2_ret: ret
key2_mode: ldi al,7
cpse mode_num,al
rjmp key2_mode1
ret
key2_mode1: inc mode_num
cp mode_num,al
brsh key2_mode2
rjmp key2_mode3
key2_mode2: mov mode_num,al
key2_mode3: ldi al,12
out eearl,al
ldi al,0
out eearh,al
out eedr,mode_num
key2_mode4:
in al,eecr
sbrc al,eewe
rjmp key2_mode4
sbi eecr,eemwe
sbi eecr,eewe
ret
key2_dl_num:
inc dl_num
ldi al,6
cp dl_num,al
brsh key2_dl_num1
ret
key2_dl_num1:cbr r_bit0,$08
mov dl_num,al
ret
key2_time: sbr r_bit0,$20
ldi zl,low(dl_pre_1l)
ldi zh,high(dl_pre_1l)
mov al,dl_num
dec al
add al,al
add zl,al
ldi al,$00
adc zh,al
ld al,z
ldd ah,z+1
add al,data_buf
st z,al
ldi al,0
adc ah,al
std z+1,ah
ld al,z
ldi ah,25
add al,ah
ldd al,z+1
ldi ah,252
adc al,ah
brcs key2_time1
ret
key2_time1: ldi al,231
ldi ah,03
st z,al
std z+1,ah
ret
key3_deal: cbr r_key0,key3_bit
ret
SW5_DEAL: cbr r_key1,sw5_bit
rcall ring_setup
rjmp stop_start
key4_deal: cbr r_key0,key4_bit
rcall ring_setup
rjmp stop_start
key5_deal: cbr r_key0,key5_bit
ret
key6_deal: cbr r_key0,key6_bit
sbrc r_bit0,working_bit1
ret
rcall ring_setup
in al,portc
ldi ah,$12
eor al,ah ;y5 shuttle
out portc,al
sbr r_bit0,$01
ret
key7_deal: cbr r_key0,key7_bit
sbrc r_bit0,working_bit1
ret
rcall ring_setup
in al,portc
ldi ah,$04
eor al,ah ;y4 working_table
out portc,al
sbr r_bit0,$01
ret
key8_deal: cbr r_key1,key8_bit ;sub_key -
rcall ring_setup
sbrc r_bit0,mode_bit
rjmp key8_mode
sbrc r_bit0,time_bit
rjmp key8_time
sbrc r_bit0,dl_num_bit
rjmp key8_dl_num
ldi zl,low(counter_l)
ldi zh,high(counter_l)
ld al,z+
ld ah,z
or ah,al
breq key8_ret
ld ah,z
sbiw al,$01
st z,ah
st -z,al
key8_ret: ret
key8_mode: ldi al,0
cp mode_num,al
breq key8_mode1
dec mode_num
rcall key2_mode3
key8_mode1: ret
key8_dl_num:ldi al,1
cp dl_num,al
breq key8_dl_num1
dec dl_num
ret
key8_dl_num1:cbr r_bit0,$08
ret
key8_time: sbr r_bit0,$20
ldi zl,low(dl_pre_1l)
ldi zh,high(dl_pre_1l)
mov al,dl_num
dec al
add al,al
add zl,al
ldi al,$00
adc zh,al
ld al,z
ldd ah,z+1
sub al,data_buf
st z,al
ldi al,0
sbc ah,al
std z+1,ah
ld al,z
ldi ah,25
add al,ah
ldd al,z+1
ldi ah,252
adc al,ah
brcs key8_time1
ret
key8_time1: ldi al,00
ldi ah,00
st z,al
std z+1,ah
ret
key9_deal: ;motor1
cpi ah,$00
brne key9_deal1
in al,portc
ori al,$20
out portc,al
sbrc r_key1,1
rjmp key9_deal2
ret
key9_deal1: cpi ah,$ff
brne key9_deal3
in ah,portc
andi ah,$df
out portc,ah
sbrc r_key1,1
ret
cbr r_bit0,$40
rcall ring_setup
sbr r_key1,key9_bit
ret
key9_deal2: cbr r_key1,key9_bit
cbr r_bit0,$40
rcall ring_setup
key9_deal3: ret
keya_deal: cbr r_key1,keya_bit
sbrc r_bit0,working_bit1
ret
rcall ring_setup
in al,portc
ldi ah,$01
eor al,ah ;y6 test_stamp
out portc,al
sbr r_bit0,$01
ret
keyb_deal: cbr r_key1,keyb_bit ;set_key
rcall ring_setup
sbrc r_bit0,mode_bit
ret
sbrc r_bit0,dl_num_bit
rjmp keyb_deal1
sbr r_bit0,$08
ldi al,$01
mov dl_num,al
ret
keyb_deal1: sbrc r_bit0,time_bit
rjmp keyb_deal2
sbr r_bit0,$10
ldi data_buf,100
ret
keyb_deal2: cpi data_buf,100
brne keyb_deal3
ldi data_buf,10
ret
keyb_deal3: cpi data_buf,10
brne keyb_deal4
ldi data_buf,1
ret
keyb_deal4: cbr r_bit0,$10
ret
ring_setup: sbi portc,speaker
ldi al,250
mov ring_timer,al
ret
谁看得懂以上程序啊? |