|
Tài trợ cho PIC Vietnam |
Chương trình dịch & các công cụ mô phỏng Khu vực này chỉ có thành viên diễn đàn mới được vào |
|
Ðiều Chỉnh | Xếp Bài |
21-07-2008, 05:39 PM | #6 |
Đệ tử 2 túi
Tham gia ngày: Feb 2008
Bài gửi: 27
: |
Proteus ko mô phỏng được ngắt? Hay chương trình viết sai?
Hi các bác,
Em có viết đoạn chương trình sau để quét 4 con LED, thực tế em lắp mạch và chạy được rồi tuy nhiên khi mô phỏng bằng Proteus 7.2sp6 thì chương trình báo stack underflow, chạy được vài ngắt rồi đứng yên không chịu chạy nữa. Code như dưới đây: Code:
list p=16f628A ; list directive to define processor #include <p16F628A.inc> ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT ;********************************************************************** ;***** CONSTANTS DEFINITIONS WRITTEN HERE w_temp EQU 0x7D ; variable used for context saving status_temp EQU 0x7E ; variable used for context saving pclath_temp EQU 0x7F ; variable used for context saving LED_CTRL_TRIS EQU TRISA LED_CTRL_PORT EQU PORTA ; dat PORTA la cung la PORT co chan dieu khien quet LED LED1 EQU 0 ; dat chan RA0 dieu khien LED1 LED2 EQU 1 LED3 EQU 2 LED4 EQU 3 LED_DATA_TRIS EQU TRISB LED_DATA_PORT EQU PORTB ; dat PORTB la PORT cap data cho LED ;***** VARIABLES DEFINITIONS WRITTEN HERE ORG 0x20 ;start of general purpose registers ;***** VARIABLES FOR MAIN PROG LED_COUNT RES 1 ; counter for selecting of LED to send data to LED4_DATA RES 1 ; LED data register LED3_DATA RES 1 LED2_DATA RES 1 LED1_DATA RES 1 ;********************************************************************** ORG 0x000 ; processor reset vector goto BEGIN ; go to beginning of program ORG 0x0004 goto INTERRUPT ORG 0x0005 ; interrupt vector location ;********************************************************************** ;***** MAIN PROGRAM GOES HERE BEGIN movlw 0x07 movwf CMCON ;turn comparators off Initialise clrf PORTA clrf PORTB clrf INTCON ; disable all Interrupt sources and some Interrupt Flags SetPorts bsf STATUS, RP0 movlw 0x00 ; dat cac chan cap DATA cho LED la chan Out movwf LED_DATA_TRIS movlw 0x00 ; cac chan dieu khien LED la Out movwf LED_CTRL_TRIS bcf STATUS, RP0 Main ;****** ENABLE TIMER0 INTERRUPT movlw b'10100000' movwf INTCON ; Enable General Interrupt and Timer0 Interrupt bsf STATUS, RP0 ; select bank 1 movlw b'11000011' movwf OPTION_REG ; Initialise Timer0 with 1:16 prescaler bcf STATUS, RP0 ; select bank 0 ;***** movlw b'10111111' ; so 0 movwf LED4_DATA ; set LED data register number 0 movlw b'10000110' ; so 1 movwf LED3_DATA movlw b'11011011' ; so 2 movwf LED2_DATA movlw b'11001111' ; so 3 movwf LED1_DATA clrf LED_COUNT goto $ ;********************************************************************** ;***** INTERRUPT SUB-ROUTINES WRITTEN HERE INTERRUPT movwf w_temp ; save off current W register contents movf STATUS, W ; move STATUS register into W register movwf status_temp ; save off contents of STATUS register movf PCLATH, W ; move PCLATH register into W register movwf pclath_temp ; save off contents of PCLATH register ;***** clrf STATUS ; Chon bank 0 btfsc INTCON, T0IF ; Ngat tran timer0 da xay ra chua? goto T0_INT INT_ERROR goto END_ISR T0_INT ; Xu ly ngat tran timer0 LED4_OUT bcf LED_CTRL_PORT, LED1 clrf LED_DATA_PORT movf LED_COUNT, W xorlw d'0' btfss STATUS, Z ; kiem tra xem co dung thu tu LED4 ko? goto LED3_OUT ; neu ko dung thi qua quet LED3 movf LED4_DATA, W ; neu dung thi quet LED4 movwf LED_DATA_PORT ; send DATA to LED4 (pin RA3 of PORTA) bsf LED_CTRL_PORT, LED4 incf LED_COUNT, F goto END_ISR LED3_OUT bcf LED_CTRL_PORT, LED4 ; tat LED4 clrf LED_DATA_PORT ; xoa data movf LED_COUNT, W xorlw d'1' btfss STATUS, Z goto LED2_OUT movf LED3_DATA, W movwf LED_DATA_PORT ; send DATA to LED3 (pin RA2 of PORTA) bsf LED_CTRL_PORT, LED3 incf LED_COUNT, F goto END_ISR LED2_OUT bcf LED_CTRL_PORT, LED3 clrf LED_DATA_PORT movf LED_COUNT, W xorlw d'2' btfss STATUS, Z goto LED1_OUT movf LED2_DATA, W movwf LED_DATA_PORT ; send DATA to LED2 (pin RA1 of PORTA) bsf LED_CTRL_PORT, LED2 incf LED_COUNT, F goto END_ISR LED1_OUT bcf LED_CTRL_PORT, LED2 clrf LED_DATA_PORT movf LED_COUNT, W xorlw d'3' btfss STATUS, Z goto END_ISR movf LED1_DATA, W movwf LED_DATA_PORT ; send DATA to LED2 (pin RA0 of PORTA) bsf LED_CTRL_PORT, LED1 clrf LED_COUNT ; reset LED counter goto END_ISR END_ISR bcf INTCON, T0IF ; Xoa co ngat tran timer0 ;***** movf pclath_temp, w ; retrieve copy of PCLATH register movwf PCLATH ; restore pre-isr PCLATH register contents movf status_temp, w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp, f swapf w_temp, w ; restore pre-isr W register contents Retfie ; Return from Interrupt ;********************************************************************** END ; directive 'end of program' thay đổi nội dung bởi: dark_electron, 22-07-2008 lúc 08:24 AM. |
Ðiều Chỉnh | |
Xếp Bài | |
|
|