inline void Timer23_Setup(void) { OpenTimer23( T2_OFF & T2_IDLE_CON & T2_GATE_OFF & T2_PS_1_256 & T2_32BIT_MODE_ON & T2_SOURCE_INT, PR23); ConfigIntTimer23( T3_INT_PRIOR_2 & T3_INT_ON ); return; }
int main(void) { int dmaChn=0; // the DMA channel to use // first let us set the LED I/O ports as digital outputs mPORTASetPinsDigitalOut(0xff); mPORTAClearBits(0xff); // start with all LED's turned off // Open the desired DMA channel. // We enable the AUTO option, we'll keep repeating the sam transfer over and over. DmaChnOpen(dmaChn, 0, DMA_OPEN_AUTO); // set the transfer parameters: source & destination address, source & destination size, number of bytes per event DmaChnSetTxfer(dmaChn, LED_pattern, (void*)&LATA, sizeof(LED_pattern), 1, 1); // set the transfer event control: what event is to start the DMA transfer DmaChnSetEventControl(dmaChn, DMA_EV_START_IRQ(_TIMER_3_IRQ)); // once we configured the DMA channel we can enable it // now it's ready and waiting for an event to occur... DmaChnEnable(dmaChn); // now use the 32 bit timer to generate an interrupt at the desired LED_BLINK_RATE { int pbFreq=SYS_FREQ/(1<<mOSCGetPBDIV()); // get the PB frequency the timer is running at // use 1:1 prescaler for max resolution, the PB clock OpenTimer23(T2_ON | T2_SOURCE_INT | T2_PS_1_1, (pbFreq/1000)*LED_BLINK_RATE); } while(1) { // do some other useful work } }