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

How to program PIC16F877A through rs232

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



Joined: 04 Aug 2005
Posts: 21

View user's profile Send private message

How to program PIC16F877A through rs232
PostPosted: Wed Oct 19, 2005 9:44 pm     Reply with quote

Hi everyone..

I need some help in this matter...
I've heard something about boot loader...
But i dont quite understand..
Is there anyway i can include this features (reprogram my PIC through RS232) without the need to by extra software?
The hardware would be our PC and PIC usart...

I really2 appreciate ur help~
Thanx soo much! Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 19, 2005 9:58 pm     Reply with quote

Go here and look at the link for PIC16F87xA bootloader:
http://www.microchipc.com/
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Oct 19, 2005 10:12 pm     Reply with quote

Search the web - you will find plenty of information on bootloaders.
Microchip has application notes for implementing your own. A bootloader is a small program that you program into the PIC using a typical PIC programmer. Once the bootloader is installed you can use the bootloader to install new fireware into the PIC.

Bootloaders come in multiple flavours. You can get bootloaders than can load code via serial interfaces (RS232, RS485) these may use the embedded UART or use bit banging techniques. These are also USB, Ethernet and SPI bootloaders. You can use virtually any bidirectional bus.

Bootloader capabilities vary significantly. Some bootloader are used to program only and replace the entire image at one. Others allow you to change just a single byte. Some bootloaders enable you to upload code from a PIC and selectively erase EEPROM, PROGRAM memory etc.

Some bootloaders require just a terminal program, others require a specific application - each approach has specific tradeoffs.

Bootloaders also differ on how they present themselves. The type of bootloader I use gains control of the PIC at power up for a few seconds, enough time to determine if it is required to be in bootloader mode. If not it passes control to the users program. This type of bootloader does not use any system resources other than the program memory space. Other bootloaders coexist with the operation image. In which case the bootloader can be invoked at any time (does not require resetting the PIC) but this type of bootloader generally requires additional system resources (memory).

Some bootloaders are located in low memory. These bootloaders generally require the user program be compile to coexist with the bootloader. This apporach also requires that the boot loader relocate the interrupt vectors which means that an interrupt will require a double jump and return. For time critical applications (latency sensitive) this time of bootloader can be a problem. The other approach is the bootloader is located in high memory. These bootloaders are generally tranparent to the application (do not normally require the application code to be relocated) with the following exception. Bootloaders, either type, remap the reset vector. In general a PIC application program must execute a long jump within the first four instructions.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
John_Lintern



Joined: 30 Sep 2004
Posts: 14

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

PostPosted: Thu Oct 20, 2005 3:04 am     Reply with quote

I have recently used the bootloader that comes with the examples for the CCS compiler called "ex_bootloader.c"

Have you got this example ?

By pulling a pin low when you reset the PIC, the bootloader is activated and you can use a serial port monitor program (like the one in CCS) to re-program your PIC.

I started using the PIC16F877A, but then went onto use the PIC18F452.

They are pin for pin compatible devices.

One of the reasons I chose to use the PIC18F452 instead was because it does a FULL reset after the bootloader has re-programed the PIC.

The PIC16F877A does not do a full reset (i.e. some registers are not reset), although I think you could use an output pin connected to the reset pin to get around this if it was a problem ?

To use the bootloader you compile the program ex_bootloader.c and use a programmer (such as PICStart Plus) to program the bootloader into the PIC.

You will always need a programmer to program the bootloader into the PIC the first time round.

From that point on you dont need the programmer and you can re-program the PIC using the serial port (providing you dont overwrite the bootloader!).

All you need to do in your own application code is include the file bootloader.h....

i.e.

#include <bootloader.h>

This redirects the reset and interrupt vectors.

You only include bootloader.h when you are re-programing a PIC using the bootloader.

If you are not using the bootloader to reprogram the PIC (i.e. you use PICStart Plus etc) do not include bootloader.h.

To reprogram just pull a pin low (as defined in ex_bootloader.c) whilst reseting the PIC.

Then you can reprogram your PIC using the serial port.
ChickyMeal
Guest







PostPosted: Sun Oct 23, 2005 10:31 pm     Reply with quote

Thanx John..

Right now im trying to compile the ex_bootloader.c..
This error kept popping:

*** Error 12 "C:\PIC PROGRAM\BootLoader C\bootielicous.c" Line 83(4,15): Undefined identifier jump_to_isr

what is this mean? im quite new in writing code in C (i used to write in assembly).. so a lot of things look gibberish to me.. what else do i need to alter to use the program for p16f877a? please advise..

Thanx so much..
John_Lintern



Joined: 30 Sep 2004
Posts: 14

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

PostPosted: Mon Oct 24, 2005 2:12 am     Reply with quote

jump_to_isr is a function.

