130 likes | 272 Views
4.2 LED 查表. HT46R23 程式記憶體 4096 個位址 (0000-FFFFh) 256 個位置為單一程式頁 TBLP 暫存器只有 8 個位元 TABRDC [m] 指令 依據 TBLP 所示位址將目前程式頁之內容讀出 將低 8 位元存入資料記憶體 [m] 中其餘位元存入 TBLH 暫存器 TABRDL [m] 指令依據 TBLP 所示位址將程式最後一頁 (F00-FFFh) 之內容讀出 將低 8 位元存入資料記憶體 [m] 中 其餘位元存入 TBLH 暫存器. HT46R23 與 TBLP TABRDC [m]:@7-@0 表 TBLP 內含值
E N D
HT46R23 程式記憶體4096個位址(0000-FFFFh) • 256個位置為單一程式頁 • TBLP暫存器只有8個位元 • TABRDC [m] 指令 依據TBLP所示位址將目前程式頁之內容讀出 將低8位元存入資料記憶體[m]中其餘位元存入TBLH暫存器 • TABRDL [m] 指令依據TBLP所示位址將程式最後一頁(F00-FFFh)之內容讀出 將低8位元存入資料記憶體[m]中 其餘位元存入TBLH暫存器
HT46R23與 TBLP • TABRDC [m]:@7-@0 表TBLP內含值 • P11-P8:表目前程式計數器高四位元
4-2 ;PROGRAM : 4-2 PROGRAM (4-2.PRJ) ;FUNCTION: DISPLAY 1 PORT LED PILI LIGHT BY STEVEN #INCLUDE HT46R23.INC .CHIP HT46R23 ;-------------------------------------------------------------------- MY_DATA .SECTION 'DATA' ;== DATA SECTION == DEL1 DB ? ;DELAY LOOP COUNT 1 DEL2 DB ? ;DELAY LOOP COUNT 2 DEL3 DB ? ;DELAY LOOP COUNT 3 COUNT DB ? ;-------------------------------------------------------------------- LED_PORT EQU PA ;DEFINE LED PORT LED_PORTC EQU PAC ;DEFINE LED PORT CONTROL REG. MY_CODE .SECTION AT 0 'CODE' ;== PROGRAM SECTION == ORG 00H ;HT-46RXX RESET VECTOR CLR LED_PORTC ;CONFIG PA AS OUTPUT MODE MAIN: MOV A,TAB_PILI MOV TBLP,A ;INITIAL POINTER START ADDRESS MOV A,06 MOV COUNT,A ;SET DATA COUNT OF TAB_PILI
LOOP: TABRDC LED_PORT ;READ TABLE AND SEND TO PA MOV A,80 MOV DEL1,A ;SET DELAY FACTOR CALL DELAY ;DELAY 80*1mS INC TBLP ;UPDATE TABLE POINTER SDZ COUNT ;COUNT DOWN BY 1 JMP LOOP ;JUMP IF NOT TABLE END JMP MAIN ;RESTART TAB_PILI: DC 000000010000001B ;TABLE FOR MDK02 DC 000000001000010B ;"1" FOR TURN ON DC 000000000100100B DC 000000000011000B DC 000000000100100B DC 000000001000010B
;********************************************************************;******************************************************************** ; Delay about DEL1*1mS ;******************************************************************** DELAY PROC MOV A,03 MOV DEL2,A ;SET DEL2 COUNTER DEL_2: MOV A,110 MOV DEL3,A ;SET DEL3 COUNTER DEL_3: SDZ DEL3 ;DEL3 DOWN COUNT JMP DEL_3 SDZ DEL2 ;DEL2 DOWN COUNT JMP DEL_2 SDZ DEL1 ;DEL1 DOWN COUNT JMP DELAY RET DELAY ENDP END
4-2-1 ;PROGRAM : 4-2-1.ASM ;FUNCTION: DISPLAY 1 PORT LED PILI LIGHT (LAST PAGE) BY STEVEN #INCLUDE HT46R23.INC .CHIP HT46R23 ;-------------------------------------------------------------------- MY_DATA .SECTION 'DATA' ;== DATA SECTION == DEL1 DB ? ;DELAY LOOP COUNT 1 DEL2 DB ? ;DELAY LOOP COUNT 2 DEL3 DB ? ;DELAY LOOP COUNT 3 COUNT DB ? ;-------------------------------------------------------------------- LED_PORT EQU PA ;DEFINE LED PORT LED_PORTC EQU PAC ;DEFINE LED PORT CONTROL REG. MY_CODE .SECTION AT 0 'CODE' ;== PROGRAM SECTION == ORG 00H ;HT-46RXX RESET VECTOR CLR LED_PORTC ;CONFIG PA AS OUTPUT MAIN: MOV A,TAB_PILI MOV TBLP,A ;INITIAL POINTER START ADDRESS MOV A,06 MOV COUNT,A ;SET DATA COUNT OF TAB_PILI
LOOP: TABRDL LED_PORT ;LOAD FROM LAST PAGE MOV A,80 MOV DEL1,A ;SET DELAY FACTOR CALL DELAY ;DELAY 80*1mS INC TBLP ;TABLE POINTER+1 SDZ COUNT ;END OF TABLE? JMP LOOP ;NO. NEXT ENTRY. JMP MAIN ;RESTART
;********************************************************************;******************************************************************** ; Delay about DEL1*1mS ;******************************************************************** DELAY PROC MOV A,03 MOV DEL2,A ;SET DEL2 COUNTER DEL_2: MOV A,110 MOV DEL3,A ;SET DEL3 COUNTER DEL_3: SDZ DEL3 ;DEL3 DOWN COUNT JMP DEL_3 SDZ DEL2 ;DEL2 DOWN COUNT JMP DEL_2 SDZ DEL1 ;DEL1 DOWN COUNT JMP DELAY RET DELAY ENDP ORG LASTPAGE ;ORG 0F00H TAB_PILI: DC 000000010000001B ;TABLE FOR MDK02 DC 000000001000010B ;"1" FOR TURN ON DC 000000000100100B DC 000000000011000B DC 000000000100100B DC 000000001000010B END
4-2-2 ;PROGRAM : 4-2-2.ASM (4-2-2.PRJ) ;FUNCTION: DISPLAY 1 PORT LED PILI LIGHT (ADDM A,PCL) BY STEVEN #INCLUDE HT46R23.INC .CHIP HT46R23 ;-------------------------------------------------------------------- MY_DATA .SECTION 'DATA' ;== DATA SECTION == DEL1 DB ? ;DELAY LOOP COUNT 1 DEL2 DB ? ;DELAY LOOP COUNT 2 DEL3 DB ? ;DELAY LOOP COUNT 3 COUNT DB ? INDEX DB ? ;-------------------------------------------------------------------- LED_PORT EQU PA ;DEFINE LED PORT LED_PORTC EQU PAC ;DEFINE LED PORT CONTROL REG. MY_CODE .SECTION AT 0 'CODE' ;== PROGRAM SECTION == ORG 00H ;HT-46RXX RESET VECTOR CLR LED_PORTC ;CONFIG PA AS OUTPUT MAIN: CLR INDEX ;INITIAL POINTER START ADDRESS MOV A,06 MOV COUNT,A ;SET DATA COUNT OF TAB_PILI
LOOP: MOV A,INDEX ;LOAD INDEX TO Acc CALL TRANS_PILI ;LOOK-UP TABLE MOV LED_PORT,A ;SEND TO LED PORT MOV A,80 MOV DEL1,A ;SET DELAY FACTOR CALL DELAY ;DELAY 80*1mS INC INDEX ;TABLE INDEX+1 SDZ COUNT ;END OF TABLE? JMP LOOP ;NO. NEXT ENTRY. JMP MAIN ;RESTART
Delay about DEL1*1mS ;******************************************************************** DELAY PROC MOV A,03 MOV DEL2,A ;SET DEL2 COUNTER DEL_2: MOV A,110 MOV DEL3,A ;SET DEL3 COUNTER DEL_3: SDZ DEL3 ;DEL3 DOWN COUNT JMP DEL_3 SDZ DEL2 ;DEL2 DOWN COUNT JMP DEL_2 SDZ DEL1 ;DEL1 DOWN COUNT JMP DELAY RET DELAY ENDP ;******************************************************************** ; LOOK-UP TABLE BY Acc AS INDEX, AND RETURN DATA IN Acc ;******************************************************************** TRANS_PILI PROC ADDM A,PCL ;PCL=PCL+Acc RET A,10000001B ;RETURN FROM HERE IF Acc=0 RET A,01000010B ;RETURN FROM HERE IF Acc=1 RET A,00100100B ;RETURN FROM HERE IF Acc=2 RET A,00011000B ;RETURN FROM HERE IF Acc=3 RET A,00100100B ;RETURN FROM HERE IF Acc=4 RET A,01000010B ;RETURN FROM HERE IF Acc=5 TRANS_PILI ENDP END
ADDM A,PCL • PC 指向 RET A,10000001B 若 ACC=0, 執行ADDM A,PCL 接著執行RET A,10000001B 回到主程式 ACC=10000001B • ALU 8 bit • 系統將低8位元置於PC<7:0> 即PCL