CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Bootloader for PIC16F876A

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Arnaud
Guest







Bootloader for PIC16F876A
PostPosted: Mon Aug 09, 2004 5:21 am     Reply with quote

Hi,
I am working on a PIC16F876A and I would like to use a bootloader for it. However, the loader.c I have with my compiler (v 3.150) does only work with the PIC16F876. Does a bootloader exist for the A extension ?
Thanks you
Regards
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Aug 09, 2004 6:00 am     Reply with quote

Should work for both.
Sorry
Guest







PostPosted: Mon Aug 09, 2004 6:28 am     Reply with quote

Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Aug 09, 2004 6:44 am     Reply with quote

CCS should have any issues with writing fixed, if there ever were any. The compiler knows which chip you are using (provided you specify the 16F876A) and should handle it correctly. Try it and see.
Arnaud
Guest







PostPosted: Mon Aug 09, 2004 8:48 am     Reply with quote

Hi Mark,
Thank you for your answer. I tried without success tu use loader.c. I programmed my PIC successfully. But under hyperterm I tried to send hex file but nothing happened. I search on this forum how to configure hyperterm and how to send hex file but I did not find any answer.
Could you help me please?
Thank you


Regards
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Aug 09, 2004 8:52 am     Reply with quote

Post you code showing how you implemented it. Also see this:

Quote:

//// The LOADER.C will take an Intel 8-bit Hex file over RS232 ////
//// and modify the flash program memory with the new code. ////
//// ////
//// After each good line, the loader sends an ACK character. The ////
//// driver uses XON/XOFF flow control. Also, any buffer on the PC ////
//// UART must be turned off, or to its lowest setting, otherwise it////
//// will miss data. ////
//// ////
//// A program such as Hyper-Term may be used to simply transmit the////
//// .HEX file output from the compiler. ////
Arnaud
Guest







PostPosted: Mon Aug 09, 2004 9:00 am     Reply with quote

Thank you Marc for your answer
I did not change anything to the CCS loader.c and ex_load.c files excepted the #include <16f876a.h>.
I configured my hyperterm with XON/XOFF 1 stop bit and no parity. I also unchecked FIFO buffers in the COM properties.
I tried "send a file" and "send a text file" with hyperterm and it says that the target is not responding...
So I am a little confused...
What do you think I did wrong
Regards
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Aug 09, 2004 10:16 am     Reply with quote

How did you get it into bootloader mode?
Did you see anything on the Hyperterminal screen?
What board are you using?
Is the circuit good?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Aug 09, 2004 11:50 am     Reply with quote

I used ex_bootloader.c and ex_bootload.c with the 16F876A with no problems.
Arnaud
Guest







PostPosted: Mon Aug 09, 2004 10:51 pm     Reply with quote

I do not have these two files. I only have loader.c eand ex_load.c
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 10, 2004 6:04 am     Reply with quote

Since this is just an example of how to use one of their driver files, I'll post the code. If you are missing any driver files, then contact CCS for them.

ex_bootload.c
Code:

///////////////////////////////////////////////////////////////////////////
////                      EX_BOOTLOAD.C                                ////
////                                                                   ////
////  This program is an example application program that can be       ////
////  be loaded, recompiled and reloaded by a stand alone bootloader.  ////
////                                                                   ////
////  Before loading this program the bootloader (ex_bootloader.c)     ////
////  must be compiled and loaded into the target chip.                ////
////                                                                   ////
////  Use an RS232 link and the SIOW.EXE program to load this HEX file ////
////  into the target chip.  See ex_bootloader.c for more information. ////
////                                                                   ////
////  This example will work with the PCM and PCH compilers.  The      ////
////  following conditional compilation lines are used to include a    ////
////  valid device for each compiler.  Change the device, clock and    ////
////  RS232 pins for your hardware if needed.                          ////
///////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2004 Custom Computer Services           ////
//// This source code may only be used by licensed users of the CCS    ////
//// C compiler.  This source code may only be distributed to other    ////
//// licensed users of the CCS C compiler.  No other use,              ////
//// reproduction or distribution is permitted without written         ////
//// permission.  Derivative programs created using this software      ////
//// in object code form are not restricted in any way.                ////
///////////////////////////////////////////////////////////////////////////


#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12
#endif

#include <bootloader.h>

void main(void) {
   int i=0;

   printf("\r\nApplication program version 1.00 \r\n");

   while(TRUE)
     printf("%u ",++i);

}


ex_bootloader.c
Code:

///////////////////////////////////////////////////////////////////////////
////                      EX_BOOTLOADER.C                              ////
////                                                                   ////
////  This program is an example stand alone bootloader.               ////
////                                                                   ////
////  This program must be loaded into a target chip using a device    ////
////  programmer.  Afterwards this program may be used to load new     ////
////  versions of the application program.                             ////
////                                                                   ////
////  This bootloader is designed to detect pin B5 low on reset.  It   ////
////  will then use the RS232 link to download a new program.          ////
////  Otherwise the application program is started.                    ////
////                                                                   ////
////  Use an RS232 link and the SIOW.EXE program to load a new HEX     ////
////  file into the target chip.                                       ////
////                                                                   ////
////  This example will work with the PCM and PCH compilers.  The      ////
////  following conditional compilation lines are used to include a    ////
////  valid device for each compiler.  Change the device, clock and    ////
////  RS232 pins for your hardware if needed.                          ////
///////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2004 Custom Computer Services           ////
//// This source code may only be used by licensed users of the CCS    ////
//// C compiler.  This source code may only be distributed to other    ////
//// licensed users of the CCS C compiler.  No other use,              ////
//// reproduction or distribution is permitted without written         ////
//// permission.  Derivative programs created using this software      ////
//// in object code form are not restricted in any way.                ////
///////////////////////////////////////////////////////////////////////////

