第15週筆記 第15週筆記

 

上課筆記:

 

鍵盤掃描原始程式

 

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

 

系統初始狀態規定

 

 

Team Set功能規定

 

 

Team Set原始程式

 

    org   00h

 

 

;===========================================

led_red    equ  p2.2

led_grn    equ  p2.3

led_flg     equ  22h.1               ;led flag,1=>red,0=>green

;===========================================

 

team_set:

        jb     led_flg,red

        jmp  green

;

red:

        clr    led_red                ;red led

        setb  led_grn

        jmp  team_set          ;jmp=>ret

;

green:                                  ;grn led

        clr    led_grn

        setb  led_red

        jmp  team_set          ;jmp=>ret

;

        ;end

 

修改後Team Set副程式

 

clr    led_flg

        call   team_set

(須將初始條件加入系統初始化中)

;=====================================

led_red    equ  p2.2

led_grn    equ  p2.3

led_flg     equ  22h.1               ;led flag,1=>red,0=>green

;=====================================

(以上程式片段須移至變數宣告區)

team_set:

        jb     led_flg,red

        jmp  green

;

red:

        clr    led_red                ;red led

        setb  led_grn

        ret                   ;jmp=>ret

;

green:                                  ;grn led

        clr    led_grn

        setb  led_red

        ret                    ;jmp=>ret

;

       

原始系統初始化程式

 

     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

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

該加入什麼???

;=================================

 

Team 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

該加入什麼???

;=================================

 

修改後具Team 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

;---------------------------------------

 

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:

 

該加入什麼???

 

have_func2_s:

    jmp sho_menu

 

;=======display data array=============

main_scr1:      db    "該改為什麼?",0

main_scr2:      db    "該改為什麼?",0

該加入什麼???

該再加入什麼???

;=================================