• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: p16f877, 關TMR1中斷使用問題
#4
新會員
新會員


查看用戶資訊
謝謝指導。仍無法找到問題所在。
此為範例程式
因配合bootloader,所以:
reset vector 設在0x10, 而interrupt vector設在0x14
其中macro是將W_reg及STATUS狀態先暫存,待程式執行完後
再回存。
在interrupt子程式中只有T1_Int有程式,作為測式TMR1 Interrupt用。

請再次不吝指教。

list p=16f877,r=dec
#include "p16f877.inc"
#include "mymacro.mac"

;******* Define variables here *************

W_Temp equ 0x21
STATUS_Temp equ 0x22
Counter equ 0x23


;******* Start and Interrupt vector *************

org 0x10 ; reset vector
goto Main_Program

org 0x14
goto Int_Service ; interrupt vector

;******* Main Process 'Start' *******************

Main_Program:
call Initial

Main_Program_End:
goto Main_Program_End

;******* Main Process 'End' *********************
;------------------------------------------------
;******* Program Test 'Start' *******************

Program_Test:

Program_Test_End:
return

;******* Program Test 'End' *********************
;------------------------------------------------
;******* Function Call 'Start' ******************

Function_Test:

;------------------------------------------------

Time_Ini:
banksel TMR1H
movlw 0xff
movwf TMR1H
movlw 0xee
movwf TMR1L
return

;------------------------------------------------

Function_Test_End:
retlw 0

;******* Function Call 'End' ********************
;------------------------------------------------
;******* Initial System 'Start' *****************

Initial:
banksel TRISD
clrf TRISD
banksel PORTD
movlw 0x01
movwf PORTD
movlw 0x00
movwf T1CON
clrf Counter
call Time_Ini
banksel INTCON
bsf INTCON, GIE
bsf INTCON, PEIE
banksel PIE1
bsf PIE1,TMR1IE
banksel T1CON
bsf T1CON,TMR1ON

Initial_End:
return

;******* Initial System 'End' *******************
;------------------------------------------------
;******* Interrupt Service 'Start' **************

Int_Service:
PUSH_W_STATUS W_Temp,STATUS_Temp ;Macro

;******* Check interrupt source **************

btfsc INTCON,INTF
goto EX_Int
btfsc INTCON,T0IF
goto T0_Int
btfsc INTCON,RBIF
goto RB_Int

; peripheral 1 interrupt *********************

banksel PIR1
btfsc PIR1,TMR1IF
goto T1_Int
btfsc PIR1,TMR2IF
goto T2_Int
btfsc PIR1,CCP1IF
goto CCP1_Int
btfsc PIR1,SSPIF
goto SSP_Int
btfsc PIR1,TXIF
goto TX_Int
btfsc PIR1,RCIF
goto RC_Int
btfsc PIR1,ADIF
goto AD_Int
btfsc PIR1,PSPIF
goto PSP_Int

; peripheral 2 interrupt *********************

btfsc PIR2,CCP2IF
goto CCP2_Int
btfsc PIR2,BCLIF
goto BCL_Int
btfsc PIR2,EEIF
goto EE_Int

;---------------------------------------------
; Interrupt Service routine ******************

EX_Int:
;******* add your code here ******************

;---------------------------------------------
bcf INTCON,INTF
goto Int_Service_End

T0_Int:
;******* add your code here ******************


;---------------------------------------------

bcf INTCON,T0IF
goto Int_Service_End

RB_Int:
;******* add your code here ******************

;---------------------------------------------
bcf INTCON,RBIF
goto Int_Service_End

T1_Int:
;******* add your code here ******************

call Time_Ini
incf Counter,F
movf Counter,W
sublw 0xa4
btfss STATUS,Z
goto T1_Int_End
bcf STATUS,C
rlf PORTD,W
rlf PORTD,F
clrf Counter

;---------------------------------------------

T1_Int_End:
bcf PIR1,TMR1IF
goto Int_Service_End

T2_Int:
;******* add your code here ******************


;---------------------------------------------
bcf PIR1,TMR2IF
goto Int_Service_End

CCP1_Int:
;******* add your code here ******************

;---------------------------------------------
bcf PIR1,CCP1IF
goto Int_Service_End

SSP_Int:
;******* add your code here ******************

;---------------------------------------------
bcf PIR1,SSPIF
goto Int_Service_End

TX_Int:
;******* add your code here ******************

