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 support@ccsinfo.com

Bootloading in 16F87XA

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







Bootloading in 16F87XA
PostPosted: Wed Jun 18, 2003 7:06 am     Reply with quote

I have searched extensively in this message board and with google for how to setup the CCS compiler for to be compatible with a bootloader as Microchip's AN851. But I haven't found all information needed. There are a lot of posts regarding the 16F87X but that is not working the same way as the 16F87xA.
The closest I came was <a href="http://www.pic-c.com/forum/general/posts/10731.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/10731.html</a> but there are some questions there that is not answered.
According to the above mentioned post I have successfully changed the reset and irq vector addresses to 0x0100/0x0104
I have also tried to reserve the bootloader space with #org 0000, 00FF {}, which should prevent the compiler from putting any code in that area, but yet it does.

I have also tried to replace the "#org 0000, 00FF {}" with

#org 0x0000,0x00ff
void bootloader() {
#asm
nop
#endasm
}
No change. The nop isn't even in the list file, so the compiler omits the bootloader function.

I have read that some of you have succeded with this, any hints?

My compiler version is PCW3.116, 16399

Best regards
Daniel Brännwik
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515351
R.J.Hamlett
Guest







Re: Bootloading in 16F87XA
PostPosted: Wed Jun 18, 2003 7:12 am     Reply with quote

:=I have searched extensively in this message board and with google for how to setup the CCS compiler for to be compatible with a bootloader as Microchip's AN851. But I haven't found all information needed. There are a lot of posts regarding the 16F87X but that is not working the same way as the 16F87xA.
:=The closest I came was <a href="http://www.pic-c.com/forum/general/posts/10731.html" TARGET="_blank"> <a href="http://www.pic-c.com/forum/general/posts/10731.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/10731.html</a></a> but there are some questions there that is not answered.
:=According to the above mentioned post I have successfully changed the reset and irq vector addresses to 0x0100/0x0104
:=I have also tried to reserve the bootloader space with #org 0000, 00FF {}, which should prevent the compiler from putting any code in that area, but yet it does.
:=
:=I have also tried to replace the "#org 0000, 00FF {}" with
:=
:=#org 0x0000,0x00ff
:=void bootloader() {
:=#asm
:=nop
:=#endasm
:=}
:=No change. The nop isn't even in the list file, so the compiler omits the bootloader function.
:=
:=I have read that some of you have succeded with this, any hints?
:=
:=My compiler version is PCW3.116, 16399
:=
:=Best regards
:=Daniel Brännwik
Critical word. 'DEFAULT'. Add this after your initial ORG statement, and it will allow you to place code to overlay the default routines. Otherwise it will not. After your function, add the line:
#ORG DEFAULT

which turns the option back off.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515352
Daniel Brännwik
Guest







Re: Bootloading in 16F87XA
PostPosted: Wed Jun 18, 2003 8:37 am     Reply with quote

:=Critical word. 'DEFAULT'. Add this after your initial ORG statement, and it will allow you to place code to overlay the default routines. Otherwise it will not. After your function, add the line:
:=#ORG DEFAULT
:=
:=which turns the option back off.
:=
:=Best Wishes

===============================
Thanks for your quick reply. However I'm still not able to get it to work. I have therefore made a stripped dummy project that I'm enclosing below:

#device PIC16F877A
#build (reset=0x0100)
#build (interrupt=0x0104)

#org 0x0000,0x00FF DEFAULT
void bootloader() {
#asm
nop
#endasm
}
#org DEFAULT

#org 0x0200, 0x3FFF AUTO=0
void main (void)
{
int i;

for (i=0x00; i<5; i++)
{}
}

This results in the following lst-file:
CCS PCW C Compiler, Version 3.116, 16399

Filename: C:\PIC-PR~1\EMB\TEST\TEST.LST

ROM used: 19 (0\%)
Largest free fragment is 2048
RAM used: 3 (2\%) at main() level
3 (2\%) worst case
Stack: 0 locations

*
0100: MOVLW 00
0101: MOVWF 0A
0102: GOTO 000
0103: NOP
.................... #device PIC16F877A
....................
.................... #build (reset=0x0100)
.................... #build (interrupt=0x0104)
....................
.................... #org 0x0000,0x00FF DEFAULT
.................... void bootloader() {
.................... #asm
.................... nop
.................... #endasm
.................... }
.................... #org DEFAULT
....................
.................... #org 0x0200, 0x3FFF AUTO=0
.................... void main (void)
.................... {
.................... int i;
*
0000: CLRF 00
0001: MOVLW 1F
0002: ANDWF 03,F
0003: MOVLW 07
0004: BSF 03.5
0005: MOVWF 1F
....................
.................... for (i=0x00; i<5; i++)
0006: BCF 03.5
0007: CLRF 21
0008: MOVF 21,W
0009: SUBLW 04
000A: BTFSS 03.0
000B: GOTO 00E
.................... {}
000C: INCF 21,F
000D: GOTO 008
.................... }
....................
000E: SLEEP
....................
....................

