;------------------------------------------------
mul_process: ;8ms
call key_scan
mov a,mul_dptr
incms mul_dptr
add pcl,a
jmp led_display10 ;led
jmp led_display20
key_scan:
mov a,#00001110b
mov p2ur,a
mov a,#00110000b
or p2,a
mov a,#11110001b
mov p2m,a
b0mov r,#30
decms r
jmp $-1
mov a,p2
and a,#00001110b
mov new_key,a
mov a,#00110000b
mov p2ur,a
mov a,#11001111b;0001
mov p2m,a
mov a,#11110001b
and p2,a
b0mov r,#30
decms r
jmp $-1
mov a,p2
and a,#00110000b
or new_key,a
bts0 f_key_rel
jmp key_scan10 ;检测放键
jmp key_scan20 ;检测按键
key_scan10:
mov a,new_key
cmprs a,#00111110b
jmp key_scan30
incms key_cnt
mov a,key_cnt
cmprs a,#5 ;20ms
jmp key_scan90
bclr f_key_rel
jmp key_scan30
key_scan20:
mov a,new_key
cmprs a,old_key
jmp key_scan21
incms key_cnt
mov a,key_cnt
cmprs a,#8 ;32ms
jmp key_scan90
clr key_cnt
jmp key_scan40
key_scan21:
mov_ old_key,new_key
key_scan30:
clr key_cnt
jmp key_scan90
key_scan40:
;--
mov a,new_key
cmprs a,#00011110b
jmp key_scan40_0
incms key_cnt0
mov a,key_cnt0
cmprs a,#80
jmp key_scan90
clr key_cnt0
jmp key_scan44
key_scan40_0:
clr key_cnt0
mov a,new_key
cmprs a,#00111010b
jmp key_scan40_1
incms key_cnt1
mov a,key_cnt1
cmprs a,#80
jmp key_scan90
clr key_cnt1
jmp key_scan45
key_scan40_1:
clr key_cnt1
;---
mov a,new_key
cje a,#00111110b,key_scan90 ;无键按下不作处理
cje a,#00111100b,key_scan41
cje a,#00101110b,key_scan42
cje a,#00110110b,key_scan43
;cje a,#00011110b,key_scan44
;cje a,#00111010b,key_scan45
;cje a,#00100110b,key_scan46/////
jmp key_scan90
key_scan41:
mov_ event_buf,#1 ;POWER键键值1
jmp key_scan80
key_scan42:
mov_ event_buf,#2 ;speed键键值2
jmp key_scan80
key_scan43:
mov_ event_buf,#3 ;timer键键值3
jmp key_scan80
key_scan44:
mov_ event_buf,#4 ;cleaner键值4
jmp key_scan80
key_scan45:
mov_ event_buf,#5 ;replace键键值5
jmp key_scan80
;key_scan46:
; mov_ event_buf,#6 ;speed+timer键键值6////
; jmp key_scan80
key_scan80:
bset f_key_rel
call wrt_FIFO ;将键值写入event_FIFO
key_scan90:
ret
;---------------------------------------
led_display10:
mov a,#0 ;去掉上拉,不然会有影响
mov p2ur,a
mov a,#11100001b
mov p2m,a
bset p2.5
bclr p2.4
bts1 f_power
jmp led_display10_1
bset p2m.4
bset p2m.3
bset p2.3
led_display10_1:
bts1 f_8h
jmp led_display10_2
bset p2m.4
bset p2m.2
bset p2.2
led_display10_2:
bts1 f_4h
jmp mul_process90
bset p2m.4
bset p2m.1
bset p2.1
jmp mul_process90
;--------------------------------
led_display20:
mov a,#0 ;去掉上拉,不然会有影响
mov p2ur,a
mov a,#11010001b
mov p2m,a
bset p2.4
bclr p2.5
bts1 f_cleaner
jmp led_display20_1
bset p2m.5
bset p2m.3
bset p2.3
led_display20_1:
bts1 f_2h
jmp led_display20_2
bset p2m.5
bset p2m.2
bset p2.2
led_display20_2:
bts1 f_replace
jmp led_display20_3
bset p2m.5
bset p2m.1
bset p2.1
led_display20_3:
clr mul_dptr
mul_process90:
ret
;----------------------------------------
;----------------------------------------
wrt_FIFO:
b0mov y,#event_FIFO$m
b0mov z,#event_FIFO$l ;取首地址
mov a,writep ;计算当前地址
b0add z,a ;写表的高位地址
mov a,event_buf
mov @yz,a ;存键值
incms writep
mov a,writep
cje a,#FIFO_len,wrt_FIFO10 ;到底部writep清0
jmp wrt_FIFO90 ;没有到底部退出
wrt_FIFO10:
clr writep
wrt_FIFO90:
ret
;---------------
rd_FIFO:
mov a,writep ;读写指针相等没有数据写入,退出
cje a,readp,rd_FIFO90 ;读写指针不等,读event_FIFO
b0mov y,#event_FIFO$m
b0mov z,#event_FIFO$l ;取首地址
mov a,readp ;计算当前地址
b0add z,a ;读表的高位地址
mov_ r,@yz ;存键值
incms readp
mov a,readp
cje a,#FIFO_len,rd_FIFO10 ;到底部readp清0
jmp rd_FIFO90 ;没有到底部退出
rd_FIFO10:
clr readp
rd_FIFO90:
ret
;----------------------------------------------
chip_init:
call sys_init
bset P_high ;关输出
bset P_low
bset P_med
;------------------------------------buzzer init
clr intrq
mov a,#11110100b ;4k 131 : 2k 6
mov tc0m,a
mov a,#tc0_value ;
mov tc0c,a
mov tc0r,a
;--------------------------------------t0 init
mov a,#10110000b ;32
mov t0m,a
mov a,#t0_value ;4ms
mov t0c,a
mov a,#3
mov state,a
mov a,#40
mov cnt_f1,a
ret
;-----------------------------------------------
sys_init:
clr oscm
mov a,#5ah
b0mov wdtr,a
mov a,#10110000b ;32
mov t0m,a
mov a,#11110100b ;2
or tc0m,a
mov a,#00000000b
b0mov inten,a
mov a,#00001100b
or p1m,a
bset p2m.0
ret |