Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16F886/16F887 Serial Boot Loader

Status
Not open for further replies.

Mike - K8LH

Well-Known Member
Just got around to testing and debugging a 16F886/887 serial bootloader yesterday that I had written several months ago.

Like my other 16F' bootloaders it resides in the first 256 words of program memory space, uses a "trigger" pin to enter the bootloader during power up or reset, and uses Hyperterminal as the PC "front end".

Transfer standard hex files (which may include holes in program memory space) using the Hyperterminal <Transfer> menu and <Send Text File...> menu item.

I know many people don't like dedicating a pin for the boot loader "trigger" but up 'til now I've always been able to use an existing allocated pin. For example, on many of my projects I include a miniature piezo speaker which I use for switch press beep or other annunciator type functions. If I install a jumper and a pull-up on the speaker pin as shown in the drawing below, the boot loader can detect a high on this "trigger" pin when the jumper is removed or read a low on the pin when the jumper is installed. You can also use an existing switch on the project as the "trigger". Normally you don't press a switch while powering up or resetting a project so pressing the switch during power up or during reset makes a perfect boot loader "trigger".

Regards, Mike
 

Attachments

  • Trigger.PNG
    Trigger.PNG
    6.3 KB · Views: 1,167
  • 16F887 Boot 24.asm.txt
    20.6 KB · Views: 1,183
Last edited:
hi Mike,
Hope you dont mind.:)

Converted your loader to 16F877A, [have no 16F887 on hand]
Runs OK in the Oshonsoft Sim.

Always find your programs of interest.
 

Attachments

  • esp01 Aug. 12.gif
    esp01 Aug. 12.gif
    10.6 KB · Views: 892
Hi Eric,

I don't mind. Please let me know if it works?

I took a quick look at my old 16F877A version 1 boot loader code from 2004 and the algorithm looks similar but I would have to take a closer look to make sure there are no banking differences. The '877A requires you to setup the TRISC bits for the UART pins (the '877 does this for us) so that would have to be added to the code.

I have version 2 boot loaders for; 16F87/88, 16F886/887, 18F2420/4420, 18F2431/4431, and 18F2620/4620. I just upgrade old version 1 boot loaders to version 2 as needed.

Your simulation looks much like "the real thing" (below).

Have fun. Mike

loader-2-4-screen-shot-png.21643
 

Attachments

  • loader 2.4 screen shot.PNG
    loader 2.4 screen shot.PNG
    26.9 KB · Views: 4,081
Last edited:
Eric (and gang),

Caveat! I just found and corrected an error and updated the program source file in the first post (12-Aug-08 @ 1205 UTC)... I was using byte count rather than word count in the EEProm code... Sorry for the inconvenience fellows...

Mike
 
887 bootloader

Mike,
I finally got your boot loader working but when i read the contents of the PIC after you bootloader said "OK", it looks like there is a pattern of memory that is not written to in the pic. Have you had a problem with this before?
 
RE: 887 bootloader

I have attached the file. When I compile a program using MPASM there is no problem. Though I am using Hi -Tech PICC compiler and maybe the hex file is in a slightly different format.
View attachment 887_test.hex.txt
test.gif
The left side of the pic shows the program memory from MPLAB, and the right side shows the memory read from the pic after using the bootloader. You can see on the right the highlighted blocks havent been written to. its looks like the loader write the first 16 blocks of data, [skips 4, writes 12, skips 4, writes 12]..etc this pattern repeats till the end.
 
I'm sorry, my bootloader is not compatible with that PICC hex file output.

Until now I've not seen a compiler that generates hex records with data that crosses a 16 word boundary.

Mike
 
Mike,
I remember reading somewhere that the PICC compiler can generate different output formats, I will look into that and let you know if I find anything. I also had another problem using MPASM. I modified your loader to display a "hello world" when my device is powered up, the problem is that when i load the program without the loader its works as expected, but when I load the file with the loader (using org h'0100' to relocate for bootloader) the output to my terminal displays funny characters instead of "hello world".

I get some warnings when compiling your bootloader using MPASM 5.20 is this normal (the line numbers should match you original loader):
Warning[202] C:\BOOTLOADER_TEST\16F887 BOOT 24.ASM 181 : Argument out of range. Least significant bits used.
Warning[202] C:\BOOTLOADER_TEST\16F887 BOOT 24.ASM 268 : Argument out of range. Least significant bits used.
Warning[202] C:\BOOTLOADER_TEST\16F887 BOOT 24.ASM 305 : Argument out of range. Least significant bits used.

here is the file that suppose to spit out "hello world"
View attachment 16F887 Boot led.HEX.txt

Also, where would I have to add a line of code that will add '1' to every byte that gets written to the PIC when in bootloader mode. The reason I ask this is Im planning on adding a little decryption routine inside the loader.

I appreciate your help so far.
 
I get some warnings when compiling your bootloader using MPASM 5.20 is this normal (the line numbers should match you original loader):
Warning[202] C:\BOOTLOADER_TEST\16F887 BOOT 24.ASM 181 : Argument out of range. Least significant bits used.
Warning[202] C:\BOOTLOADER_TEST\16F887 BOOT 24.ASM 268 : Argument out of range. Least significant bits used.
Warning[202] C:\BOOTLOADER_TEST\16F887 BOOT 24.ASM 305 : Argument out of range. Least significant bits used.

Those three warnings are normal.

I'm sorry I can't help you with your PICC + bootloader problems.

Mike
 
Mike,
Thats ok. Thanks for you help anyway. I have been trying to convert a 877a bootloader to work instead. I got it compiling ok for the 887 but it starts to write the code over the bootloader. Do you use any software to simulate/test your bootloader? I cant seem to find any simulators that support writing to internal program memory. Im using Proteus VSM which supports everything else except writing to program memory. Any Ideas?
 
Problem with 16F887 Boot 24.ASM

Hi Mike!
I am working with 16F886/7 chips and just discovered your version of the bootloader. I am using it with an hybrid Atmel Atmega8 USB/RS232 interface and a Delphi Window application to send the HEX file to the chip.
I have however a problem with writing the EEPROM as it quits immediately after the 8th byte - If I remove the code where I imbed the EEPROM (ORG 2100h dt 'Date here...') I get the Ok message at the end. I use a very standard MPASM hex file.
I know you have mentioned having updated your code to correct a byte from word error - My question is: is the code available for download shown in your first post the correct one or is there one available elsewhere?

Thanks,

Robert Cote / derosoft
MiniDCC Digital Command Control - New uppdated Version
 
Hello Mike,


I have been unable to get your code to work properly on either an 16F886 or 16F887 using an mpasm generated hex file. The code portion works properly however the EEPROM data does not register properly - I get the first row with 8 bytes and the additonal 8 bytes rewrite over the first one. If I try with a longer string, the second row gets written, but never pass the 8th byte...
When I build directly with the MPLAB, the date is correctly programmed.

I have studied your code very carefully and ran it in debug but I can't figure out what is happening on the second row of EEPROM data...

Can someone help?

Thank you,

Robert
 
I will take a look at it this week. You might want to post the particular hex file you're using for me to test.

Mike
 
Wow! that was quick!
Thanks for taking the time to test it out. Here is the hex file and a picture from the EEPROM screen on the MPLAB.
My first post on this site so I am not sure if the attachments will work...

Regards,

Robert
 

Attachments

  • 16f886Test.HEX.txt
    323 bytes · Views: 368
  • EEPROM.jpg
    EEPROM.jpg
    66.6 KB · Views: 460
Mike,
further to my previous post, here is the actual information from the asm file with regards to the EEPROM data, as well as the output from MPLAB if when I programme the chip using MPLAB ICd2.
The program code just sets up the internal oscillator to 8 MHz and loops on itself.
Thanks again,

Robert
 

Attachments

  • EEPROM_DATA.jpg
    EEPROM_DATA.jpg
    18.2 KB · Views: 253
  • EEPROM_Display.jpg
    EEPROM_Display.jpg
    62.9 KB · Views: 262
Hi Robert,

Try using the 'de' directive instead of the 'dt' directive and see if that makes a difference.

Code:
        org     0x2100
        de      "0123456789abcdefgh"
        de      "ijklmnopqrstuvwxyz"
 
Mike,
I tried with the DE directive but it makes no difference, although the HEX file is slightly different, as seen in this dump. As well I get the same "Ok" message at the end of the transfer but the EEPROM memory block still the overwritten data in the first 8 bytes of the line, not going over the end...


Robert
 

Attachments

  • 16f886Test_DE_Directive.HEX.txt
    323 bytes · Views: 211
Robert,

I just setup an '887 bootloader board and verified there is some type of problem. Let me investigate.

Mike
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top