728x90

728x90

Friday, October 3, 2025

dsPIC30F2010 CCS PICC Bootloaders Example

Overview

A boot-loader is a computer program that is responsible for booting a computer and booting an operating system. If it also provides an interactive menu with multiple boot choices then it's often called a boot manager.

dsPIC30F2010 CCS PICC Bootloaders Example
dsPIC30F2010 ds18B20 Demo Program with Boot Loader

It also applicable for some 8-bit micro-controller with self re-programmable under software control capabilities, for instance the PIC16F877A, PIC16F887, PIC18F4550, dsPIC30F1010, dsPIC30F2010 etc. It's a block of micro-controller program that manage the process of loading embedded program to any location of Flash memory. It must locates at beginning or at the end of micro-controller Flash memory address.

The dsPIC30F2010 is a self re-programmable Flash micro-controller that allow the user to take the advantage of using a boot loader program.

dsPIC30F2010 CCS PICC Bootloaders Example
Program Space Memory Map for dsPIC30F2010

The user just need to burn its boot-loader firmware once using a conventional device programmer, for instance a serial port JDM programmer or even a USB PICKIT3. Then the following embedded program must reserves the boot-loader memory section to prevent ROM program overwriting.  

dsPIC30F2010 CCS PICC Bootloaders Example
Preliminary Boot Loader Firmware Flashing to dsPIC30F2010

The boot loader section should locate at the beginning or at the last section of Flash program memory space. However locating it at beginning is very suitable to prevent boot loader program overwriting that can destroy the boot loader functionalities. 

A boot-load embedded program can be uploaded to its target MCU an appropriate host PC boot-loader software on any OS platform via a typical serial port or even a USB port. CCS PICC provides a serial port and USB port boot-loader for some of their devices.

CCS PICC PCD Boot Loader Example

Boot Loader for 8-bit PIC Micro-controllers  

CCS PICC provide C boot/boot-loader C driver and example for its target chips. For its 8-bit PIC16 and PIC18 chips there are a "bootloader.h" header file and "loader.c" C driver. We can check its "ex_bootloader.c" for boot-loader firmware and "ex_bootload.c" for boot program example. In that example, the boot-loader firmware locates at the beginning of program memory. This example boot the program via RS-232 port.

On the other hand we can use CCS PICC Create Project Wizard to generate a boot-loader firmware for 8-bit PIC micro-controllers. There are two options, boot-loader at the start of memory and boot-loader at the end of memory. 

There many method of bootloading the program such as I2C and USB. 

Boot Loader for 16-bit PIC Micro-controllers  

Since the architecture of 16-bit DSC PIC micro-controllers are far different from the 8-bit PIC micro-controllers, the boot-loader C driver are in separated files. There are two C driver files, the "pcd_bootloader.h" and the "loader_pcd.c" C source files. 

There are two C examples file of using the PCD boot-loader firmware. The "ex_pcd_bootloader.c" is firmware of boot-loader prior to boot program. It requires a user input button and reset button to enter firmware loading mode. The "ex_pcd_bootload.c" C sample program is an example of loading the boot program into the chip. It use CCS PICC Serial Input/Output software and boot-loader software to load the program. In this program the boot-loader section locates at the beginning of the program.

Some newer version of CCS PICC as an instance of CCS PICC v5.119 has problem when compiling the boot-loader firmware for some dsPIC30FXXXX series. However I use an older version of CCS PICC v5.049 instead. It works very well without errors and problems.

dsPIC30F2010 CCS PICC Bootloaders Example
CCS PICC v5.049 IDE

Boot Loader firmware

Initially I need to prepare a boot-loader firmware for my dsPIC30F2010 DSC.

