BS2 serin/serout
gc3076
Posts: 44
can anyone suggest any information on using serin/serout or sample code. I am trying to input a 12 bit binary serial data from an external device and display a decimal output on a parallax serial LCD display.
Comments
And, as always, reading the sections on SERIN and SEROUT in the manual (their detailed) will go a long way toward developing your understanding of these commands. The manual (and help file) have several code snippets to demonstrate PBASIC features.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
· value VAR Word
····.
····.
····.
· SEROUT 14, 84, [noparse][[/noparse]22, 12]
· PAUSE 5
· DO
··· GOSUB Get_12_Bit_ADC_Value
··· SEROUT 14, 84, [noparse][[/noparse]128, DEC5 value]
··· PAUSE 250
· LOOP
··· .
····.
··· .
There are more tips and tricks of a similar sort in this post: Getting Started with the Parallax Serial LCD.
Post Edited (Andy Lindsay (Parallax)) : 1/18/2006 7:34:08 PM GMT
MSB (B7 [noparse][[/noparse]1] indicates·MSB - B6 EVEN PARITY - B5-B0 output of A/D convereter)
LSB (B7 [noparse][[/noparse]0]·indicates LSB - B6 EVEN PARITY - B5-B0 output of A/D convereter)
i.e. 1001 0110·· 0101 0101 equals -21.2 in decimal
Post Edited (gc3076) : 1/18/2006 8:21:39 PM GMT
Post Edited (Andy Lindsay (Parallax)) : 1/18/2006 11:24:39 PM GMT
http://www.spectronsensors.com/appsheets/SAN-213-0304.pdf
Here's what the Get_Sensor routine does: It waits for two bytes and then checks the high bit of the MSB to make sure that the bytes are properly aligned.· If that's the case, then the word variable is reassembled from the two bytes that contain six data bits each.· Please study the data shee carefully and compare it to this code.
Sensor···· ·PIN··· 15
SnsrBaud··· CON··· 84
result···· ·VAR··· Word
...
Get_Sensor:
· SERIN Sensor, SnsrBaud, [noparse][[/noparse]result.HIGHBYTE, result.LOWBYTE]
· IF (result.BIT15 = 0) THEN Get_Sensor
· result.BIT6 = result.BIT8
· result.BIT7 = result.BIT9
· result.HIGHBYTE = (result.HIGHBYTE & %00111111) >> 2
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Here is a test program (TestSpectroTilt3.bs2) to try with your·SPECTROTILT module and Parallax Serial LCD.· Make sure to update the Pin directives for your setup.· Also, if you're not using the BASIC Stamp 2, make sure to update the $STAMP, and BaudMode directives accordingly.
The examples in the part datasheet appear to be incorrect because they truncate the D10 and D11 bits.· Either that, or the explanation is incorrect.··Assuming the explanation is correct, the binary value for -56.27 degrees·should be·1100_0110_0101_0101 and the·one for -37.7 degrees·should be·1000_1110_0011_0011.·
Regards, Andy
Post Edited (Andy Lindsay (Parallax)) : 1/22/2006 12:38:09 AM GMT
If not I tried to use the following as a test using a ASCII chart from the below link.
http://www.myke.com/lcd.htm
' {$STAMP BS2}
' {$PBASIC 2.5}
degree VAR Byte
degree = %01111110
SEROUT 14, 84, [noparse][[/noparse]degree]
Post Edited (gc3076) : 1/24/2006 8:20:41 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
http://forums.parallax.com/showthread.php?p=567287
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax