EasyManua.ls Logo

Microchip Technology dsPIC30F - Page 255

Microchip Technology dsPIC30F
738 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
© 2004 Microchip Technology Inc. DS70059C-page 12-13
Section 12. Timers
Timers
12
Figure 12-4: Gated Timer Mode Operation
Example 12-4: Initialization Code for 16-bit Gated Time Accumulation Mode
TxIF
0001 0002
TMRx
1 Instruction Cycle (T
CY
)
00040003
TxCK pin
00050000
TxIF bit cleared by user in software.
; The following code example will enable Timer2 interrupts, load the
; Timer2 Period register and start Timer2 using an internal clock
; and an external gate signal. On the falling edge of the gate
; signal a Timer2 interrupt occurs. The interrupt service
; routine must clear the Timer2 interrupt status flag in software .
CLR T2CON ; Stops the Timer2 and reset control reg.
CLR TMR2 ; Clear contents of the timer register
MOV #0xFFFF, w0 ; Load the Period register with
MOV w0, PR2 ; the value 0xFFFF
BSET IPC1, #T2IP0 ; Setup Timer2 interrupt for
BCLR IPC1, #T2IP1 ; desired priority level
BCLR IPC1, #T2IP2 ; (this example assigns level 1 priority)
BCLR IFS0, #T2IF ; Clear the Timer2 interrupt status flag
BSET IEC0, #T2IE ; Enable Timer2 interrupts
BSET T2CON, #TGATE ; Set up Timer2 for operation in Gated
; Time Accumulation mode
BSET T2CON, #TON ; Start Timer2
; Example code for Timer2 ISR
__T2Interrupt:
BCLR IFS0, #T2IF ; Reset Timer2 interrupt flag
; User code goes here.
RETFIE ; Return from ISR

Table of Contents

Other manuals for Microchip Technology dsPIC30F