As you can see, main is still located at address 0x0000 and the function bootloader isn't compiled. I have tried every combination of the #org statements I could imagine and this is more or less the only way that the compiler hasn't reported any errors.
I'm sure there is an easy way to achive what I'm trying to do.

Best regards
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515356
R.J.Hamlett
Guest







Re: Bootloading in 16F87XA
PostPosted: Wed Jun 18, 2003 10:54 am     Reply with quote

:=:=Critical word. 'DEFAULT'. Add this after your initial ORG statement, and it will allow you to place code to overlay the default routines. Otherwise it will not. After your function, add the line:
:=:=#ORG DEFAULT
:=:=
:=:=which turns the option back off.
:=:=
:=:=Best Wishes
:=
:================================
:=Thanks for your quick reply. However I'm still not able to get it to work. I have therefore made a stripped dummy project that I'm enclosing below:
:=
:=#device PIC16F877A
:=#build (reset=0x0100)
:=#build (interrupt=0x0104)
:=
:=#org 0x0000,0x00FF DEFAULT
:=void bootloader() {
:=#asm
:=nop
:=#endasm
:=}
:=#org DEFAULT
:=
:=#org 0x0200, 0x3FFF AUTO=0
:=void main (void)
:={
:=int i;
:=
:= for (i=0x00; i<5; i++)
:= {}
:=}
:=
:=This results in the following lst-file:
:=CCS PCW C Compiler, Version 3.116, 16399
:=
:= Filename: C:\PIC-PR~1\EMB\TEST\TEST.LST
:=
:= ROM used: 19 (0\%)
:= Largest free fragment is 2048
:= RAM used: 3 (2\%) at main() level
:= 3 (2\%) worst case
:= Stack: 0 locations
:=
:=*
:=0100: MOVLW 00
:=0101: MOVWF 0A
:=0102: GOTO 000
:=0103: NOP
:=.................... #device PIC16F877A
:=....................
:=.................... #build (reset=0x0100)
:=.................... #build (interrupt=0x0104)
:=....................
:=.................... #org 0x0000,0x00FF DEFAULT
:=.................... void bootloader() {
:=.................... #asm
:=.................... nop
:=.................... #endasm
:=.................... }
:=.................... #org DEFAULT
:=....................
:=.................... #org 0x0200, 0x3FFF AUTO=0
:=.................... void main (void)
:=.................... {
:=.................... int i;
:=*
:=0000: CLRF 00
:=0001: MOVLW 1F
:=0002: ANDWF 03,F
:=0003: MOVLW 07
:=0004: BSF 03.5
:=0005: MOVWF 1F
:=....................
:=.................... for (i=0x00; i<5; i++)
:=0006: BCF 03.5
:=0007: CLRF 21
:=0008: MOVF 21,W
:=0009: SUBLW 04
:=000A: BTFSS 03.0
:=000B: GOTO 00E
:=.................... {}
:=000C: INCF 21,F
:=000D: GOTO 008
:=.................... }
:=....................
:=000E: SLEEP
:=....................
:=....................
:=
:=As you can see, main is still located at address 0x0000 and the function bootloader isn't compiled. I have tried every combination of the #org statements I could imagine and this is more or less the only way that the compiler hasn't reported any errors.
:=I'm sure there is an easy way to achive what I'm trying to do.
:=
:=Best regards

I'd be very suprised if this would even compile!.. The ORG range given is larger than the available ROM in the chip.
Now that having been said, #ORG DEFAULT, happily lets me put code anywhere, _except_ the very start of memory (which you want). There is probably a trick, but I have never found it. My own 'solution', has been to manually code the first few bytes, using:

#build (reset=0x0100)
#build (interrupt=0x0104)

#use fast_io(c)

#ROM 0x0000 = { 0 }

#ORG 0x0200,0x02FF AUTO=0 DEFAULT
void main (void)
{
int i;

for (i=0x00; i<5; i++)
{}
}
#ORG DEFAULT

The #ROM directive, happily allows you to put values into the first locations.
You can #ORG DEFAULT, to address 3, and upwards, it is just the initial location, used for the boot 'jump', which needs manual overriding...
There are several 'undocumented' instructions (the 'build' you use, is one - there is also an 'import', and 'export' command, which I have never worked out...).

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515359
Michael Thompson
Guest







Re: Bootloading in 16F87XA
PostPosted: Wed Jun 18, 2003 11:25 am     Reply with quote

Try the following:

#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01FF {}
void bootloader()
{
#asm
nop
#endasm
}

The compiler is expecting byte addresses for locating the code.
The code:

#build(reset=0x100)
#build(interrupt=0x104)

is using instruction word (16-bit) addresses.

Regards,
Mike
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515361
Daniel Brännwik
Guest







Re: Bootloading in 16F87XA
PostPosted: Thu Jun 19, 2003 7:15 am     Reply with quote

