Introduction
The dsPIC30F2010 digital signal controller can be programmed using Assembly language that's free of charge from device's supplier. Currently, using a high level programming language is common for most of modern micro-controllers. Unlike a few decade ago, modern micro-controllers have a large amount of ROM (commonly Flash memory), SRAM, and riches of peripherals and functionalities. Due its larger size in RAM and ROM, using a high level programming language such as C, Basic, Pascal, micro-Python are not a problem anymore.
For the 16-bit PIC micro-controller families, there are a lot of C compilers including free or paid versions. Microchip Technology offers many C compilers for their 8-bit, 16-bit and 32-bit MCUs. There free and paid version. However, using a free version has some limited functionalities especially memory optimization.
Paid C compilers for this chip are widely available from many companies such as Custom Computer Service (CSS), MikroElectronika MikroC Pro for dsPIC, IAR Embedded Workbench, etc. However MikroC for dsPIC offers a free version for students and hobbyists with a code compiling limits to below 2KB. That's suitable for most of light-weight applications.
MikroC for dsPIC has a lot of build-in peripheral and hardware libraries. For additional C libraries the user can gets it from LibStocks that contains a lot libraries created by many users.
dsPIC30F2010 LED Blinking in MikroC for dsPIC
Blinking an LED is most common for most of novice embedded system programmers. In MikroC we can do it from scratch. I use my own dsPIC30F2010/dsPIC30F1010 prototype board to test this program. It has on-board LEDs, push buttons, PICKit2 ICSP and 20MHz crystal oscillator. That's no need for auxiliary components.
In this introductory example, the dsPIC30F2010 toggles its output LED connects to RD0 every one second. The clock frequency is driven from the external crystal oscillator without additional Phase Lock Loop (PLL) enabled.
MikroC Source Code:
- void main() {
- ADPCFG = 0xFFFF; // configure AN pins as digital
- TRISD = 0; // set direction to be output
- LATD = 0; // turn OFF the PORTD leds
- while(1){
- LATD=0;
- Delay_ms(1000);
- LATD=0x01;
- Delay_ms(1000);
- }
- }
It will blinks D8 LED connects to RD0 via a DIP switch.
Don't forget to set some parameters for this projects by going to Project -> Edit Project and select as below.
![]() |
| Project Setting |
I use an old 20-year-old DIY PICKit2 Programmer to program this chip. it look likes silly :D.
![]() |
| PICKit2 ICSP Programmer |
In MikroC for dsPIC, programming is quite simple.

PICKit2 ICSP Programmer
The compiler outputs are not only Intel HEX file but also an Assembly code as shown below.
_main:- MOV #2048, W15
- MOV #6142, W0
- MOV WREG, 32
- MOV #1, W0
- MOV WREG, 52
- MOV #4, W0
- IOR 68
- ;blink_dev.c,1 :: void main() {
- ;blink_dev.c,2 :: ADPCFG = 0xFFFF; // configure AN pins as digital
- MOV #65535, W0
- MOV WREG, ADPCFG
- ;blink_dev.c,3 :: TRISD = 0; // set direction to be output
- CLR TRISD
- ;blink_dev.c,4 :: LATD = 0; // turn OFF the PORTD leds
- CLR LATD
- ;blink_dev.c,5 :: while(1){
- L_main0:
- ;blink_dev.c,6 :: LATD=0;
- CLR LATD
- ;blink_dev.c,7 :: Delay_ms(1000);
- MOV #26, W8
- MOV #28274, W7
- L_main2:
- DEC W7
- BRA NZ L_main2
- DEC W8
- BRA NZ L_main2
- ;blink_dev.c,8 :: LATD=0x01;
- MOV #1, W0
- MOV WREG, LATD
- ;blink_dev.c,9 :: Delay_ms(1000);
- MOV #26, W8
- MOV #28274, W7
- L_main4:
- DEC W7
- BRA NZ L_main4
- DEC W8
- BRA NZ L_main4
- ;blink_dev.c,10 :: }
- GOTO L_main0
- ;blink_dev.c,11 :: }
- L_end_main:
- L__main_end_loop:
- BRA L__main_end_loop
- ; end of _main
Now the MCU toggles two LEDs connect to RD0(D8) and RD1(D7) complementary for every one second.
- void main() {
- ADPCFG = 0xFFFF; // configure AN pins as digital
- TRISD = 0; // set direction to be output
- LATD = 0; // turn OFF the PORTD leds
- while(1){
- LATD=0x0001;
- Delay_ms(1000);
- LATD=0x0002;
- Delay_ms(1000);
- }
- }
Two LEDs D8 and D7 will toggle alternately on board. We don't have create a new project since MikroC IDE can handle multiple C source file in one project with different names.


