本文將使用“三總線”方式連接?8255。
有這樣一個問題:按鍵計數(shù),按一下鍵,顯示數(shù)字加一。
兩個按鍵控制分別控制兩組數(shù)碼管,每個按鍵控制一個兩位數(shù)碼管,顯示十進制數(shù),0到99。
題目給定的電路圖中,共有四個共陰數(shù)碼管,用?8255?的?PA?來驅(qū)動段,位,則使用了單片機?P1?口,按鍵使用了?P2?口。
呵呵,題目給定的電路,看起來,有些雜亂。做而論道修改了一下,如下所示:
;?8255?控制字格式如下:
;+-----+-----+-----+-----+-----+-----+-----+-----+
;|??1??|??PA_FUNC??|PA_IO|PC7_4|PB_F?|PB_IO|PC3_0|
;+-----+-----+-----+-----+-----+-----+-----+-----+
;|??1??|??0??|??0??|??0??|??1??|??0??|??0??|??1??|
;+-----+-----+-----+-----+-----+-----+-----+-----+
;
呵呵,百度這排版格式,把控制字顯示的亂七八糟?!??復(fù)制到記事本再看吧。
仿照題目的要求,用匯編語言編寫了如下的程序:
????ORG???0000H
START:
????MOV???R1,?#03H???;控制寄存器地址
????MOV???A,?#89H????;控制字
????MOVX??@R1,?A?????;PA?PB輸出,?PC輸入
????MOV???SP,?#70H
????MOV???30H,?#01???;初始顯示8031
????MOV???31H,?#255?-?8
????MOV???32H,?#03
????MOV???33H,?#255?-?4
????MOV???34H,?#00
????MOV???35H,?#255?-?2
????MOV???36H,?#08
????MOV???37H,?#255?-?1
????MOV???R4,?#0?????;初值0
????MOV???R5,?#0
????MOV???R1,?#02H???;PC
;----------------------------------初始化結(jié)束
M_LOOP:
????CALL??DISP
????MOVX??A,?@R1
????JNB???ACC.0,?K1_1
????JNB???ACC.1,?K2_1
????JMP???M_LOOP
;---------------------
K1_1:
????CALL??DISP
????MOVX??A,?@R1
????JNB???ACC.0,?K1_2
????JMP???M_LOOP
K1_2:
????CALL??DISP
????MOVX??A,?@R1
????JNB???ACC.0,?K1_2
????INC???R4
????CJNE??R4,?#100,?K1_3
????MOV???R4,?#0
K1_3:
????MOV???A,?R4
????MOV???B,?#10
????DIV???AB
????MOV???34H,?B
????MOV???36H,?A
????JMP???M_LOOP
;---------------------
K2_1:
????CALL??DISP
????MOVX??A,?@R1
????JNB???ACC.1,?K2_2
????JMP???M_LOOP
K2_2:
????CALL??DISP
????MOVX??A,?@R1
????JNB???ACC.1,?K2_2
????INC???R5
????CJNE??R5,?#100,?K2_3
????MOV???R5,?#0
K2_3:
????MOV???A,?R5
????MOV???B,?#10
????DIV???AB
????MOV???30H,?B
????MOV???32H,?A
????JMP???M_LOOP????;主程序循環(huán)
;----------------------------------主程序到此為止
DISP:???????????????;顯示子程序
????PUSH??PSW
????PUSH??ACC
????SETB??RS0
????MOV???R0,?#30H??;顯示緩沖區(qū)首址
????MOV???R1,?#00H??;PA
????MOV???R2,?#4
D_LOOP:
????MOV???A,?@R0
????ADD???A,?#(SEG_TAB?-?$?-?3)
????MOVC??A,?@A?+?PC??
????MOVX??@R1,?A????;寫入PA
????INC???R0
????INC???R1????????;PB
????MOV???A,?@R0
????MOVX??@R1,?A????;寫入PB
????DJNZ??R7,?$
????DJNZ??R7,?$
????MOV???A,?#255???;消隱
????MOVX??@R1,?A????;寫入PB
????INC???R0
????DEC???R1
????DJNZ??R2,?D_LOOP
????POP???ACC
????POP???PSW
????RET
;---------------------
SEG_TAB:
????DB????3FH,?06H,?5BH,?4FH,?66H
????DB????6DH,?7DH,?07H,?7FH,?6FH
;----------------------------------
END
程序啟動后,首先顯示出來?8031,如上面的插圖所示。
以后,分別按動兩個按鍵,即可看到兩組數(shù)碼管分別顯示出來加一、加一的現(xiàn)象。