;---------------------------------------------
bcf PIR1,TXIF
goto Int_Service_End

RC_Int:
;******* add your code here ******************

;---------------------------------------------
bcf PIR1,RCIF
goto Int_Service_End

AD_Int:
;******* add your code here ******************

;---------------------------------------------
bcf PIR1,ADIF
goto Int_Service_End

PSP_Int:
;******* add your code here ******************

;---------------------------------------------
bcf PIR1,PSPIF
goto Int_Service_End

CCP2_Int:
;******* add your code here ******************

;---------------------------------------------
bcf PIR2,CCP2IF
goto Int_Service_End

BCL_Int:
;******* add your code here ******************

;---------------------------------------------
bcf PIR2,BCLIF
goto Int_Service_End

EE_Int:
;******* add your code here ******************

;---------------------------------------------
bcf PIR2,EEIF
goto Int_Service_End

;---------------------------------------------
POP_W_STATUS W_Temp,STATUS_Temp ;Macro

Int_Service_End:
retfie

;******* Interrupt Service 'End' ****************
;------------------------------------------------

end

發表於: 2005/1/11 14:30
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: p16f877, 關TMR1中斷使用問題
#3
高級會員
高級會員


查看用戶資訊
ORG 0x000 ; processor reset vector
clrf PCLATH ; 保證頁位元被清除
goto main ; 到程式開始位址


;**************************************
;*** INTERRUPT SERVICE ROUTINE ***
;*** PROGRAM BY LEE-CHIN-WEI ***
;*** INITIAL DATE : 2003-06-09 ***
;**************************************

ORG 0x004 ; 中斷向量位址
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
BTFSS INTCON,T0IF ; TIMER INT 0 FLAG == 1 ?
GOTO END_INT ; NO THEN RETURN

BCF INTCON,T0IF ; YES THEN CLEAR T0IF FLAG
BSF F_TMAIN ; SET THE MAIN LOOP FLAG=1
MOVLW .6
MOVWF TMR0

; isr code can go here or be located as a call subroutine elsewhere

END_INT:
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

;*********************************************
;*** MAIN SERVICE ROUTINE
;*** INITIAL DATE 2003-06-09
;*********************************************

main
CALL INIT_IO ; initial all IO port
CALL CLEAR_ALL_MEMORY ; clear all memory
CALL SYSTEM_INITIAL ; the system initial service routine
LOOP:
CALL KEY_SCAN ; KEY SCAN
CALL KEY_DEBOUNCE_PROC ; KEY DEBOUNCE PROCESS
CALL CHECK_SYSTEM_TIME ; CHECK THE SYSTEM TIME
CALL FUN_PROC
LOOP1:
BTFSS F_TMAIN ;
GOTO LOOP1 ;
BCF F_TMAIN ;
NOP ;
GOTO LOOP ;
;**************************************
;*** SYSTEM INITIAL SERVICE ROUTINE ***
;*** INITIAL DATE : 2003-06-09 ***
;*** PROGRAM BY LEE-CHIN-WEI ***
;**************************************
SYSTEM_INITIAL:
BANKSEL OPTION_REG ;OPTION_REG IN RAM BANK 1這一點要特別注意
MOVLW B'00000011' ; 1:16 FOR TIMER
MOVWF OPTION_REG
BSF INTCON,GIE
BSF INTCON,T0IE
BANKSEL TMR0
MOVLW .6
MOVWF TMR0
RETLW 0


我想你可能忘了切BANK
我在systems_initial第一行註解你可以看一下

發表於: 2005/1/11 13:34
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: p16f877, 關TMR1中斷使用問題
#2
高級會員
高級會員


查看用戶資訊
把程式貼上
這樣很難替你診斷

發表於: 2005/1/11 13:28
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


p16f877, 關TMR1中斷使用問題
#1
新會員
新會員


查看用戶資訊
小弟最近才接觸PIC16F877。
那位先進有空時請不吝指導下列問題:

在設定Timer1 interrupt時遇到下列問題:
當Timer1 overflow時程式會直接回到 reset vector而不是到
interrupt vector。
小弟有再三確認已設定:
movlw 0x00
movwf T1CON
INTCON GIE, PEIE, 設為1
PIE1 TMR1IE 設為1
最後
t1con TMR1ON, 設為1。
以上。不知問題是發生在那裡。

發表於: 2005/1/11 12:35
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------