Shop OBEX P1 Docs P2 Docs Learn Events
Confused on READ and DATA. Need a little help :) — Parallax Forums

Confused on READ and DATA. Need a little help :)

eagletalontimeagletalontim Posts: 1,399
edited 2009-01-14 03:31 in General Discussion
I have been trying to conserve space in the SX28 chips and am trying to use the READ and DATA functions. I have looked at several examples and read how to use them in the SX/B help file but am still lost and cannot get my code to work right [noparse]:([/noparse]

Here is what I have :
showmenu:
  temp1 = __PARAM1
  temp2 = temp1
  FOR idx = 0 TO 15
    READ Menu1 + temp1, temp3
    INC temp1
    PUT line1(idx), temp3
  NEXT
  FOR idx = 0 TO 15
    READ Menu2 + temp2, temp3
    INC temp2
    PUT line2(idx), temp3
  NEXT
  UPDATE_L1
  UPDATE_L2
  RETURN

........

Menu1:
  DATA "Menu 1",0
  DATA "Menu 2",0
  DATA "Menu 3",0
  DATA "Menu 4",0

Menu2:
  DATA "Text for Menu 1",0
  DATA "Text for Menu 2",0
  DATA "Text for Menu 3",0
  DATA "Text for Menu 4",0



The usage is showmenu menu_number.
The PUT Line1(idx) is the same as used in one of the examples in the SX/B help file.
When it displays it on the LCD, it shows part of one string on the wrong line and it even parts of another menu string. What am I doing wrong?

This is what I get with using showmenu 3

LCD Line1 : u 1 Menu 2 Menu
LCD Line2 : t for Menu1 Tex

Thanks for the help in advance!

Comments

  • mojorizingmojorizing Posts: 249
    edited 2009-01-14 02:57
    JohnnyMac helped me out on this particular question posted here..

    http://forums.parallax.com/showthread.php?p=771380

    Check out his LCD_4_Menus.SXB attached later in the post.· What you need to do is to·present the correct "offset" which·in his prog is·the data field named "LineOffset"·.· Look over this post, especially the last few dialogues.



    Kevin





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Bad spellers of the world untie!
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-01-14 03:16
    I knew I had seen that before, but I never caught on to how it worked. I simply subtracted 1 from temp1 and multiplied it by 17. So now, showmenu 1 - how many menus I want [noparse]:)[/noparse]

    Thanks!
    Tim
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2009-01-14 03:31
    You may also want to read JonnyMacs book: http://forums.parallax.com/attachment.php?attachmentid=48274·especially pages 102-104 (bottom of the page numbers).

    Take a look at this stripped down program for LCD display also:
    ' =========================================================================
    '
    '   File...... LCD_Display
    '   Purpose... Example LCD display program
    '   Author.... Timothy Gilmore
    '   E-mail.... [url=mailto:gilmoret@us.saic.com]gilmoret@us.saic.com[/url]
    '   Started... 13 JAN 2008
    '
    ' =========================================================================
    
    ' -------------------------------------------------------------------------
    ' Program Description
    ' -------------------------------------------------------------------------
    
    ' -------------------------------------------------------------------------
    ' Device Settings
    ' -------------------------------------------------------------------------
    DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX  
      
    FREQ            20_000_000   'Use external 20MHz resonator
    
    ' -------------------------------------------------------------------------
    ' IO Pins
    ' -------------------------------------------------------------------------
    LCD_TxPin PIN RA.0 OUTPUT  'RA.0 pin used for Serial LCD
    
    ' -------------------------------------------------------------------------
    ' Constants
    ' -------------------------------------------------------------------------
    
    LcdBaud  CON "T19200"   ' Baud rate = 19200 -> SW1 ON,  SW2 ON
    LcdBkSpc        CON     $08              ' move cursor left
    LcdRt           CON     $09              ' move cursor right
    LcdLF           CON     $0A              ' move cursor down 1 line
    LcdCls          CON     $0C              ' clear LCD (need 500 ms delay)
    LcdCR           CON     $0D              ' move to position 0 of next line
    LcdBLon         CON     $11              ' backlight on
    LcdBLoff        CON     $12              ' backlight off
    LcdOff          CON     $15              ' LCD off
    LcdOn1          CON     $16              ' LCD on; no crsr, no blink
    LcdOn2          CON     $17              ' LCD on; no crsr, blink on
    LcdOn3          CON     $18              ' LCD on; crsr on, no blink
    LcdOn4          CON     $19              ' LCD on; crsr on, blink on
    LcdLine0Pos0    CON     $80              ' move to line 0, position 0
    LcdLine0Pos1    CON     $81              ' move to line 0, position 1
    LcdLine0Pos2    CON     $82              ' move to line 0, position 2
    LcdLine0Pos3    CON     $83              ' move to line 0, position 3
    LcdLine0Pos4    CON     $84              ' move to line 0, position 4
    LcdLine0Pos5    CON     $85              ' move to line 0, position 5
    LcdLine0Pos6    CON     $86              ' move to line 0, position 6
    LcdLine0Pos7    CON     $87              ' move to line 0, position 7
    LcdLine0Pos8    CON     $88              ' move to line 0, position 8
    LcdLine0Pos9    CON     $89              ' move to line 0, position 9
    LcdLine0Pos10   CON     $8A              ' move to line 0, position 10
    LcdLine0Pos11   CON     $8B              ' move to line 0, position 11
    LcdLine0Pos12   CON     $8C              ' move to line 0, position 12
    LcdLine0Pos13   CON     $8D              ' move to line 0, position 13
    LcdLine0Pos14   CON     $8E              ' move to line 0, position 14
    LcdLine0Pos15   CON     $8F              ' move to line 0, position 15
    LcdLine1Pos0    CON     $94              ' move to line 1, position 0
    LcdLine1Pos1    CON     $95              ' move to line 1, position 1
    LcdLine1Pos2    CON     $96              ' move to line 1, position 2
    LcdLine1Pos3    CON     $97              ' move to line 1, position 3
    LcdLine1Pos4    CON     $98              ' move to line 1, position 4
    LcdLine1Pos5    CON     $99              ' move to line 1, position 5
    LcdLine1Pos6    CON     $9A              ' move to line 1, position 6
    LcdLine1Pos7    CON     $9B              ' move to line 1, position 7
    LcdLine1Pos8    CON     $9C              ' move to line 1, position 8
    LcdLine1Pos9    CON     $9D              ' move to line 1, position 9
    LcdLine1Pos10   CON     $9E              ' move to line 1, position 10
    LcdLine1Pos11   CON     $9F              ' move to line 1, position 11
    LcdLine1Pos12   CON     $A0              ' move to line 1, position 12
    LcdLine1Pos13   CON     $A1              ' move to line 1, position 13
    LcdLine1Pos14   CON     $A2              ' move to line 1, position 14
    LcdLine1Pos15   CON     $A3              ' move to line 1, position 15
    ' -------------------------------------------------------------------------
    ' Variables
    ' -------------------------------------------------------------------------
    tmpB1   VAR  Byte    ' work vars
    tmpW1   VAR  Word
    
    temp1           VAR     Byte                    ' work vars
    temp2           VAR     Byte
     
    tmp1     VAR     BYTE          ' work vars          
     
    ' =========================================================================
      PROGRAM Start
    ' =========================================================================
    
    ' -------------------------------------------------------------------------
    ' Subroutine Declarations
    ' -------------------------------------------------------------------------
    SEROUTLCD  SUB 1
    DISPLAY_TEXT    SUB 2
    DELAY           SUB 1, 2                       ' delay in milliseconds
    ' -------------------------------------------------------------------------
    ' Program Code
    ' -------------------------------------------------------------------------
    Start:
    HIGH LCD_TxPin
    SEROUTLCD LcdCls    ' Clear the screen 
    DELAY 500
    SEROUTLCD LCDBLon           ' Turn on the Backlight (Backlight model only) 
    SEROUTLCD LCDON1
     
    Main:
            ' Display 1st message on both lines on LCD
      
      SEROUTLCD LcdLine0Pos0
      DISPLAY_TEXT Msg1a    ' Subroutine call to display text in DATA MSG1a statement.
      SEROUTLCD LcdLine1Pos0
      DISPLAY_TEXT Msg1b    ' Subroutine call to display text in DATA MSG1b statement.   
    
      Goto Main
      
    END
    ' -------------------------------------------------------------------------
    ' Subroutine Code
    ' -------------------------------------------------------------------------
    
    ' Use: DELAY base {, multiplier}
    ' -- pause for 'base' * (optional) 'multiplier' milliseconds
    SUB DELAY                                       ' delay x { * y } ms
      temp1 = __PARAM1
      IF __PARAMCNT = 1 THEN
        temp2 = 1
      ELSE
        temp2 = __PARAM2
      ENDIF
      IF temp1 > 0 THEN
        IF temp2 > 0 THEN
          PAUSE temp1 * temp2
        ENDIF
      ENDIF
      ENDSUB
    
    SUB SEROUTLCD
      tmp1 = __PARAM1                            ' Capture the passed byte
      SEROUT LCD_TxPin, LcdBaud, tmp1         ' Tx Byte
      ENDSUB            ' return to caller
     
    ' Use: DISPLAY_TEXT [noparse][[/noparse]String | Label]
    ' -- pass embedded string literal or DATA label (zString at label)
    SUB DISPLAY_TEXT
      tmpW1 = __WPARAM12 ' get address of string
      DO
       READINC tmpW1, tmpB1 ' read a character
       IF tmpB1 = 0 THEN EXIT ' if 0, string complete
       SEROUTLCD tmpB1 ' send the byte
      LOOP
      ENDSUB
     
    ' -------------------------------------------------------------------------
    ' DATA
    ' -------------------------------------------------------------------------
    
    Msg1a:
      DATA "This is line 0", 0   ' Up to 16 LCD character message
    Msg1b:
      DATA "& this is line 1", 0   ' Up to 16 LCD character message
    
     
    
Sign In or Register to comment.