pcd_bootloader.c


  1. /*CCS PICC Compiler version 5.049*/
  2. #include <30F2010.h>
  3. #fuses HS,NODEBUG,NOWDT,PR,CKSFSM
  4. #use delay(clock=20000000)
  5. #use rs232(BAUD=9600,UART1)

  6. #define PUSH_BUTTON PIN_C14
  7. #define BOOT_LED PIN_D0

  8. #define _bootloader
  9. //#define BOOTLOADER_MODE2X

  10. #include <pcd_bootloader.h>
  11. #include <loader_pcd.c>

  12. #org APPLICATION_START
  13. void application(void)
  14. {
  15. while(TRUE);
  16. }

  17. void main(void)
  18. {
  19. output_c(0);
  20. output_d(0);
  21. set_tris_d(0);
  22. set_tris_c(1<<14);
  23. //set_pullup(TRUE,PUSH_BUTTON);
  24. output_high(PUSH_BUTTON);
  25. if(!input(PUSH_BUTTON))
  26. {
  27. output_high(BOOT_LED);
  28. // Let the user know it is ready to accept a download
  29. printf("\r\nWaiting for download...");
  30. // Load the program
  31. load_program();
  32. }
  33. output_low(BOOT_LED);
  34. application();
  35. while(1);
  36. }

  37. #int_default
  38. void isr(void)
  39. {
  40. jump_to_isr(LOADER_END+5);
  41. }


After compile this program I need to burn its hex file into my target chip using a PICKIT2 device programmer.

dsPIC30F2010 CCS PICC Bootloaders Example
Preliminary Boot Loader Firmware Flashing to dsPIC30F2010

From this point the dsPIC30F2010 has a start-of-memory boot-loader firmware. It doesn't need a device programmer any more. That is a blank program that contain only boot-loader section. To test how it works we just, 

1- press and hold the input push button connects to pin RC14

2- at the same time press the reset button and release them.

3- then you will see an LED(pin RD0) turns on the micro-controller enter its loading program mode. 

dsPIC30F2010 CCS PICC Bootloaders Example
The dsPIC30F2010 Prototype Board waiting for program loading

 

dsPIC30F2010 CCS PICC Bootloaders Example
dsPIC30F2010 waiting for loading program from host PC
 

Click here to download this example package.

Boot Load Example Program

From here we can load any firmware with a boot loader setting to dsPIC30F2010 via host PC serial port and CCS PICC boot loader software. I modify the "ex_pcd_bootload.c" to blinks an LED then I load it into the dsPIC30F2010 via CCS PICC boot-loader software.



  1. /*CCS PICC Compiler version 5.049*/
  2. #include <30F2010.h>
  3. #fuses HS,NODEBUG,NOWDT,PR,CKSFSM
  4. #use delay(clock=20M)
  5. #use rs232(UART1,BAUD=9600)

  6. //#define BOOTLOADER_MODE2X

  7. //This is a necessary include file. It reserves space so that the
  8. //bootloader is not overwritten.
  9. #include <pcd_bootloader.h>

  10. #define LED_0 PIN_D1

  11. print_message(void){
  12. delay_ms(10);
  13. printf("\rCCS PICC v5.049 PCD BOOTLOADER\n\r");
  14. }

  15. void main()
  16. {
  17. print_message();
  18. unsigned int16 counter=0;
  19. output_d(0);
  20. set_tris_d(0);
  21. while(TRUE)
  22. {
  23. output_toggle(LED_0);
  24. printf("Counter Variable: %Lu\n\r",counter);
  25. counter++;
  26. delay_ms(1000);
  27. }
  28. }


After compile this program we just press and hold the boot button, and then press and release the reset pin to enter programming loading mode.

Make sure that the SIOW.exe is already open and connected with an appropriate baud rate. 


dsPIC30F2010 CCS PICC Bootloaders Example
press and hold the boot button, and then press and release the reset pin

 

dsPIC30F2010 CCS PICC Bootloaders Example
CCS PICC SIOW Waiting for download

 

dsPIC30F2010 CCS PICC Bootloaders Example
Click on CCS PICC Bootloader tool

 

dsPIC30F2010 CCS PICC Bootloaders Example
Downloading Program

After the program downloading is completed the application on the MCU will run.

dsPIC30F2010 CCS PICC Bootloaders Example
Running Program

 Click here to download this example.

ds18B20 LCD Example with Boot-Loader

