em có viết chương trình bật led dùng ngắt ngoài.Nhưng khi em bấm nút led không sáng, portc không thây đổi mức logic.mong các anh xem giúp sai chỗ nào.
Code:
#include "p16F887.inc" ;CONFIG1 ; __config 0xFFF7 __CONFIG _CONFIG1, _FOSC_EXTRC_CLKOUT & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _IESO_OFF & _FCMEN_OFF & _LVP_OFF ;CONFIG2 ; __config 0xFFFF __CONFIG _CONFIG2, _BOR4V_BOR40V & _WRT_OFF org 0x00 goto main org 0x04 goto ctngat ;================================================= ;khai bao bien cblock 0x20 vong1,vong2,W_SAVE,STAT_SV,PCH_SV,FSR_SV ENDC ;================================================== org 0x05 main ;----------chuong trinh chinh bsf STATUS,RP0 movlw 0x01;RB0 la input movwf TRISB clrf TRISC bsf OPTION_REG,6;ngat canh xuong bcf STATUS,RP0 bcf PORTC,0 bsf INTCON,4 bsf INTCON,7 GOTO $ ;======================================= ctngat ;---------luu gia tri cac thanh ghi------- movwf W_SAVE ; swapf STATUS,w ; clrf STATUS ; MOVWF STAT_SV ; STAT_SV = swap_nibbles MOVF PCLATH, W MOVWF PCH_SV ; PCH_SV = PCLATH clrf PCLATH movf FSR,w MOVWF FSR_SV ; FSR_SV = FSR ;--------------------------------------------- ; btfsc INTCON,INTF ; goto ngat goto thoat_ngat ngat bsf PORTC,0 ;bat led call delay bcf PORTC,0 bcf INTCON,1; ;------------------------------------------------ ;-------------tra lai gia tri cho cac thanh ghi--------------- MOVF FSR_SV, W MOVWF FSR ; FSR = FSR_SV MOVF PCH_SV, W MOVWF PCLATH ; PCLATH = PCH_SV SWAPF STAT_SV, W MOVWF STATUS ; STATUS = swap_nibbles SWAPF W_SAVE,F SWAPF W_SAVE, W ; W = swap BSF INTCON, GIE thoat_ngat RETFIE ;================================================= delay movlw d'20' movwf vong1 movlw d'3' movwf vong2 decfsz vong1 goto $-1 decfsz vong2 goto $-3 return end
Comment