PDA

View Full Version : PCLATH initialising for Bootloader



Squibcakes
- 14th March 2006, 23:47
Hi there,

It's been a while since I played here and I'm a bit rusty...

A while ago I was loading tiny bootloader into the 16F88 and it was working but now, I cant figure what the heck I'm doing wrong, my program wont install using the bootloader, I get a error come up:

WARNING: PCLATH not initialised before GOTO! ... could not repair.,
Maybe you sould use some directive in your compiler to enable the use of bootloaders


The tiny website recommends that the program must meet this requirement:

it must have in the first 4 words of memory a GOTO to the start of the main program. (this is what the majority of the bootloaders require). So in assembler it should look something like this:



asm
org 0
;clrf STATUS
clrf PCLATH
goto Main
endasm


This codedoesnt make a lot of sense to me but perhaps there is somebody out there that can point me in the right direction.

BTW What the heck does LATH in PCLATH stand for???

Oh yeah, I use MCS and PICBASIC pro for compilying.. dur!
Cheers
J

mister_e
- 15th March 2006, 16:44
Out of curiosity, Did you insert DEFINE LOADER_USED 1 at the top of your code?

Squibcakes
- 15th March 2006, 22:08
A Ha!,

I think that did the trick... btw, any idea about that LATH comment I made?

Thanks Steve.
J

Bruce
- 18th March 2006, 01:45
PCLATH = (program counter latch high) = the latch register you write to that
holds the value to be loaded into PCH.

PCH is the high 5-bits of the 13-bit program counter for the 14-bit core. PCL
is the lower 8-bits.

You can't write directly to PCH, so you write to PCLATH. The value you place
in PCLATH gets latched into the program counter high (PCH) when PCL is
written.

All 13-bits of the program counter have to be written simultaneously. That's
the purpose of the PCLATH latch register.

The error you're getting is because you haven't reserved enough space in the
beginning or program memory for the Tiny loader to automatically insert the
CLRF PCLATH instruction.

On return from the loader sub routine PCH needs to be cleared to point to the
program memory in bank 0 where your code is located.

If CLRF PCLATH can't be inserted before GOTO Main, then it would jump back
to program memory in bank 1 instead of bank 0 causing major problems.

As Steve mentioned, inserting DEFINE LOADER_USED 1 takes care of this since
it tells PBP to reserve the first 4 locations for loader use.

Squibcakes
- 18th March 2006, 02:39
Thats a great reply, thanks Bruce!

J

modifyit
- 20th March 2006, 02:04
I'm having a similar problem using the tinybootloader, but when I use microcode studio's bootloader I don't have any issues.

When using the tiny loader the first time I bootload my program to the chip it works, but I get the following error in the Tinybootloader window:
----------------------
HEX: 9 hours old, INHX32,16Fcode+cfg+eeprom , total=14546 bytes.
Searching for PIC ...
Found:16F 876A/877A
WARNING: PCLATH not initialised before GOTO! ... sucessfully repaired.,
WRITE OK. time:9.203 sec
----------------------

The problem I am having is I can't bootload a new hex file to the chip after this, everytime I try I get the following error:

----------------------
Searching for PIC ...
pic sending unknown data: "K" <> E0h=à
Check baudrate & Start Write while PIC is not sending serial data (e.g. in reset)
ERROR!
---------------------

I would appreciate any advice you may have.

Thanks

modifyit
- 20th March 2006, 02:20
I figured out my problem....it always helps to read directions

My problem is that I am using a chip that is constantly sending serial commands so I needed to hold down the chip reset button and release it immeadiatly after I hit "write flash"

This seemed to solve my issue.

Squibcakes
- 20th March 2006, 22:46
Yeah that would do it.

Btw, I still get the PCLATH not initialised before GOTO! ... sucessfully repaired.,
message come up. Not sure what thats about but HEY, it works!

Squib

modifyit
- 21st March 2006, 13:26
Yeah I still get that error as well, but it does work