PDA

View Full Version : POKECODE problems (16F877)



Archilochus
- 23rd March 2005, 16:53
Hi all,
Hope someone can help out with this odd problem.
Have a bit of code for the 16F877. The code itself is about 3,100 words, and there are about 1,000 bytes of data stored at the end using POKECODE:

@ org 7100 ; Set data start location
POKECODE data here...
POKECODE more data here...
and so on for all the data.

This all works out fine, with the program compiling fine, and data being read properly by the program.

Now to the problem...
I added about 1,000 words to the program - bringing it up to about 4,100 words total, with the same exact, unchanged data stored at the end using the POKECODEs.

BUT... now each POKECODE instruction is adding in 3 extra words each time it is used! This completely mixes up the data, because there are now 3 extra unwanted locations taken up for each POKECODE used - and several POKECODE instructions are needed to fill the 1,000 bytes of data.

As I understand it POKECODE just places a RETLW followed by the data byte into the specified code location - so where are these 3 extra words coming from? - and how do I get rid of them?

Any ideas greatly appreciated
Thanks,
Arch

< EDIT >
Here' the programmers buffer from a test:

1F40: 158A 120A 277B 3452 3452 3452 3452 3452

It looks like the opcodes for BSF, BCF, and a CALL are getting added in before the 5 ASCII values for "R" that I wrote as a test using POKECODE.

Archilochus
- 24th March 2005, 14:23
Well... for anyone interested, here's what I found.
Once the actual program code passes the $1000 (dec 4,096) boundary, the POKECODE instruction starts inserting a BCF, BSF, and a CALL every time it is used (I'm guessing it's trying to do bank switching?).
This makes POKECODE worthless for use past the $1000 boundary, as your data is stored shifted up three places from where you expect it to be.

After searching about the forum, I found a post from Melanie about saving data to code-space, and so used this instead:

ASM
CODE 0x1F40 ; Data start location @ dec. 8,000
DB 0x57,0x58,0x59 etc... ; Store data bytes starting at location 8,000
DB 0x22,0x19,0x1B etc...
etc...
etc...
EndASM

The "CODE" and "DB" statements should be indented - and "0x" should be used instead of "$" to indicate hexadecimal.
The "DB" instruction adds the RETLW ($34) instruction to the first six bits of each 14-bit Program Word.