I modify my program in this post adding a boot-loader program. However it consumes more program memory. I copied the "ds18b20.c" to my project folder since the older version of v5.049 doesn't have this driver.

  • pcd_bootload_ds18b20_lcd.c
  

  1. /*CCS PICC Compiler version 5.049*/
  2. #include <30F2010.h>
  3. #fuses HS,NODEBUG,NOWDT,PR,CKSFSM
  4. #use delay(clock=20M)
  5. #use rs232(UART1,BAUD=9600)

  6. //#define BOOTLOADER_MODE2X

  7. //This is a necessary include file. It reserves space so that the
  8. //bootloader is not overwritten.
  9. #include <pcd_bootloader.h>

  10. #define PIN_DS18B20_DATA PIN_B0
  11. #include "ds18b20.c"

  12. #define LCD_RS_PIN PIN_E4
  13. #define LCD_RW_PIN PIN_E5
  14. #define LCD_ENABLE_PIN PIN_E5
  15. #define LCD_DATA4 PIN_E0
  16. #define LCD_DATA5 PIN_E1
  17. #define LCD_DATA6 PIN_E2
  18. #define LCD_DATA7 PIN_E3

  19. #include "lcd.c"

  20. #define lcd_clear() lcd_putc('\f')
  21. #define lcd_home() lcd_putc('\a')
  22. /*For 16x4 LCD Only*/
  23. #define line_1() lcd_send_byte(0,0x80);
  24. #define line_2() lcd_send_byte(0,0xC0);
  25. #define line_3() lcd_send_byte(0,0x90);
  26. #define line_4() lcd_send_byte(0,0xD0);

  27. print_message(void){
  28. delay_ms(10);
  29. printf("\rCCS PICC v5.049 PCD BOOTLOADER\n\r");
  30. }

  31. void main(){
  32. print_message();
  33. signed int16 val;
  34. printf("\n\rdsPIC30F2010 Prototype Board.");
  35. printf("\n\rSaturday 26th September 2025");
  36. printf("\n\rds18b20 Humidity Sensor Example\n\r");
  37. printf("\r\n\r\ds18b20.c - DHT11 example starting\r\n\r\n");
  38. ds18b20_init();
  39. lcd_init();
  40. printf(LCD_PUTC,"dsPIC30F2010 LCD");
  41. line_2();
  42. printf(LCD_PUTC,"ds18b20 Sensor");
  43. line_3();
  44. printf(LCD_PUTC,"PCD BootLoader");
  45. line_4();
  46. printf(LCD_PUTC,"CCS PICC v5.049");
  47. delay_ms(5000);
  48. lcd_clear();
  49. while(1){
  50. ds18b20_read(&val);
  51. printf("temperature = %ldC\r\n", val/(signed int16)16);
  52. lcd_home();
  53. printf(LCD_PUTC," ds18b20 Sensor");
  54. line_2();
  55. printf(LCD_PUTC," Temperature");
  56. line_3();
  57. printf(LCD_PUTC," %ld%cC",val/(signed int16)16,0xDF);
  58. line_4();
  59. printf(LCD_PUTC," and %f%cF",1.8*(val/(signed int16)16)+32,0xDF);
  60. delay_ms(1000);
  61. }
  62. }

Since the boot-loader section locates at the start of program memory. It doesn't matter even the the compiled boot-load application exceeds the the ROM capacity. It just has an abnormal function.

dsPIC30F2010 CCS PICC Bootloaders Example
CCS PICC Memory Use


 I tested it on my DIY dsPIC30F2010 Prototype Board.

dsPIC30F2010 CCS PICC Bootloaders Example
Downloading the program

 

After uploading this program we can see the result.

dsPIC30F2010 CCS PICC Bootloaders Example
Data send over serial port

 This C driver work fine as I prototype it on my PCBA.

dsPIC30F2010 CCS PICC Bootloaders Example
dsPIC30F2010 ds18B20 Demo Program with Boot Loader

 
dsPIC30F2010 CCS PICC Bootloaders Example
ds18B20 Temperature Sensor Reading

Click here to download this example.

DHT-11 LCD Example with Boot-Loader

I add this boot-load feature to my previous programming example that the dsPIC30F2010 read the humidity and temperature data from a DHT-11 environmental sensor. The result will display on a TC1604A-04 16x4 LCM. 



  1. /*CCS PICC Compiler version 5.049*/
  2. #include <30F2010.h>
  3. #fuses HS,NODEBUG,NOWDT,PR,CKSFSM
  4. #use delay(clock=20M)
  5. #use rs232(UART1,BAUD=9600)

  6. //#define BOOTLOADER_MODE2X

  7. //This is a necessary include file. It reserves space so that the
  8. //bootloader is not overwritten.
  9. #include <pcd_bootloader.h>

  10. #define LED_0 PIN_D1

  11. #define PIN_DHT11_DATA PIN_B0
  12. #include "dht11.c"
  13. #define LCD_RS_PIN PIN_E4
  14. #define LCD_RW_PIN PIN_E5
  15. #define LCD_ENABLE_PIN PIN_E5
  16. #define LCD_DATA4 PIN_E0
  17. #define LCD_DATA5 PIN_E1
  18. #define LCD_DATA6 PIN_E2
  19. #define LCD_DATA7 PIN_E3

  20. #include "lcd.c"

  21. #define lcd_clear() lcd_putc('\f')
  22. #define lcd_home() lcd_putc('\a')
  23. /*For 16x4 LCD Only*/
  24. #define line_1() lcd_send_byte(0,0x80);
  25. #define line_2() lcd_send_byte(0,0xC0);
  26. #define line_3() lcd_send_byte(0,0x90);
  27. #define line_4() lcd_send_byte(0,0xD0);

  28. print_message(void){
  29. delay_ms(10);
  30. printf("\rCCS PICC v5.049 PCD BOOTLOADER\n\r");
  31. }

  32. void main()
  33. {
  34. print_message();
  35. unsigned int8 relativeHumidity;
  36. unsigned int8 tempC;
  37. printf("\n\rdsPIC30F2010 Prototype Board.");
  38. printf("\n\rFriday 26 September 2025");
  39. printf("\n\rDHT-11 Humidity Sensor Example\n\r");
  40. printf("\r\n\r\dht-11.c - DHT11 example starting\r\n\r\n");
  41. dht11_init();
  42. lcd_init();
  43. printf(LCD_PUTC,"dsPIC30F2010 LCD");
  44. line_2();
  45. printf(LCD_PUTC,"DHT-11 Sensor");
  46. line_3();
  47. printf(LCD_PUTC,"PCD BootLoader");
  48. line_4();
  49. printf(LCD_PUTC,"CCS PICC v5.049");
  50. delay_ms(5000);
  51. lcd_clear();
  52. while(1){
  53. dht11_read(&relativeHumidity, &tempC);
  54. printf("HUMIDITY=%03u%%, TEMPERATURE=%02uC\r\n", relativeHumidity, tempC);
  55. lcd_home();
  56. printf(LCD_PUTC," DHT-11 Sensor");
  57. line_2();
  58. printf(LCD_PUTC," Reading:");
  59. line_3();
  60. printf(LCD_PUTC,"Humidity: %03u%%",relativeHumidity);
  61. line_4();
  62. printf(LCD_PUTC,"Temperature:%02u%cC",tempC,0xDF);
  63. output_toggle(LED_0);
  64. delay_ms(1000);
  65. }
  66. }

 The total line of program instructions is less then the previous example (275 instructions).

M:\ccs picc\v5.049\dsPIC30F2010\pcd_bootload_dht11 - 1604LCD\Media
Program Uploading

 The sensor data also send over the PC serial port.

 

dsPIC30F2010 CCS PICC Bootloaders Example
CCS PICC SIOW Data Sending

dsPIC30F2010 CCS PICC Bootloaders Example
Start-Up Program


dsPIC30F2010 CCS PICC Bootloaders Example
Environmental Data Reading/Displaying

 


Click here to download this example.


No comments:

Post a Comment

320x50

Search This Blog

tyro-728x90