:=I'd be very suprised if this would even compile!.. The ORG range given is larger than the available ROM in the chip.
:=Now that having been said, #ORG DEFAULT, happily lets me put code anywhere, _except_ the very start of memory (which you want). There is probably a trick, but I have never found it. My own 'solution', has been to manually code the first few bytes, using:
:=
:=#build (reset=0x0100)
:=#build (interrupt=0x0104)
:=
:=#use fast_io(c)
:=
:=#ROM 0x0000 = { 0 }
:=
:=#ORG 0x0200,0x02FF AUTO=0 DEFAULT
:=void main (void)
:={
:=int i;
:=
:=for (i=0x00; i<5; i++)
:={}
:=}
:=#ORG DEFAULT
:=
:=The #ROM directive, happily allows you to put values into the first locations.
:=You can #ORG DEFAULT, to address 3, and upwards, it is just the initial location, used for the boot 'jump', which needs manual overriding...
:=There are several 'undocumented' instructions (the 'build' you use, is one - there is also an 'import', and 'export' command, which I have never worked out...).
:=
:=Best Wishes


Of course the address range is too big, my mistake. However I have followed your instructions and my sample program now works as intended. I still have some problems when I try to lift this over to my real program but it seems to be going in the right direction. So I think I'll make a new post later on.

I have one question right away though. It regards the jump address to main that are generated in the startup (my reset vector address is 0x100)
The list file starts like this:
0100: MOVLW 00
0101: MOVWF 0A
0102: GOTO 20C ;Here it should jump to main()
0103: NOP

To me it looks like it starts by setting PCLATH to 0x00 and then jumps to 0x20C. But my main function starts at 0xA0C.
I have verified with the simulator that the program indeed jumps to address 0x20C at reset, which means that PCLATH is set incorrectly. Any ideas what to do about that?

//DB
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515390
R.J.Hamlett
Guest







Re: Bootloading in 16F87XA
PostPosted: Thu Jun 19, 2003 9:04 am     Reply with quote

:=:=I'd be very suprised if this would even compile!.. The ORG range given is larger than the available ROM in the chip.
:=:=Now that having been said, #ORG DEFAULT, happily lets me put code anywhere, _except_ the very start of memory (which you want). There is probably a trick, but I have never found it. My own 'solution', has been to manually code the first few bytes, using:
:=:=
:=:=#build (reset=0x0100)
:=:=#build (interrupt=0x0104)
:=:=
:=:=#use fast_io(c)
:=:=
:=:=#ROM 0x0000 = { 0 }
:=:=
:=:=#ORG 0x0200,0x02FF AUTO=0 DEFAULT
:=:=void main (void)
:=:={
:=:=int i;
:=:=
:=:=for (i=0x00; i<5; i++)
:=:={}
:=:=}
:=:=#ORG DEFAULT
:=:=
:=:=The #ROM directive, happily allows you to put values into the first locations.
:=:=You can #ORG DEFAULT, to address 3, and upwards, it is just the initial location, used for the boot 'jump', which needs manual overriding...
:=:=There are several 'undocumented' instructions (the 'build' you use, is one - there is also an 'import', and 'export' command, which I have never worked out...).
:=:=
:=:=Best Wishes
:=
:=
:=Of course the address range is too big, my mistake. However I have followed your instructions and my sample program now works as intended. I still have some problems when I try to lift this over to my real program but it seems to be going in the right direction. So I think I'll make a new post later on.
:=
:=I have one question right away though. It regards the jump address to main that are generated in the startup (my reset vector address is 0x100)
:=The list file starts like this:
:=0100: MOVLW 00
:=0101: MOVWF 0A
:=0102: GOTO 20C ;Here it should jump to main()
:=0103: NOP
:=
:=To me it looks like it starts by setting PCLATH to 0x00 and then jumps to 0x20C. But my main function starts at 0xA0C.
:=I have verified with the simulator that the program indeed jumps to address 0x20C at reset, which means that PCLATH is set incorrectly. Any ideas what to do about that?
:=
:=//DB
I'm afraid, I suspect that is a compiler version fault. Obviously, 0A0C, is addressed as 020C, but with the PCLATH set to the right page. Unfortunately, '0' isn't it... :-(
You can use the #ROM statement (again), to write the correct value into the MOVLW statement. I had to do this in the past with the 18F family, before CCS implemented RETFIE 1, manually changing the word to the right value.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515395
daniel.brannwik@empir.se
Guest







Re: Bootloading in 16F87XA
PostPosted: Thu Jun 19, 2003 3:42 pm     Reply with quote

:=I'm afraid, I suspect that is a compiler version fault. Obviously, 0A0C, is addressed as 020C, but with the PCLATH set to the right page. Unfortunately, '0' isn't it... :-(
:=You can use the #ROM statement (again), to write the correct value into the MOVLW statement. I had to do this in the past with the 18F family, before CCS implemented RETFIE 1, manually changing the word to the right value.
:=
:=Best Wishes

Thanks, you're a rock! I just got an answer from CCS support and they confirm what you suspected. My version of the compiler is not fully compatible with the #build directive, and that causes this behaviour.
Tomorrow is holiday in Sweden, but I'll try your suggestion first thing on Monday.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515408
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