dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
Example DMA code for the DsPIC33 |
Posted: Fri Jul 11, 2014 4:23 pm |
|
|
Written using CCS PCD Version 5.026 for the DsPIC Processor
After this code starts it blinks an LED on Pin E1 at 1Hz and waits for eight
consecutive characters to arrive via UART1 then prints them on the
terminal. If this simple code doesn't work in hardware with the above
version you have a hardware problem. It is NOT designed to be used in
Proteus!!
Code: |
#include <33FJ256MC710.h>
#FUSES XT
#FUSES NOWDT //No Watch Dog Timer
#FUSES PUT128 //Power On Reset Timer value 128ms
#device ICSP=1
#use delay(internal=16MHZ)
//
#use rs232(baud=9600, UART1,bits=8,parity=N)//
//
#BANK_DMA
char UARTBUFF[8];
//
#INT_DMA0
void DMA0_ISR(void)
{
int i;
printf("Buffer= ");
for(i=0;i<8;++i)
printf("%c", UARTBUFF[i]);
printf("\r\n\n");
}
////////////////////////////////////
/////////// Begin Main /////////////
////////////////////////////////////
void main()
{
setup_ADC_PORTS(NO_ANALOGS);// make sure they dont interfere if we dont need them
//
setup_dma(0, DMA_IN_UART1, DMA_BYTE);
dma_start(0, DMA_CONTINOUS, UARTBUFF);
//
enable_interrupts(INT_DMA0); //enable DMA interrupt
enable_interrupts(GLOBAL); //enable interrupts
//
For(;;)
{ ///////// main loop /////////////////////
output_toggle(pin_E1); // verify the chip is running and at the right speed
delay_ms(500); // led should blink at 1Hz
}
} // end Main Routine
|
_________________ Google and Forum Search are some of your best tools!!!! |
|