hi, i do not give complete samples, i just try to get you on your way.
the Y i was missing. my point : when you start sending data like 123------456 123----456 ,how can you be sure that the receiver know what the start is? some data might never arrive because receiver is powered later for example.
So you need to have a simple protocol.
# means start of data , in your receiver you keep waiting till you get this character !
, can be delimiter for multiple values like x and y :
I would not send all the ------ since you can easily add that in the receiver. send as little data as is needed is best.
so send would send :
#123,456#123,456
here you see, you do not know the end ! so you need a trailer as well like *
so you can send : #123,456*
or #123,456*#123,456*#123,456*
IN the receiver you need to build some logic using a simple state machine:
dim bState as byte
ISR :
b=udr 'get the character
select case b ' depending on the state
case 0 : 'no header yet so wait for #
if b="#" then ' ok we got the header
bstate=1 'next state
sX="" : sY="" 'clear strings
end if
case 1 : 'we only get here when the header was received so all data is X value until we get a ,
if b= "," then 'check the comma
bstate=2 'next state
else ' this means we receive data for X
sX=sX+chr(b) 'store in string
end if
case 2 ' this means the comma was received and now we receive data for Y till we get a *
if b="*" then 'end
lcd sX
lowerline lcd sY
bstate=0 'reset state
else 'still data for Y
sY=sY+ chr(b)
end if
end select
return
try to follow the flow in the isr. maybe by using the simulator.
↧