;****************************************************** ;* EXT_INT.ASM ;* INTCON外部中斷設定,RB0 外接按鍵按下,觸發外部中斷 ;****************************************************** list p=16F877 #include ; VAL_US equ .249 ; 1ms delay 給定初值 VAL_MS equ .250 ; 呼叫1ms Delay之次數 VAL_S equ .4 count equ 0x20 ; 1ms delay 變數位址 count_ms equ 0x21 ; 呼叫1ms Delay之變數位址. count_s equ 0x22 ; ;****** 程式開始 ********************* org 0x00 ; reset vector nop ; Reserve for MPLAB-ICD goto start org 0x04 goto isr start: clrw clrf PCLATH banksel TRISC ; Select to bank1 clrf TRISC ; PORTC = Output banksel PORTC ; Select to bank0 clrf PORTC ; Clear PORTC bsf INTCON,GIE bsf INTCON,INTE inc: incf PORTC,f call delay_250ms goto inc isr: movlw B'11111111' movwf PORTC call delay_250ms bcf INTCON,INTF retfie ; ;-------- 1s delay routine ---------- ;delay_s: ; movlw VAL_S ; movwf count_s ;loop_s call delay_250ms ; decfsz count_s,f ; goto loop_s ; return ;-------- 250 ms delay routine ---------- delay_250ms: movlw VAL_MS movwf count_ms loop_ms call delay_1ms decfsz count_ms,f goto loop_ms return ; ;-------- 1 ms delay routine ----------- delay_1ms: nop movlw VAL_US movwf count dec_loop nop decfsz count,f goto dec_loop return ; end