Wednesday, May 30, 2007

Projects

I've a few projects I'd like to do:

  • USB Audio Interface
    • for hooking up my guitar to my computer
    • using those fancy PICs
  • A darts scoring system
    • Just to use those *HUGE* LEDs
    • Would suite my mates' "Bar and Darts" room.


Projects in the works

  • RTL visualiser
    • Python and wxWidgets
    • inspired by Nova's Debussy

Projects I've recently completed:

  • Multi-Zone Lighting Controller for a friend's new gaff.
    • PICs, keypads and high-voltages!

My Code vs the PIC16F871 Linker Script

Just wasted a day trying to port some PIC code over from a PIC16F684 to a 16F871. It was all down to the linker script, and my hazy understanding of where the linker tries to place data. First a few basic facts about the directives for specifying relocatable memory blocks:

  • UDATA: Uninitialised data which is placed in sections defined as "DATABANK" in the linker scripts. These sections are 'banked' memory locations, so you have to be careful to select the correct bank before accessing the data at these memory locations.

  • UDATA_SHR: Uninitialised shared data which is placed in sections defined as "SHAREBANK" in the linker scripts. These sections are 'unbanked', which means you don't need to care too much which bank you've selected when using these data locations. The data accessed at this location is the same across all banks.

The All-Important Linker Script

My assembler code is split across a few files, with some of the files defining a few variables in UDATA blocks. This was all cool when I was targeting the code to the 18F684, but when I targeted it to the 16F871, I got the error message:

Error - section '.udata' can not fit the section.  Section '.udata' length=0x00000012

After some vigorous interweb searching, I finally hit on the answer - the 16F871 linker script doesn't define any DATABANK sections! The linker had nowhere to put my UDATA.

The Fix

Instead of hacking the linker file, which I was tempted to do, I changed all my UDATA blocks to UDATA_SHR. One of my files had UDATA and UDATA_SHR blocks, so I had to edit this 'cos you're only allowed one block of each type per file.

Now it links like a dream! Needless to say, there are now copious comments in the code...

References: