
Originally Posted by
richard
...a packetised binary structure is way more efficient esp if its fixed length ...
I've been working with your module for 2 days and encountered a slight complication. I love the routine, but it seems the module is still working in the background when the next code instructions execute. For example:
I can refer to ADCcode in the RX pgm right away after strcpy cause it's the first byte in my structure:
Code:
asm
ADCcode = _MsgData
ADCnum = _MsgData + 1
ADCerror1 = _MsgData + 3
ADCerror2 = _MsgData + 4
endasm
...
Mainloop:
while RXoccurred = 0 ' Wait for message
wend
strcpy MsgData , incoming ,5
if ADCcode = 0 then
gosub ProcessADC_A0
else
if ADCcode = 1 then
gosub ProcessADC_A1
else
if ADCcode = 3 then
gosub ProcessSW3
else
if ADCcode = 4 then
gosub ProcessADC_A4
else
if ADCcode = 5 then
gosub ProcessADC_C3
else
if ADCcode = 6 then
gosub ProcessADC_C4
endif
endif
endif
endif
endif
endif
GOTO Mainloop
This code works as expected.
But if I refer to ADCerror1 or ADCerror2 in the TX pgm immediately after strcpy, they don't get seen by the program. I have to add a PAUSE 1 for the IFs to get triggered:
Code:
hserout [ str MsgData\5 ] ' transmit ADC value
while TX1STA.1 = 0 ' Check TRMT bit
wend
while RXoccurred = 0 ' Wait for confirmation message (RX int)
wend
strcpy MsgData , incoming ,5
PAUSE 1
if ADCerror1 = 1 then ' Check return code 1
Errorcodes = Errorcodes | %01000000 ' Force PORTA bit 6 to 1
else
if ADCerror2 = 1 then ' Check return code 2
Errorcodes = Errorcodes | %10000000 ' Force PORTA bit 7 to 1
else
Errorcodes = Errorcodes & %00111111 ' Force PORTA bits 6-7 to 0
endif
endif
Is it complicated to add a Completion Code variable in element 0 (1 byte)?
0 = processing
1 = finished
That way I can substitute the PAUSE by a WHILE WEND like this:
Code:
' PAUSE 1
while incoming[0] = 0 ' Wait for string copy to complete
wend
I can initialize incoming[0] to 0 before calling strcpy if that helps you.
I try to avoid using PAUSE so I can use DT Ints without surprises.
Right now my structure is only 5 bytes long, but this will most likely grow over time.
PS: Please don't bother with this if it takes more than 2-3 minutes.
Bookmarks