Shop OBEX P1 Docs P2 Docs Learn Events
SEROUT and word variables — Parallax Forums

SEROUT and word variables

aa200orionaa200orion Posts: 10
edited 2009-09-27 20:34 in General Discussion
I am trying to send a word variable using SEROUT.· Below is the code.· Is there a better way to send a word variable instead of breaking it up as shown below?· Is there a way to break a word into upper and lower bytes?

· SEND_CHARTCODE_TO_AP:

··· eyechartcode = $4164·' 64 = "d"· and 41 = "A" ' test data



···· SEROUT·RB.1,·N9600, eyeChartcode
···· eyeChartcode = eyeChartcode SHR 8
···· SEROUT·RB.1,·N9600, eyechartcode
···· PAUSE 1000

·RETURN

It works, just looks awkward.


Thanks,

Jimmy

Comments

  • JonnyMacJonnyMac Posts: 9,212
    edited 2009-09-27 18:37
    SEROUT only works with bytes so it's best that you encapsulate it in a subroutine and then call it. For programs that don't use interrupts you can code the subroutine like this:

    SUB TX_BYTE
      SEROUT TX, Baud, __PARAM1
      ENDSUB
    


    And, of course, it's good practice to define your serial output pin using the PIN declaration, and your baud rate as a constant (see the SX/B help file). Now you can do this:

    TX_BYTE eyechartcode_LSB
    TX_BYTE eyechartcode_MSB
    


    This assumes that you've defined the variable using Word; the compiler will create the _LSB and _MSB [noparse][[/noparse]byte] variables automatically.
  • aa200orionaa200orion Posts: 10
    edited 2009-09-27 20:34
    I'll give it a try.··Didn't know about·the 'UNDERSCORE'.

    Thanks
Sign In or Register to comment.