EasyManua.ls Logo

Microchip Technology dsPIC30F - Page 290

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...
dsPIC30F Family Reference Manual
DS70061C-page 14-8 © 2004 Microchip Technology Inc.
Example 14-1: Compare Mode Toggle Mode Pin State Setup
Example 14-2 shows example code for the configuration and interrupt service of the Single
Compare mode toggle event.
Example 14-2: Compare Mode Toggle Setup and Interrupt Servicing
; The following code example illustrates how to define the initial
; OC1 pin state for the output compare toggle mode of operation.
; Toggle mode with initial OC1 pin state set low
MOV 0x0001, w0 ; load setup value into w0
MOV w0, OC1CON ; enable module for OC1 pin low, toggle high
BSET OC1CON, #1 ; set module to toggle mode with initial pin
; state low
; Toggle mode with initial OC1 pin state set high
MOV 0x0002, w0 ; load setup value into w0
MOV w0, OC1CON ; enable module for OC1 pin high, toggle low
BSET OC1CON, #0 ; set module to toggle mode with initial pin
; state high
; The following code example will set the Output Compare 1 module
; for interrupts on the toggle event and select Timer 2 as the clock
; source for the compare time-base. It is assumed in that Timer 2
; and Period Register 2 are properly configured. Timer 2 will
; be enabled here.
CLR OC1CON ; Turn off Output Compare 1 Module.
MOV #0x0003, w0 ; Load the working register with the new
MOV w0, OC1CON ; compare mode and write to OC1CON
MOV #0x0500, w0 ; Initialize Compare Register 1
MOV w0, OC1R ; with 0x0500
BSET IPC0, #OC1IP0 ; Setup Output Compare 1 interrupt for
BCLR IPC0, #OC1IP1 ; desired priority level
BCLR IPC0, #OC1IP2 ; (this example assigns level 1 priority)
BCLR IFS0, #OC1IF ; Clear Output Compare 1 interrupt flag
BSET IEC0, #OC1IE ; Enable Output Compare 1 interrupts
BSET T2CON, #TON ; Start Timer2 with assumed settings
; Example code for Output Compare 1 ISR:
__OC1Interrupt:
BCLR IFS0, #OC1IF ; Reset respective interrupt flag
; Remaining user code here
RETFIE ; Return from ISR

Table of Contents

Other manuals for Microchip Technology dsPIC30F