Home Code DsPIC30F4011 Development Board flashing LED example

DsPIC30F4011 Development Board flashing LED example

by shedboy71

In this article we look at theĀ A look at a DsPIC30F4011 Development Board and we will do a hello world type example where we simply flash the LEDs on the board

Lets look at the dsPic and the LED’s on the schematic. You can see that these are all connected to the RE port

 

Hardware

The board costs about $25

Description Link
DsPIC30F4011 Development Board DsPIC 30F4011 Development Board/dsPIC Experimental Board/System Board/

Code

This is the main code example, the complete project will be posted below

[codesyntax lang=”cpp”]

************************************************* ********************/
/*File description: RE LED flashing*/
/*Hardware configuration: MCU: dsPIC30F4011 development board, OSC: use off-chip 7.3728MHzX16PLL=117.9648MHz oscillator.*/
/*Software configuration: development environment MPLAB X IDE v5.10 compiler XC16 v1.50 */
/************************************************* *******************/
#include "p30f4011.h"
//Configuration bits
_FOSC(0Xc307); //FCKSM = 00; clock switch enable FOS = 0111 main oscillator XT crystal mode external 7.3728MHz
_FWDT(0X0000);//Off dog
_FBORPOR(0X83A2);//MCLREN enable Undervoltage 2.7V Power-up delay 16MS
_FGS(0X03);
void Delay_1ms(unsigned int t)//t = 1000 about 1s
{
    unsigned int i,j;
    for(i = 0;i <t;i ++)
        for(j = 0;j <2000;j ++);
}
//Oscillator configuration
void System_Clock(void)
{
    //Generate Fosc = 7.3728MHz 117.9648MHz 30MIPS
    while (OSCCONbits.COSC!= 0b011)
    while (OSCCONbits.LOCK!= 1) {};//PLL is locked
}
void System_Init(void)
{
    PWMCON1 = 0x0000; //General IO
    TRISE = 0x0000; //Set output
    PORTE = 0xffff;
}
int main()
{
    unsigned char i;
    System_Clock();
    System_Init();
    while(1)
    {
        i ++;
        PORTE = i;
        Delay_1ms(1000);
    }
}

[/codesyntax]

Upload this to your development board, I connected my Pickit4 to the ICSP connection – its a 1 to 1 connection and you should see the LEDs flash in sequence – they are actually counting up

You can see the ICSP and LEDs highlighted below on the development board

DsPIC 30F4011 Development Board LED example

DsPIC 30F4011 Development Board LED example

 

Here is a bonus, this would simply flash all the leds off and then on

[codesyntax lang=”cpp”]

#include "p30f4011.h"
//Configuration bits
_FOSC(0Xc307);//FCKSM = 00; clock switch enable FOS = 0111 main oscillator XT crystal mode external 7.3728MHz
_FWDT(0X0000);//Off dog
_FBORPOR(0X83A2);//MCLREN enable Undervoltage 2.7V Power-up delay 16MS
_FGS(0X03);
void Delay_1ms(unsigned int t)//t = 1000 about 1s
{
     unsigned int i,j;
     for(i = 0;i <t;i ++)
         for(j = 0;j <2000;j ++);
}
//Oscillator configuration
void System_Clock(void)
{
     //Generate Fosc = 7.3728MHz 117.9648MHz 30MIPS
     while (OSCCONbits.COSC!= 0b011)
     while (OSCCONbits.LOCK!= 1) {};//PLL is locked
}
void System_Init(void)
{
     PWMCON1 = 0x0000; //General IO
     TRISE = 0x0000; //Set output
     PORTE = 0xffff;
}
int main()
{
     System_Clock();
     System_Init();
     while(1)
     {
         PORTE = 0x00;
         Delay_1ms(1000);
         PORTE = 0xFF;
         Delay_1ms(1000);
     }
}

[/codesyntax]

 

Link

https://github.com/getelectronics/PICLearning/tree/master/DsPIC30F4011%20Development%20Board/1.LED.X

Share

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More