POKECODE problems (16F877)


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Location
    New England
    Posts
    164

    Default POKECODE problems (16F877)

    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.
    Last edited by Archilochus; - 23rd March 2005 at 17:54.

  2. #2
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. 16f877 and ps/2 keyboard error???
    By boraciner in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th July 2009, 08:14
  2. serial communication between CMUcam and PIC 16F877
    By gengkeys in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th March 2007, 06:43
  3. 4 Quadrant dc drive with 16F877
    By mns45 in forum mel PIC BASIC
    Replies: 2
    Last Post: - 23rd February 2006, 13:05
  4. USART problems
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 47
    Last Post: - 6th March 2005, 21:45
  5. Interrupts using a 16F877
    By Niall in forum General
    Replies: 1
    Last Post: - 6th August 2003, 01:33

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts