Shop OBEX P1 Docs P2 Docs Learn Events
Reading a Maxbotix EZ1 Sonar with the SX28 - outputting the result to a Serial — Parallax Forums

Reading a Maxbotix EZ1 Sonar with the SX28 - outputting the result to a Serial

francis_L_Hfrancis_L_H Posts: 10
edited 2008-05-05 11:04 in General Discussion
I do not understand how to send a variable to the LCD with the SX. I am storing a variable from an ultrasonic distance sensor. (MaxBotix - MaxSonar EZ1 http://www.maxbotix.com/MaxbotixHome.html) I am trying to convert that variable into ASCII characters so I can use the serout command to display that value onto my LCD screen (Parallax Item code 27979). I tried modifying a code from another thread "Sending a variable to a serial LCD" in the Best SX Threads Index, but I do not understand how it works. I pasted my code below for the ultrasonic sensor portion. I want to be able to take the variable time, and display that value to my LCD. I appreciate any help.


DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ 4_000_000

pwpin PIN RB.0
store var word
counter var word
time var word

Program Start
Start:
for counter = 1 to 10
Pulsin pwpin, 1, store
pause 50
time = store*10
next
' watch time
' break
Pause 5000
goto start

Comments

  • BeanBean Posts: 8,129
    edited 2008-05-05 11:04
    Although not the most code effecient, the easiest method is to use divide and remainder.
    tempW VAR WORD
     
    tempW = time / 10_000
    time = __WREMAINDER
    tempW = tempW + "0"
    SEROUT SerialPin, Baud, tempW_LSB ' 10,000's digit
    tempW = time / 1_000
    time = __WREMAINDER
    tempW = tempW + "0"
    SEROUT SerialPin, Baud, tempW_LSB ' 1,000's digit
    tempW = time / 100
    time = __WREMAINDER
    tempW = tempW + "0"
    SEROUT SerialPin, Baud, tempW_LSB ' 100's digit
    tempW = time / 10
    time = __WREMAINDER
    tempW = tempW + "0"
    SEROUT SerialPin, Baud, tempW_LSB ' 10's digit
    SEROUT SerialPin, Baud, time_LSB  ' 1's digit
     
    
    
    
    

    · This is the basic method for converting a value to ASCII.

    Bean.





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?

    www.iElectronicDesigns.com



    Post Edited (Bean (Hitt Consulting)) : 5/5/2008 11:11:20 AM GMT
Sign In or Register to comment.