In this tutorial, we will learn How to Blink an LED with DSPIC33FJ64GS606 Microcontroller using MPAB XC16 Compiler.

Product Overview

The DSPIC33FJ64GS606-I/PT is a 16-bit Digital Signal Controller with high-speed PWM, ADC and comparators. The PGECx and PGEDx pins are used for In-circuit Serial Programming™ (ICSP™) and debugging purposes. It is recommended to keep the trace length between the ICSP connector and the ICSP pins on the device as short as possible. The CPU module has a 16-bit (data) modified Harvard architecture with an enhanced instruction set, including significant support for DSP. The CPU has a 24-bit instruction word with a variable length opcode field. The Program Counter (PC) is 23-bit wide and addresses up to 4M x 24 bits of user program memory space.

Product Category:Digital Signal Processors & Controllers – DSP, DSC
Number of Cores:1 Core
Maximum Clock Frequency:40MHz
Flash Memory Size:64KB
No. of I/O’s:58I/O’s
No. of Pins:64Pins
Core Size16-Bit
Oscillator TypeInternal
Core Supply Voltage:2.75V
Voltage – Supply (Vcc/Vdd)3V to 3.6V
Embedded Interface Type:ECAN, I2C, SPI, UART
Operating Temperature Min & Max-40°C to 85oC

Components required table

2PICkit4 Programmer1https://www.amazon.in/MPLAB-PICkit4-in-Circuit-Debugger
4Breadboard – 21https://www.amazon.in/Robotbanao-Solderless-MB102-Breadboard1
5Jumper wires1(set)https://www.amazon.in/YUVS-Jumper-Wires

Software Requirments

  • MPLAB X X16 Compailer

Circuit Diagram

Pin Description

PORTDirection RegisterNumber of PinsAlternative Function
PORTBRB0-RB1516bidirectional I/O port
PORTCRC12-RB154bidirectional I/O port
PORTDRD0-RD1112bidirectional I/O port
PORTERE0-RD78bidirectional I/O port
PORTFRF0-RF67bidirectional I/O port
PORTGRG2-RG98bidirectional I/O port

PIC I/O Register Configurations

TRISxUsed to configure the respective PORT as output/input
PORTxUsed to Read/Write the data from/to the Port pins
LATxUsed to Read/Write the data from/to the Port pins

Source Code

 * File:   main.c
 * Author: Admin
 * Created on  March, 2023, 

// DSPIC33FJ64GS606 Configuration Bit Settings

// 'C' source line config statements

// FBS
#pragma config BWRP = WRPROTECT_OFF     // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_FLASH           // Boot Segment Program Flash Code Protection (No Boot program Flash segment)

// FGS
#pragma config GWRP = OFF               // General Code Segment Write Protect (General Segment may be written)
#pragma config GSS = OFF                // General Segment Code Protection (General Segment Code protect is disabled)

#pragma config FNOSC = FRCDIVN          // Oscillator Source Selection (Internal Fast RC (FRC) Oscillator with postscaler)
#pragma config IESO = ON                // Internal External Switch Over Mode (Start up device with FRC, then switch to user-selected oscillator source)

#pragma config POSCMD = NONE            // Primary Oscillator Source (Primary Oscillator disabled)
#pragma config OSCIOFNC = OFF           // OSC2 Pin Function (OSC2 is clock output)
#pragma config FCKSM = CSDCMD           // Clock Switching Mode bits (Both Clock switching and Fail-safe Clock Monitor are disabled)

#pragma config WDTPOST = PS32768        // Watchdog Timer Postscaler (1:32,768)
#pragma config WDTPRE = PR128           // WDT Prescaler (1:128)
#pragma config WINDIS = OFF             // Watchdog Timer Window (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (Watchdog timer enabled/disabled by user software)

#pragma config FPWRT = PWR128           // POR Timer Value (128ms)
#pragma config ALTSS1 = ON              // Enable Alternate SS1 pin bit (SS1A is selected as the I/O pin for SPI1)
#pragma config ALTQIO = OFF             // Enable Alternate QEI1 pin bit (QEA1, QEB1, INDX1 are selected as inputs to QEI1)

#pragma config ICS = PGD1               // Comm Channel Select (Communicate on PGC1/EMUC1 and PGD1/EMUD1)
#pragma config JTAGEN = OFF             // JTAG Port Enable (JTAG is disabled)

#pragma config HYST0 = HYST45           // Even Comparator Hysteresis Select (45 mV Hysteresis)
#pragma config CMPPOL0 = POL_FALL       // Comparator Hysteresis Polarity (for even numbered comparators) (Hysteresis is applied to falling edge)
#pragma config HYST1 = HYST45           // Odd Comparator Hysteresis Select (45 mV Hysteresis)
#pragma config CMPPOL1 = POL_FALL       // Comparator Hysteresis Polarity (for odd numbered comparators) (Hysteresis is applied to falling edge)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include "p33FJ64GS606.h"
#include "dsp.h"
#include "libpic30.h"

int main(void) {
    // select output pin
    TRISGbits.TRISG3 =  0; // 0 as a Ouput 1 as a Input
    TRISGbits.TRISG2 =  0; // 0 as a Ouput 1 as a Input
    TRISDbits.TRISD2 =  0; // 0 as a Ouput 1 as a Input 
        LATGbits.LATG3 =    1;// led high
        LATGbits.LATG2 =    1; // led high
        LATDbits.LATD2 =    1; // led high
        LATGbits.LATG3 =    0;// led Low
        LATGbits.LATG2 =    0; // led Low
        LATDbits.LATD2 =    0; // led Low


By Devilal

Leave a Reply

Your email address will not be published. Required fields are marked *