pin state into byte variable - serial...
Hi All,
Am just wondering if I am going about this the right way, in SXBasic.
I have serial data coming into an SX pin, and want to shift that data into a byte variable.
I'm just not sure if its working correctly...
string is a byte variable.
RA.0 is the serial input pin
immediately after I detect the start bit it goes something like this...
· pauseus 417················ 'align the first data bit to the middle of the bit, correct for 1200bps
· startbit = RA.0············· 'get start bit
· pauseus·833················ 'pause 1 bit period
for counter = 0 to 7········ 'loop for 8 bits of data
· string.7 = RA.0············· 'get the serial input pin state and put it into bit 7 of 'string' variable
· string = string SHR 1····· 'shift bits right
· pauseus 833················
next
··parity = RA.0··············· 'get parity bit
· pauseus 833
· stopbit = RA.0············· 'get stop bit
· pauseus 833
Is there a problem with getting a pin state into a variable this way ?
I mean can you just put any bit of a byte variable directly onto a pin ?
I cant use the serin command, because its E81 comms.
Cheers,
Chris, Weastern Australia.
Am just wondering if I am going about this the right way, in SXBasic.
I have serial data coming into an SX pin, and want to shift that data into a byte variable.
I'm just not sure if its working correctly...
string is a byte variable.
RA.0 is the serial input pin
immediately after I detect the start bit it goes something like this...
· pauseus 417················ 'align the first data bit to the middle of the bit, correct for 1200bps
· startbit = RA.0············· 'get start bit
· pauseus·833················ 'pause 1 bit period
for counter = 0 to 7········ 'loop for 8 bits of data
· string.7 = RA.0············· 'get the serial input pin state and put it into bit 7 of 'string' variable
· string = string SHR 1····· 'shift bits right
· pauseus 833················
next
··parity = RA.0··············· 'get parity bit
· pauseus 833
· stopbit = RA.0············· 'get stop bit
· pauseus 833
Is there a problem with getting a pin state into a variable this way ?
I mean can you just put any bit of a byte variable directly onto a pin ?
I cant use the serin command, because its E81 comms.
Cheers,
Chris, Weastern Australia.
Comments
for counter = 0 to 7
· string = string SHR 1
· string.7 = RA.0
· pauseus 833
next
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"
Benjamin Franklin
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
yes, otherwise i shift bit 0 out of the byte on the last rotation.
So does this look ok for sending a byte...
string var byte
for counter = 0 to 7
·RA.0 = counter.0
·string = string SHR 1
·pauseus 833
next
I'm just not sure about putting bits onto pins, if it needs to be done from a bit or byte variable etc...
Cheers, Chris
I've attached a demo that works. Note that I had to disable collecting the parity bit as my terminal program can't send it. Also, you don't have to collect the stop bit -- use that time to do something with the data you've just collected from the serial input.
Jon
Is there a dedicated manual for SXB programming around for sale or download ?
Cheers, Chris, West Oz.