Duhhhh.... Yes, I use CounterA, CounterB... DataA, DataB in my subroutines, but INTERRUPTS by their very nature will INTERRUPT the flow of things, so you wouldn't use the same variables within those routines unless the interrupt is supposed to change the way the main program works - I would have thought that was obvious!
In the same way, if you nest subroutines within subroutines for a particular task... you can't have the same variables in each of those subroutines as they'll mess with each other.
It doesn't mean that every subroutine has to have it's own exclusive variables, but you do need to keep track of what is being used where - and to that end, when you list your subroutine, have a header which simply reminds you what's used inside it...
Code:
'
' Subroutine Displays Message on LCD from Program CodeSpace
' ---------------------------------------------------------
' CounterA - General Byte Variable
' CounterC - General Word Variable
' DataA - General Byte variable
' Message - ID of Message to Display
' MessageLen - Number of characters to Output
' MessageSupport - Beginning of Message Table in Codespace
' XDataAddress - 16-bit Address in Codespace
DisplayExternal:
@ GetAddress _MessageSupport, _XDataAddress ' Get Start address of Message Support Table
XDataAddress=XDataAddress+(Message*18)
ReadCode XDataAddress,MessageLen
XDataAddress=XDataAddress+1
ReadCode XDataAddress,DataA
If DataA>0 then LCDOut $FE,DataA
If MessageLen>0 then
For CounterA=1 to MessageLen
CounterC=XDataAddress+CounterA
ReadCode CounterC,DataA
LCDOut DataA
Next CounterA
endif
Return
Bookmarks