上課筆記:
鍵盤掃描原始程式
scan_key: mov keynum,#0 ;key counter=0
clr key_f ;initial
;
;row-0 ;74139=>q0=0
mov pcbit,#4 ;pc4=0
call cl_pc
mov pcbit,#5 ;pc5=0
call cl_pc
call rd_pb ;read pb,data store at pb55
call check_key
jbc key_f,have_state
;row-1 ;74139=>q1=0
mov pcbit,#4 ;pc4=1
call st_pc
mov pcbit,#5 ;pc5=0
call cl_pc
call rd_pb ;read pb,data store at pb55
call check_key
jbc key_f,have_state
;row-2 ;74139=>q2=0
mov pcbit,#4 ;pc4=0
call cl_pc
mov pcbit,#5 ;pc5=1
call st_pc
call rd_pb ;read pb,data store to pb55
call check_key
jbc key_f,have_state
;row-3 ;74139=>q3=0
mov pcbit,#4 ;pc4=1
call st_pc
mov pcbit,#5 ;pc5=1
call st_pc
call rd_pb ;read pb,data store to pb55
call check_key
jbc key_f,have_state
;
ret
;
have_state:
mov a,keynum
cjne a,#0ffh,is_key
is_key: ret
;-------------------------------------------------------------------------
;**********check key whether true and count key number
check_key:
anl pb55,#0x0f ;pb0-pb3
mov a,pb55
mov counter,#4
nextk: rrc a
jnc dblchk
inc keynum
djnz counter,nextk
ret
;
dblchk: mov keydbl,pb55
mov bounce0,#200 ;about delay time=80mS
chklp: mov bounce1,#250
djnz bounce1,$
djnz bounce0,chklp
call rd_pb ;read pb,data store to pb55
anl pb55,#0x0f ;pb0-pb3
mov a,pb55
cjne a,keydbl,not_key
setb key_f ;have state
ret
not_key: setb key_f
mov keynum,#0ffh ;not key,is bounce or noise
ret
鍵盤掃描修改後程式
scan_key: mov keynum,#0 ;key counter=0
clr key_f ;initial
;
;row-0 ;74139=>q0=0
mov pcbit,#4 ;pc4=0
call cl_pc
mov pcbit,#5 ;pc5=0
call cl_pc
call rd_pb ;read pb,data store at pb55
call check_key
jb key_f,have_state
;row-1 ;74139=>q1=0
mov pcbit,#4 ;pc4=1
call st_pc
mov pcbit,#5 ;pc5=0
call cl_pc
call rd_pb ;read pb,data store at pb55
call check_key
jb key_f,have_state
;row-2 ;74139=>q2=0
mov pcbit,#4 ;pc4=0
call cl_pc
mov pcbit,#5 ;pc5=1
call st_pc
call rd_pb ;read pb,data store to pb55
call check_key
jb key_f,have_state
;row-3 ;74139=>q3=0
mov pcbit,#4 ;pc4=1
call st_pc
mov pcbit,#5 ;pc5=1
call st_pc
call rd_pb ;read pb,data store to pb55
call check_key
jb key_f,have_state
;
ret
;
have_state:
mov a,keynum
cjne a,#0ffh,is_key
clr key_f
is_key: ret
;-----------------------------------------------------------------------
;*********check key whether true and count key number
check_key:
anl pb55,#0x0f ;pb0-pb3
mov a,pb55
mov counter,#4
nextk: rrc a
jnc dblchk
inc keynum
djnz counter,nextk
ret
;
dblchk: mov keydbl,pb55
mov bounce0,#200 ;about delay time=80mS
chklp: mov bounce1,#250
djnz bounce1,$
djnz bounce0,chklp
call rd_pb ;read pb,data store to pb55
anl pb55,#0x0f ;pb0-pb3
mov a,pb55
cjne a,keydbl,not_key
setb key_f ;have state
ret
not_key: setb key_f
mov keynum,#0ffh ;not key,is bounce or noise
ret
系統初始狀態規定
Number Set功能規定
Number Set原始程式
org 00h
;-------register define------
s74clr equ p1.6
s74clk equ P1.7
s74dta equ P1.0
;----------------------------
temp_164 equ 0x7f ;display data
count_164 equ 0x7e
;
numset:
mov temp_164,#0xb0 ;if number 6:83h,3:boh
mov count_164,#8
clr s74clr
nop
setb s74clr
;
next164:
mov a,temp_164
rlc a
mov temp_164,a
;
jc out_h
clr s74dta
call s164clk
jmp loop_164
out_h: setb s74dta
call s164clk
;
loop_164:
djnz count_164,next164
end164: jmp end164 ;jmp=>ret
;
s164clk:
clr s74clk
nop
setb s74clk
ret
;
numcode:
db 0c0h,0f9h,0a4h,0b0h,99h ;number:0-4
db 92h,82h,0f8h,80h,90h ;number:5-9
end
修改後Number Set副程式
mov temp_164, #00h
call num_set
(須將初始條件加入系統初始化中)
;-------register define------
s74clr equ p1.6
s74clk equ P1.7
s74dta equ P1.0
;----------------------------
temp_164 equ 0x7f ;display data
count_164 equ 0x7e
(以上程式片段須移至變數宣告區)
num_set:
mov a, temp_164
mov dptr, #numcode
movc a, @a+dptr
mov temp_164, a
mov count_164,#8
clr s74clr
nop
setb s74clr
;
next164:
mov a,temp_164
rlc a
mov temp_164,a
;
jc out_h
clr s74dta
call s164clk
jmp loop_164
out_h: setb s74dta
call s164clk
;
loop_164:
djnz count_164,next164
ret;
;
s164clk:
clr s74clk
nop
setb s74clk
ret
;
numcode:
db 0c0h,0f9h,0a4h,0b0h,99h ;number:0-4
db 92h,82h,0f8h,80h,90h ;number:5-9
原始系統初始化程式
org 00h
Initial:
mov ctrl55,#82h ;8255 initial status setting
call wr_ctrl ;pa:output,pb:input,pc:output
; ::::::: Initial LCD :::::::
;-------lcm function setting
mov abuf,#38h ; Set for 8 bit data transfer and
call wr_lcdcmd ; address type b,font=5*7
;-------lcm display control
mov abuf,#0eh ; Ture on the display and cursor.
call wr_lcdcmd ; cursor no twinkle
;-------lcm entry model setting
mov abuf,#06h ; Set the LCD unit to increment
call wr_lcdcmd ; the address counter.
;
修改後系統初始化程式
org 00h
clr led_flg
call team_set
mov temp_164, #00h
call num_set
Initial:
mov ctrl55,#82h ;8255 initial status setting
call wr_ctrl ;pa:output,pb:input,pc:output
; ::::::: Initial LCD :::::::
;-------lcm function setting
mov abuf,#38h ; Set for 8 bit data transfer and
call wr_lcdcmd ; address type b,font=5*7
;-------lcm display control
mov abuf,#0eh ; Ture on the display and cursor.
call wr_lcdcmd ; cursor no twinkle
;-------lcm entry model setting
mov abuf,#06h ; Set the LCD unit to increment
call wr_lcdcmd ; the address counter.
;
鍵盤掃描原始主程式
loop:
call scan_key
mov a,keynum
cjne a,#0ah,loop ;判斷是否為Menu鍵
修改後之鍵盤掃描主程式
wait_mu:
call scan_key
jbc key_f, have_mu_s
jmp wait_mu
have_mu_s:
mov a, keynum
cjne a, #0ah, wait_mu
鍵盤掃描與顯示原始主程式
loop:
call scan_key
mov a,keynum
cjne a,#0ah,loop ;判斷是否為Menu鍵
;
sho_menu:
mov dptr,#menu_scr1
call sho_lcm1
mov dptr,#menu_scr2
call sho_lcm2
;---------------------------------------
jmp sho_main
.
.
.
;=======display data array=============
main_scr1: db "TEMI-uC",0
main_scr2: db "2223-9560",0
;=================================
修改後之鍵盤掃描與顯示主程式
wait_mu:
call scan_key
jbc key_f, have_mu_s
jmp wait_mu
have_mu_s:
mov a, keynum
cjne a, #0ah, wait_mu
sho_menu:
mov dptr,#menu_scr1
call sho_lcm1
mov dptr,#menu_scr2
call sho_lcm2
;---------------------------------------
.
.
.
;=======display data array=============
main_scr1: db "該改為什麼?",0
main_scr2: db "該改為什麼?",0
該加入什麼???
;=================================
Number Set流程圖
修改鍵盤掃描與顯示主程式
wait_mu:
call scan_key
jbc key_f, have_mu_s
jmp wait_mu
have_mu_s:
mov a, keynum
cjne a, #0ah, wait_mu
sho_menu:
mov dptr,#menu_scr1
call sho_lcm1
mov dptr,#menu_scr2
call sho_lcm2
;---------------------------------------
.
.
.
;=======display data array=============
main_scr1: db "該改為什麼?",0
main_scr2: db "該改為什麼?",0
該加入什麼???
;=================================
修改後具Number Set及Return功能主程式
wait_mu:
call scan_key
jbc key_f, have_mu_s
jmp wait_mu
have_mu_s:
mov a, keynum
cjne a, #0ah, wait_mu
sho_menu:
mov dptr,#menu_scr1
call sho_lcm1
mov dptr,#menu_scr2
call sho_lcm2
;---------------------------------------
wait_func:
call scan_key
jbc key_f, have_func1_s
jmp wait_func
have_func1_s:
mov a, keynum
cjne a, #01h, have_func2_s
sho_func1:
call lcd_cls
mov dptr, #func1
call sho_lcm1
cpl led_flg
call team_set
wait_func1_num:
該加入什麼???(team_set)
have_func2_s:
mov a, keynum
cjne a, #02h, have_func3_s
call lcd_cls
mov dptr, #func2
call sho_lcm1
wait_func2_num:
call scan_key
jbc key_f, have_func2_num_s
jmp wait_func2_num
have_func2_num_s:
clr c
mov a, keynum
add a, #0f6h ; (f6h+0ah=100h, c=1 and a=00)
jc not_num
mov temp_164, keynum
call num_set
jmp wait_func2_num
not_num:
該加入什麼???(num_set)
have_func3_s:
mov a, keynum
cjne a, #03h, sho_menu
jmp Initial
;=======display data array=============
main_scr1: db "該改為什麼?",0
main_scr2: db "該改為什麼?",0
該加入什麼???
該再加入什麼???(team_set)
該再加入什麼???(num_set)
;=================================