for some reason when you are compiling your code the function is not defined or recognised by the compiler.

what version of compiler are you using ?

in CCS go to 'Help' ---> 'About' and list the compiler you are using (Im using PCWH Compiler) and also list the versions.

i 'think' jump_to_isr is a function that was added to later versions of the compiler.

but if you have the ex_bootloader.c then you should have the right version of compiler to use the example.

i did find something somewhere about the function jump_to_isr but i cant find it now !

email me your code and ill try to compile it or copy your code on a reply to this post.

just to confirm....

1 - you are only compiling ex_bootloader.c at the moment and you have made no changes to it yet.... have you ?

this is a single, seperate program, which you will need to burn to your PIC using a programmer.

there is another example ex_bootload.c.

forget about this example, its just a test program for you to download using the serial port which writes some text to the screen.

2 - in your own application code (which you want to download to the PIC using the serial port) all you need to do is include bootloader.h. So at the top of your own appication code you need to have...

#include <bootloader.h>

3 - ex_bootloader.c has been written for use on either the PIC16F877 or the PIC18F452. You will see the include files for both of these devices (#include <16F877.h> and #include <18F452.h>).
if __PCM__ is defined it will compile for the PIC16F877, if __PCH__ is defined it will compile for the PIC18F452.
__PCM__ or __PCH__ is defined automatically depending on what compiler version you have. i.e. as I have the PCWH compiler then __PCH__ is automatically defined (somewhere?) so it compiles for the PIC18F452.

As you want to use the PIC16F877, you can change the following code in ex_bootloader.c....


Code:

#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


to....

Code:

#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


Let me know how you get on.

PS. i am quite new to all this as well !
teletype-guy



Joined: 11 Oct 2005
Posts: 8
Location: AZ

View user's profile Send private message Visit poster's website

PostPosted: Mon Oct 24, 2005 1:53 pm     Reply with quote

I agree with PCM-Programmer. This one has worked for years for me. You burn the bootloader into the pic once, and then use the downloader app from a winblows pc to send the hex file from your ccs compiler to the 16F part over the serial port. The download speed is 19200 (iirc), but your app can change the port speed at run time. There is an 18F version that works very well also.

http://www.microchipc.com/PIC16bootload/
ChickyMeal
Guest







PostPosted: Mon Oct 24, 2005 6:34 pm     Reply with quote

JoHn... i've change the code as u suggest but it still prompt the same error.. here is my code..

Code:
//#if defined(__PCM__)
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#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

#int_global
void isr(void)
{
   jump_to_isr(LOADER_END+5*(getenv("BITS_PER_INSTRUCTION")/8));
}


FYI... i dont have pcwh, i'm using pcm and pch compiler with mplab..
my pcm version is 3.222...

teletype-guy and PCM programmer.. i've tried the shane tolmie's before this.. but somehow it kept 'searching for bootloader'... im not sure why it cannot find my pic... so i'd like to try this ex_bootloader instead... Confused

Thanx GuyS~
John_Lintern



Joined: 30 Sep 2004
Posts: 14

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

PostPosted: Tue Oct 25, 2005 4:20 am     Reply with quote

I copied and pasted your code into my version of CCS and it compiled without any errors.

So it must be something to do with your version or installation of CCS ?

Are you able to get an update of your PCM and PCH compiler ?

I dont know what the differences between the PCM and PCH and PCWH compilers are.

When I go to 'Help'--->'About' it says the following...

PCWH Compiler

IDE Version 3.231
PCB Version 3.231
PCM Version 3.231
PCH Version 3.231

I had a look in the C:\Program Files\PICC directory where CCS is installed and did a search for jump_to_isr

There is a readme.txt file which says the following...

A new function has been added to jump from the real PIC interrupt vector to a relocated vector. This is usefull for bootloaders. See bootloader.c for an example.

JUMP_TO_ISR(relocated_address);


Have a look in your PICC directory and see if there is a readme file with jump_to_isr in it.

The search also found jump_to_isr in the following files...

C:\Program Files\PICC\Pch.dll
C:\Program Files\PICC\Pcm.dll


So I suggest you do a search for jump_to_isr in your CCS directory.

If your search comes back with nothing then you obviously dont have the jump_to_isr function.

But as you have ex_bootloader.c I would have thought you would have the jump_to_isr function ?

If you do have the jump_to_isr function try re-installing your CCS.

If this still doesnt work get in touch with [email protected] and tell them.
dheroyan



Joined: 01 Mar 2006
Posts: 1

View user's profile Send private message Visit poster's website

PostPosted: Wed Mar 01, 2006 3:23 am     Reply with quote

I bought PIC16F877A that already with bootloader in it. I can straight forward program the PIC through RS232.
See my code that I have try from this site :
www.geocities.com/sahfeie/microcontroller
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