Hi Guys
Thanks for the suggestions.
Well I don't feel it's the stack because with all the blocks of code in, it runs on a stack as small as 80bytes. But if I put the stack up to 512bytes, it doesn't solve anything. As far as I am aware, there is only one stack. But I may be wrong. This is my working PRM file:
// ------------------------------------------------------------------------------------------------------------ //
NAMES END
SEGMENTS
Z_RAM = READ_WRITE 0x0060 TO 0x01FF;
RAM = READ_WRITE 0x0200 TO 0x087F;
ROM = READ_ONLY 0xC000 TO 0xFFBF;
ROM1 = READ_ONLY 0xFFC0 TO 0xFFD7;
END
PLACEMENT
DEFAULT_RAM, /* non-zero page variables */
INTO RAM;
_PRESTART, /* startup code */
STARTUP, /* startup data structures */
ROM_VAR, /* constant variables */
STRINGS, /* string literals */
VIRTUAL_TABLE_SEGMENT, /* C++ virtual table segment */
DEFAULT_ROM,
COPY /* copy down information: how to initialize variables */
INTO ROM; /* ,ROM1: To use "ROM1" as well, pass the option -OnB=b to the compiler */
_DATA_ZEROPAGE, /* zero page variables */
MY_ZEROPAGE INTO Z_RAM;
END
STACKSIZE 0x100
VECTOR 0 _Startup /* Reset vector: this is the default entry point for an application. */
// ------------------------------------------------------------------------------------------------------------ //
As for wayword pointers, I'm starting to agree with you, since it's a relative position in memory each time, irrespective of me shifting around where the RAM starts.
I managed to get all the code "working" yesterday by removing all intialization of global variables except for arrays / structs, and removed all static declarations to non arrays / structs. As a result, the LED task that was having a problem yesterday now works fine, but my RS232 comms task now is faulty as it buffers wrong. However, removing all the other blocks of code no longer fixes it, where doing so did fix the LED task yesterday.
I am mainly using arrays and structures as follows:
static int bob[boblength] = {0, 1, 2, 3};
etc. where the calls to the arrays are in for loops with:
intTemp = bob[loopvariable];
or
if (bob[loopvariable] == constant) <action>
Though, I have two pointers, used in my functions to draw a string on my LCD and to convert a 16bit integer to a string (the string.h and strcat functions took up far too much ROM so I wrote my own hehe).
void io_LCD_putstring(byte* str2draw)
void io_WordToStr(byte* str, byte len, word val)
but every call to it passes a constant "12345" or mmm. You may have a point.
I am also passing it variables designed to save ROM space, since I have ample RAM. So I was sending it pseudo constants as follows:
// ------------------------------------------------------------------------------------------------------------ //
typedef struct
{
byte str[menudisplaystrlengthmax];
} menu_display;
static menu_display io_sMenuDisplay_EXIT = {"EXIT"};
// ------------------------------------------------------------------------------------------------------------ //
The comms (unrelated to above) was sending 1 of the 2 packets, and that one packet was not syncing correctly without static.(i.e. of it's 3 bytes, it would send 2,3,1 instead of 123, confirmed by serial port monitor). Now, making the variable "static", I see that the comms of that packet is correct again, sending (1,2,3). Wierd since it stores those variables in the same place in .data whether you make them static or not. So the question now is, why is this static variable stored in .data and not in .bss? .data is still stored in RAM, but how is it different to .bss?
I am able to "hide" the bug by moving allocations around with static changes, but I am not confident that I have eliminated the bug, or grasping what is / was causing my problems in the first place. Do you think it could be related to these functions being passed pointers as an argument and not being passed a const / static ?
Thanks for your suggestions 
Regards,
Jacques