#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12
#endif


#define _bootloader


#include <bootloader.h>
#include <loader.c>


#if defined(__PCM__)
 #org LOADER_END+1,LOADER_END+10
#elif defined(__PCH__)
 #org LOADER_END+2,LOADER_END+20
#endif
void application(void) {
  while(TRUE);
}

#if defined(__PCH__)
#org 0x40,0x7F
#else
#org 0x20,0x3F
#endif
void main(void) {
   if(!input(PIN_B5))
   {
      load_program();
   }

   application();
}

#ORG default

#if defined(__PCM__)
   #int_global
   void isr(void) {
     #asm
       goto LOADER_END+5
     #endasm
   }
#elif defined(__PCH__)
   #int_global
   void isr(void) {
     #asm
       goto LOADER_END+7
       nop
       nop
       nop
       nop
       nop
       nop
       goto LOADER_END+0x17
     #endasm
   }
#endif


bootloader.h
Code:

///////////////////////////////////////////////////////////////////////////
////                       BOOTLOADER.H                                ////
////                                                                   ////
////  This include file must be included by any application loaded     ////
////  by the example bootloader (ex_bootloader.c).                     ////
////                                                                   ////
////  The directives in this file relocate the reset and interrupt     ////
////  vectors as well as reserving space for the bootloader.           ////
////                                                                   ////
////  LOADER_END and LOADER_SIZE may need to be adjusted for a         ////
////  specific chip and bootloader.                                    ////
///////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2004 Custom Computer Services           ////
//// This source code may only be used by licensed users of the CCS    ////
//// C compiler.  This source code may only be distributed to other    ////
//// licensed users of the CCS C compiler.  No other use,              ////
//// reproduction or distribution is permitted without written         ////
//// permission.  Derivative programs created using this software      ////
//// in object code form are not restricted in any way.                ////
///////////////////////////////////////////////////////////////////////////


#if defined(__PCM__)
   #define LOADER_END   0x1FF
   #define LOADER_SIZE   0x1BF
#elif defined(__PCH__)
   #define LOADER_END   0x4FF
   #define LOADER_SIZE   0x3FF
#endif

#ifndef _bootloader

#if defined(__PCM__)
   #build(reset=LOADER_END+1, interrupt=LOADER_END+5)
#elif defined(__PCH__)
   #build(reset=LOADER_END+2, interrupt=LOADER_END+8)
#endif

#org 0, LOADER_END {}

#endif
bdavis



Joined: 31 May 2004
Posts: 86
Location: Colorado Springs, CO

View user's profile Send private message

PostPosted: Tue Aug 10, 2004 10:55 pm     Reply with quote

Arnaud - did you try siow.exe ? Is pin B5 tied low?

Mark - Do you typically just load only the bootloader then later load the application via RS-232? Seems like it could be done also loading bootloader and application at the same time, and later (if FW upgrade), reload the FW.

Is there any good source of info on the bootloader? I was thinking of printing out a string via RS-232, and if the user replied with the correct response in a few seconds, then it would wait for a file to be downloaded or something. The way the example code looks, if RB5 is low, then your app never runs, only the bootloader.

I think CCS should give you and a few others free tools for life for all the posts you do, and all the help you give others Very Happy

I plan on starting to get a PIC bootloader running in the next week or so, so any other ideas, or sources of info would be appreciated.

Thanks,

-Brad
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Aug 11, 2004 5:50 am     Reply with quote

I don't use CCS's bootloader. Kinda simple not many features. I used the 16F/18F one that Microchip has an App note on. Small, seems to work well. They had a VB app to program it which they give you source code for which of course I changed to suit my needs and make it a bit easier for the novice to use.
bdavis



Joined: 31 May 2004
Posts: 86
Location: Colorado Springs, CO

View user's profile Send private message

PostPosted: Wed Aug 11, 2004 1:29 pm     Reply with quote

I looked at the appnote AN851, and its all assembler - did you port it to CCS 'C', or are you keeping it in assembler? I guess it wouldn't hurt to just keep it as assembler... I would like to later be able to concatinate the bootloader with my firmware, so I only have to load it once, but the location and everything like that seems to depend upon the bootloader.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Aug 11, 2004 5:46 pm     Reply with quote

Embarassed I use the C18 and just included the asm file Wink I did modify it just a little. One of my products the bootloader code will actually drive an LCD as a visual to the user. It also had to drive some 74HC165's to read some keys on a keypad. It was still under 0x300 in size. You could probably port it the CCS's asm.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group