130 likes | 371 Views
4-12 外部中斷. HT66F50. 中斷來源. 外部中斷 INT0-INT3 PINT ’ 內部中斷 TM LVD SIM. 中斷控制位元. 決定中斷是否啟動 ( enable bit ) : ADE INT0E MF1E … 反應中斷是否發生 ( request flag ): ADF INT0F MF1F. 表 2-4-2 , HT66F50. 11 種 中斷來源 7 個 中斷源 ( 單一周邊 ) INT0 – 1 Comparator 0-1 A/D Time Base 0-1
E N D
4-12 外部中斷 HT66F50
中斷來源 外部中斷 INT0-INT3 PINT’ 內部中斷 TM LVD SIM
中斷控制位元 決定中斷是否啟動(enable bit) : ADE INT0E MF1E… 反應中斷是否發生(request flag): ADF INT0F MF1F
表2-4-2 , HT66F50 • 11種中斷來源 • 7個中斷源 (單一周邊) INT0 – 1 Comparator 0-1 A/D Time Base 0-1 • 4個複功能中斷源 (13個周邊) Multi-function 0-3 TM0P-TM3P TM0A-TM3A TM1B SIM External Peripheral(PINT’) LVD EEPROM
INTC0 - CP0F INT1F INT0F CP0E INT1E INT0E EMI Bit 7 6 5 4 3 2 1 0
INTEDGE (外部中斷觸發條件) • INT0, INT1 引發中斷 cpu 跳至 004h(int0), 008h(int1) - - - - INT1S1 INT1S0INT0S1 INT0S0 Bit 7 6 5 4 3 2 1 0 INT1S1 INT1S0 (INT1’觸發條件選擇位元) =00 禁止INT1’ 中斷 =01 正緣觸發 =10 負緣觸發 =11 雙緣觸發 INT0S1 INT0S0 (INT0’觸發條件選擇位元) =00 禁止INT0’ 中斷 =01 正緣觸發 =10 負緣觸發 =11 雙緣觸發
4-12 外部中斷 ;PROGRAM : 4-12.ASM ;FUNCTION: External INT , 7 SEG 0 – 9 Back to main program #INCLUDE HT66F50.INC #INCLUDE 4-12.INC ;-------------------------------------------------------------------- MY_DATA .SECTION 'DATA' ;== DATA SECTION == DEL1 DB ? DEL2 DB ? DEL3 DB ? COUNT DB ? COUNT2 DB ? STACK_A DB ? ;STACK BUFFER FOR A STACK_PSW DB ? ;STACK BUFFER FOR PSW STACK_DEL1 DB ? ;STACK BUFFER FOR DEL1 STACK_DEL2 DB ? ;STACK BUFFER FOR DEL2 STACK_DEL3 DB ? ;STACK BUFFER FOR DEL3 ;--------------------------------------------------------------------
MY_CODE .SECTION AT 0 'CODE' ;== PROGRAM SECTION == ORG 00H ;HT-66XX RESET VECTOR JMP INIT ORG 04H ;HT-66RXX ADC INTERRUPT ;VECTOR JMP ISR_EXTINT0 INIT: CLR ACERL ;Disable ADC input MOV A,08h ; MOV CP0C,A ; Disable cp0 MOV CP1C,A ; Disable cp1 CLR SEG_PORT ; turn off 7 SEG CLR LED_PORT ; turn off LED CLR SEG_PORTC CLR LED_PORTC ;CONFIG PA AS OUTPUT SET PAPU.3 ;ENABLE PA3 pull-up SET PAC.3 ; CONFIG PA.3 (INT0)as input
MOV A,00000010B ;INT0 falling edge trigger (負緣觸發) MOV INTEG,A SET INT0E ;ENABLE external INTERRUPT 0 SET EMI ;enable global int (總開關) MAIN: MOV A,TAB_7_SEG MOV TBLP,A ;INITIAL POINTER START ADDRESS MOV A,10 MOV COUNT,A ;SET DATA COUNT OF TAB_7_SEG LOOP: TABRDL SEG_PORT ;READ TABLE AND SEND TO SEG_PORT MOVE A,100 ;DELAY 1 sec CALL DELAY INC TBLP ;UPDATE TABLE POINTER SDZ COUNT ;COUNT DOWN BY 1 JMP LOOP ;JUMP IF NOT TABLE END JMP MAIN ;RESTART
;=========================================================== ; EXT INTERRUPT SERVICE ROUTINE ;=========================================================== ISR_EXTINT0: MOV STACK_A,A ;PUSH A MOV A,STATUS MOV STACK_PSW,A ;PUSH STATUS MOV A,DEL1 MOV STACK_DEL1,A ;PUSH DEL1 MOV A,DEL2 MOV STACK_DEL2,A ;PUSH DEL2 MOV A,DEL3 MOV STACK_DEL3,A ;PUSH DEL3 SET LED_PORT.0 ;最右端點亮 MOV A,10 ;DELAY 10ms CALL DELAY ;
RL LED_PORT ;LED port 左旋 check LED_PORT.7 =1 ; 判斷LED 由左至右顯示完畢,若不成立繼 SNZ LED_PORT.7 ; 續左旋 JMP $-4 MOVE A,10 CALL DELAY RR LED_PORT ;LED port 右旋 check LED_PORT.0 =1 ; 判斷LED 由左至右顯示完畢,若不成立繼左旋 SNZ LED_PORT.7 JMP $-4 CLR LED_PORT MOV A,STACK_DEL3 ;POP DEL3 [取回進入中斷服務程式時保留數值] MOV DEL3,A MOV A,STACK_DEL2 ;POP DEL2 MOV DEL2,A MOV A,STACK_DEL1 ;POP DEL1 MOV DEL1,A MOV A,STACK_PSW ;POP STATUS MOV STATUS,A ;POP STATUS MOV A,STACK_A ;POP A CLR INT0F RETI
;===================================================================;=================================================================== ; PROC : DELAY ; FUNC : DEALY ABOUT ACC*1mS @fSYS=4MHz ; PARA : ACC : DELAY FACTOR ; REG : DEL1,DEL2,DEL3 ;=================================================================== DELAY PROC MOV DEL1,A ;SET DEL1 COUNTER DEL_1: MOV A,30 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 DEL_1 RET DELAY ENDP
ORG LASTPAGE TAB_7_SEG: DC 03Fh,006h,05Bh,04Fh,066h; DC 06Dh,07Dh,007h,07Fh,067h; END