Menu

728x90

Adskeeper - header widge

Search This Blog

468x60

Navbar

AdsKeeper - IAB Display Standard Ad Unit

Showing posts with label MikroC dsPIC. Show all posts
Showing posts with label MikroC dsPIC. Show all posts

Saturday, October 10, 2026

dsPIC30F2010 MikroC I/O Programming

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.

dsPIC30F2010 MikroC I/O Programming
LED on at RD0

 

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:

 

  1. void main() {
  2. ADPCFG = 0xFFFF; // configure AN pins as digital
  3. TRISD = 0; // set direction to be output
  4. LATD = 0; // turn OFF the PORTD leds
  5. while(1){
  6. LATD=0;
  7. Delay_ms(1000);
  8. LATD=0x01;
  9. Delay_ms(1000);
  10. }
  11. }

 

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.

 

dsPIC30F2010 MikroC I/O Programming
Project Setting

 I use an old 20-year-old DIY PICKit2 Programmer to program this chip. it look likes silly :D.

 

dsPIC30F2010 MikroC I/O Programming
PICKit2 ICSP Programmer

 

In MikroC for dsPIC, programming is quite simple. 

 

dsPIC30F2010 MikroC I/O Programming
PICKit2 ICSP Programmer

 The compiler outputs are not only Intel HEX file but also an Assembly code as shown below.

 


  1. _main:
  2. MOV #2048, W15
  3. MOV #6142, W0
  4. MOV WREG, 32
  5. MOV #1, W0
  6. MOV WREG, 52
  7. MOV #4, W0
  8. IOR 68

  9. ;blink_dev.c,1 :: void main() {
  10. ;blink_dev.c,2 :: ADPCFG = 0xFFFF; // configure AN pins as digital
  11. MOV #65535, W0
  12. MOV WREG, ADPCFG
  13. ;blink_dev.c,3 :: TRISD = 0; // set direction to be output
  14. CLR TRISD
  15. ;blink_dev.c,4 :: LATD = 0; // turn OFF the PORTD leds
  16. CLR LATD
  17. ;blink_dev.c,5 :: while(1){
  18. L_main0:
  19. ;blink_dev.c,6 :: LATD=0;
  20. CLR LATD
  21. ;blink_dev.c,7 :: Delay_ms(1000);
  22. MOV #26, W8
  23. MOV #28274, W7
  24. L_main2:
  25. DEC W7
  26. BRA NZ L_main2
  27. DEC W8
  28. BRA NZ L_main2
  29. ;blink_dev.c,8 :: LATD=0x01;
  30. MOV #1, W0
  31. MOV WREG, LATD
  32. ;blink_dev.c,9 :: Delay_ms(1000);
  33. MOV #26, W8
  34. MOV #28274, W7
  35. L_main4:
  36. DEC W7
  37. BRA NZ L_main4
  38. DEC W8
  39. BRA NZ L_main4
  40. ;blink_dev.c,10 :: }
  41. GOTO L_main0
  42. ;blink_dev.c,11 :: }
  43. L_end_main:
  44. L__main_end_loop:
  45. BRA L__main_end_loop
  46. ; end of _main

Now the MCU toggles two LEDs connect to RD0(D8) and RD1(D7) complementary for every one second.

 

  1. void main() {
  2. ADPCFG = 0xFFFF; // configure AN pins as digital
  3. TRISD = 0; // set direction to be output
  4. LATD = 0; // turn OFF the PORTD leds
  5. while(1){
  6. LATD=0x0001;
  7. Delay_ms(1000);
  8. LATD=0x0002;
  9. Delay_ms(1000);
  10. }
  11. }

 

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.

 

 

 

 

 

Adskeep- Standard Ads

336x280

DIY Electronic Projects And Instruments

AdsKeeper - 2091654

Labels

23K256 (1) 24C16B (2) 25AA010A (2) 8051 (7) 93AA46B (1) ADC (36) Analog Comparator (1) Arduino (16) ARM (32) AT89C52 (7) ATMega32 (59) ATMega644P (27) AVR (88) AVR PCB (2) Bootloader (1) CCS PICC (31) Change Notify Interrupt (CNI) (2) DAC (2) DHT11 (5) Display (149) Distance Sensor (3) dot matrix (1) ds1307 (10) DS18B20 (5) ds3231 (1) ds3232 (2) dsPIC (6) dsPIC30F1010 (3) dsPIC30F2010 (6) EEPROM (5) Environment Sensor (6) ESP32 (1) esp8266 (1) Graphical LCD (3) HD44780 (6) I2C (38) ILI9341 (1) Input/Output (82) Interrupt (22) IoT PCB (1) Keil (5) Keypad (16) KS0108 (3) LCD (79) LM35 (4) Master/Slave (2) MAX7221 (1) MCP23017 (8) MCP23S17 (7) MCP4921 (1) MCP4922 (2) Meter (3) MikroC (2) MikroC ARM (1) MikroC dsPIC (1) Module PCB (2) Motor (15) MPLABX (73) Nokia 5110 LCD (4) OLED (2) One-Wire (7) Oscillator (8) PCB (13) PCD8544 (3) PCF8574 (10) PIC (109) PIC12F (3) PIC16 (105) PIC16F628A (3) PIC16F630 (2) PIC16F716 (4) PIC16F818 (11) PIC16F818/819 (3) PIC16F84A (16) PIC16F876A (2) PIC16F877A (9) PIC16F88 (2) PIC16F887 (60) PIC18 (19) PIC18F1220 (5) PIC18F2550 (5) PIC18F4550 (12) PICKit2 (1) PICMicro PCB (4) Pin Change Interrupt (1) PWM (12) RTC (12) SBN0064G (1) Sensor (14) SH1106 (3) Shift Register (14) Shift Registers (16) SN74HC595N (4) Software TWI (2) SPI (41) ST7735 (1) STM32 (29) STM32 Black Pill (1) STM32 Blue Pill (12) STM32 HAL (23) STM32CubeIDE (32) STM32F103C8T6 (9) STM32F103R6 (18) STM32F401CCU6 (1) SysTick (7) temperature sensor (14) TFT (1) TG12864A (1) Thermometer (22) Timer/Counter (32) TM1637 (2) twi (10) UART (10) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (96)