Shop OBEX P1 Docs P2 Docs Learn Events
PROPBASIC and DATA statement... — Parallax Forums

PROPBASIC and DATA statement...

Is it possible to "implant" a constantly changing variable in a DO/LOOP (i.e. a temperature reading from an LM34) into a DATA statement like:
LCD_data_2               DATA  temp_1, posCMD,82,degreeSYM,posCMD,99,temp_2,posCMD,102,degreeSYM,posCMD,115,".",posCMD,135,".",0

The above DATA statement does "print" on the LCD at the right positions and the right line, but the variable(s), temp_1 and temp_2 spaces are just blank. Bean, any ideas...?

DennO

Comments

  • BeanBean Posts: 8,129
    edited 2018-09-06 12:35
    You need to convert the value into an ascii string.

    You can do it like this:
    DEVICE P8X32A,XTAL1,PLL16X
    FREQ 80_000_000
    
    Baud     CON "T9600"
    
    LCD_Pin  PIN 30 HIGH
    
    LCD_Data  DATA "The temperature is:"
    LCD_Data2 DATA "99999", 13, 0    ' The "99999" will get changed in code
    
    temp VAR LONG
    
    PROGRAM Start
    
    Start:
      PAUSE 5000
      FOR temp =0 to 20
        LCD_Data2 = STR temp, 5, 5
        SEROUT LCD_Pin, Baud, LCD_Data
      NEXT temp
      GOTO Start
    END
    
    

    Bean
  • Bean, I do understand your last thread, and I did run it, with a couple of changes....
    DEVICE P8X32A,XTAL1,PLL16X
    FREQ 80_000_000
    
    Baud     CON "T115200"    ''''9600"
    
    LCD_Pin  PIN 30 HIGH
    
    LCD_Data  DATA "The temperature is:",0
    LCD_Data2 DATA "99999", 13, 0    ' The "99999" will get changed in code
    
    temp VAR LONG
    
    PROGRAM Start
    
    Start:
      PAUSE 1000
      SEROUT LCD_Pin, Baud, LCD_Data
      FOR temp = 0 to 20
        LCD_Data2 = STR temp, 5, 5
        SEROUT LCD_Pin, Baud, LCD_Data2
        PAUSE 1000
      NEXT temp
      GOTO Start
    END
    

    However, I am trying to "insert" a variable in the middle (2 places actually) of the the following DATA statement...where your "insertion" is at the end of the first LCD_data statement...please note temp_1DEC, temp_2DEC. Is this even possible? I do have another way that does work, but uses 24 SEROUT commands to place (4) variables on 4 different lines of the LCD.
    LCD_data_1               DATA  clrLCD,beep,backLTon,posCMD,64,"TEMPERATURE IS",posCMD,84,"TEMPERATURE IS",posCMD,104,"VOLTAGE =",posCMD,119,"volts",posCMD,124,"VOLTAGE =",posCMD,139,"volts",0
    LCD_data_2               DATA  posCMD,79,temp_1DEC,posCMD,82,degreeSYM,posCMD,99,temp_2DEC,posCMD,102,degreeSYM,posCMD,115,".",posCMD,135,".",0
    

    Thanks...DennO
  • BeanBean Posts: 8,129
    edited 2018-09-09 15:08
    You cannot put variables in DATA statements. So temp_1DEC makes no sense and is not valid in PropBasic. You must put characters in that are placeholders for the values. That is where I use "99999".

    To do multiple values you can either break up the DATA statement into multiple DATA statements, or use offsets.
    LCD_data_2   DATA posCmd,79
    LCD_data_2A  DATA "11111", posCMD, 82, degreeSYM, posCmd, 99
    LCD_data_2B  DATA "22222",posCMD,102,degreeSYM,posCMD,115,".",posCMD,135,".",0
    
    LCD_data_2A = STR temp_1, 5, 5
    LCD_data_2B = STR temp_2, 5, 5
    SEROUT LCD_pin, Baud, LCD_data_2
    

    or
    LCD_data_2   DATA  posCMD,79,"11111",posCMD,82,degreeSYM,posCMD,99,"22222",posCMD,102,degreeSYM,posCMD,115,".",posCMD,135,".",0
    
    LCD_data_2(2) = STR temp_1, 5, 5 ' LCD_data_2(2) is position of "11111"
    LCD_data_2(12) = STR temp_2, 5, 5 ' LCD_data_2(12) is position of "22222"
    SEROUT LCD_pin, Baud, LCD_data_2
    

    Bean

    P.S. Originally I had LCD_data_2[2] and LCD_data_2[12] that was incorrect.
  • Bean....I like the offset idea. I did not see/read in the 1.48 about DATA offsets...thank you for your knowledge, once again. So, if I understand this correctly, when I......
    SEROUT LCD_pin, Baud, LCD_data_2
    

    That COMMAND will SEROUT the the LCD_data_2, first, then the LCD_data_2 [2], second, and then the LCD_data_2 [12], and fill in the "11111" and "22222".

    That will certainly reduce my coding...space.

    In reference to the STACK directive...should one just use STACK 255 and/or is the directive really necessary...?

    DennO
  • dennodenno Posts: 219
    edited 2018-09-08 14:02
    Bean, I never had any doubt in your coding abilities... as your help, actually works...I did have to figure out a few extra lines of code to get it to run...
    'the following DATA statments are to preload the display, the variables are loaded elsewhere in the program.
      LCD_data_1               DATA  clrLCD,beep,backLTon,posCMD,64,"TEMPERATURE IS",posCMD,84,"TEMPERATURE IS",posCMD,104,"VOLTAGE =",posCMD,119,"volts",posCMD,124,"VOLTAGE =",posCMD,139,"volts",0
      LCD_data_2               DATA  posCMD,79,"111",posCMD,82,degreeSYM,posCMD,99,"222",posCMD,102,degreeSYM,posCMD,115,".",posCMD,135,".",0
      LCD_data_2[3]            DATA  "111"
      LCD_data_2[9]            DATA  "222"
      SEROUT LCD_data_out, baud, LCD_data_1
      SEROUT LCD_data_out, baud, LCD_data_2
    

    After a few trial and errors...aka "UNKNOWN COMMAND",,,I added the extra DATA statements:
    LCD_data_2[3] DATA "111"
    LCD_data_2[9] DATA "222"

    Thanks again..and I am sure, as I move forward in using the PROP...I will have more.
    DennO
  • dennodenno Posts: 219
    edited 2018-09-09 11:50
    Bean, I thought I had it figured out but...I keep getting "UNKNOWN COMMAND" on line 115 and 119. There are a few lines that are commented out, and I have tried them all. Another thing that happens is I do get a "Susscessful" download in RED at the bottom, into the RAM and the EEPROM, but actually, it does now load, and at the bottom of the download page, it says there is an error on Line 530,13. As shown below......
    PropBasic Version 00.01.48 Aug 9, 2018

    Finished Compile. 251 Lines Read, 1355 Lines Generated, 0 Warnings, 0 Errors.

    Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
    Compiled for i386 Win32 at 08:17:48 on 2009/07/20
    Loading Object LCDdisplay_SE
    Loading Object LCD_1.spin

    LCD_1.spin - Error at (530,13) Expected End of Line, Assembly Conditio
    nal, BYTE, WORD, LONG or Assembly Instruction
    __LCD_DATA_2[3]_adr LONG 146
    ____________^

    Compiled 665 Lines of Code in 0.017 Seconds
    And here is the code that I am trying to run...again thanks for your time...much appreciated...when I uncomment line 101 below, I get the above LCD_1.spin error. When I leave it commented, I get the "UNKNOWN COMMAND"
    TASK LCD_1 LMM         'this TASK is running in COG 7   
      LCD_data_out     PIN  2   
      temp_1     VAR  LONG  'the temp_1erature data, itself..
      temp_2     VAR  LONG
      VOLT       VAR  LONG
      VOLTtenth  VAR  LONG
      VOLThunds  VAR  LONG
      VOLT_3v    VAR  LONG
      VOLTtenth_3v VAR LONG
      VOLThunds_3v VAR LONG
      MCPValue      VAR LONG
    '  LCD_data_2[3] VAR LONG
    'the following DATA statments are to preload the display, the variables are loaded elsewhere in the program.
      LCD_data_1  DATA  clrLCD,beep,backLTon,posCMD,64,"TEMPERATURE IS",posCMD,84,"TEMPERATURE IS",posCMD,104,"VOLTAGE =",0
      LCD_data_2  DATA  posCMD,79,"000",posCMD,82,degreeSYM,posCMD,99,"222",posCMD,102,degreeSYM,posCMD,115,".",posCMD,135,".",0
      LCD_data_3  DATA  posCMD,114, "1",posCMD,115,".",posCMD,116,"2",posCMD,117,"3",posCMD,119,"volts",posCMD,124,"VOLTAGE =",posCMD,139,"volts",0
    '  LCD_data_2[3]            DATA  "111"    <<<<<<< <<<<<BEAN this is LINE 101>>>>>>
    '  LCD_data_2[9]            DATA  "222"
    '  LCD_data_3[16]            DATA  "1"
    '  LCD_data_3[22]            DATA  "2"
    '  LCD_data_3[25]            DATA  "3" 
      SEROUT LCD_data_out, baud, LCD_data_1
      SEROUT LCD_data_out, baud, LCD_data_2
      SEROUT LCD_data_out, baud, LCD_data_3
    'LCD_data_2   DATA  posCMD,79,"11111",posCMD,82,degreeSYM,posCMD,99,"22222",posCMD,102,degreeSYM,posCMD,115,".",posCMD,135,".",0
    'LCD_data_2[2] = STR temp_1, 5, 5 ' LCD_data_2[2] is position of "11111"
    'LCD_data_2[12] = STR temp_2, 5, 5 ' LCD_data_2[12] is position of "22222"
     DO  
         RDLONG degrees_1, temp_1  'reading the temperature data that is in the HUB
         PAUSE 100
         LCD_data_2[3] = STR temp_1,3,5
    '     SEROUT LCD_data_out, baud, LCD_data_2[3]
         RDLONG degrees_2, temp_2  'reading the temperature data that is in the HUB
         PAUSE 100
    '     LCD_data_2[9] = STR temp_2,3,5
         RDLONG volt_location, VOLT
         PAUSE 100
         RDLONG tenth_location, VOLTtenth
         PAUSE 100
         RDLONG hunds_location, VOLThunds
         PAUSE 100
    '     LCD_data_3[16] = STR VOLT,1,5
    '     LCD_data_3[22] = STR VOLTtenth,1,5
    '     LCD_data_3[25] = STR VOLThunds,1,5
         RDLONG volt_location_3v, VOLT_3v
         PAUSE 100
         RDLONG tenth_location_3v, VOLTtenth_3v
         PAUSE 100
         RDLONG hunds_location_3v, VOLThunds_3v
         PAUSE 100
         actualVOLT_3v = STR VOLT_3v,1
         actualVOLTtenth_3v = STR VOLTtenth_3v,1
         actualVOLThunds_3v = STR VOLThunds_3v,1'
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 134
         SEROUT LCD_data_out, baud, actualVOLT_3v
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 136
         SEROUT LCD_data_out, baud, actualVOLTtenth_3v
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 137
         SEROUT LCD_data_out, baud, actualVOLThunds_3v
     LOOP 
    ENDTASK LCD_1  
    
  • BeanBean Posts: 8,129
    I see the problem. Totally my fault...
    I made a typo the index needs to be in parens not brackets.
    LCD_data_2(3)

    You don't need any of those extra DATA lines with the offsets. Those make no sense...

    Just do
         LCD_data_2(3) = STR temp_1,3,5
    

    Again, sorry my bad. I will fix the previous post.

    Bean
  • Gosh...Bean, I was pulling my hair out....funny, isn't it. Thanks again...and again. You are certainly good at what you do...you can see that the extra DATA lines, were commented out, but I was trying everything, instead of mowing the lawn...LOL

    DennO
  • dennodenno Posts: 219
    edited 2018-09-11 14:01
    Thanks again, Bean, I finally got the indexing of DATA statements to work...my problem was I was forgetting to append the ",5" modifier after the index position number, plus, the first DATA statement is in position "0"...silly me...DennO
  • BeanBean Posts: 8,129
    "22222" is at index (12) not at index(8).
    You have the comment correct, but the code is not correct.

    Bean
  • Bean...this code runs very nicely, and uses far less space, have omitted alot of SEROUT commands. It is just practice code, that is running in different COG(s) and putting information in the HUB and extracting it in yet another COG for display on the LCD. Of course it is not the whole program, just a snippit from the one COG. Index position commands are all good, and in the proper places....frankly, I find PROPBASIC much easier to write with, then SPIN. I know that alot of "code writers" like the OBX exchange, but again, I find that reading some of those programs very hard for a beginner in the PROP. Especially, when you have to figure out, in an OBJECT which part you want to "inject" your bit of code into to get the proper response....hope I am making since. Keep in mind, I am not a beginner in PBASIC...I like my code to read like a book, and not "hyrogrifics"..(spelling?) Thanks again..DennO
    'the following DATA statments are to preload the display, the variables are loaded elsewhere in the program.
    
      LCD_data_1  DATA  clrLCD,beep,backLTon,posCMD,64,"TEMPERATURE IS",posCMD,82,degreeSYM,0  'LCD...line 1
      LCD_data_2  DATA                       posCMD,84,"TEMPERATURE IS",posCMD,102,degreeSYM,0 'LCD...line 2 
      LCD_data_3  DATA  posCMD,104,"VOLTAGE =",posCMD,115,".",posCMD,119,"volts",0
      LCD_data_4  DATA  posCMD,124,"VOLTAGE =",posCMD,134,"1",posCMD,135,".",posCMD,136,"2",posCMD,137,"3",posCMD,139,"volts",0
    
      SEROUT LCD_data_out, baud, LCD_data_1  'to print line 1
      SEROUT LCD_data_out, baud, LCD_data_2  'to print line 2
      SEROUT LCD_data_out, baud, LCD_data_3  'to print line 3 
      SEROUT LCD_data_out, baud, LCD_data_4  'to print line 4 
     DO  
         RDLONG degrees_1, temp_1  'reading the temperature data that is in the HUB
         PAUSE 100
         LCD_data_1a  DATA  posCMD,79,"000",0
         LCD_data_1a(2) = STR temp_1,3
         SEROUT LCD_data_out, baud, LCD_data_1a
         RDLONG degrees_2, temp_2  'reading the temperature data that is in the HUB
         PAUSE 100
         LCD_data_2a  DATA posCMD,99,"222",0
         LCD_data_2a(2) = STR temp_2,3
         SEROUT LCD_data_out, baud, LCD_data_2a
         RDLONG volt_location, VOLT        'reading the voltage data that is in the HUB
         PAUSE 100
         RDLONG tenth_location, VOLTtenth  'reading the voltage data that is in the HUB
         PAUSE 100
         RDLONG hunds_location, VOLThunds  'reading the voltage data that is in the HUB
         PAUSE 100
         LCD_data_3a  DATA posCMD,114,"1",posCMD,116,"2",posCMD,117,"3",0
         LCD_data_3a(2) = STR VOLT,1,5
         LCD_data_3a(5) = STR VOLTtenth,1,5
         LCD_data_3a(8) = STR VOLThunds,1,5
         SEROUT LCD_data_out, baud, LCD_data_3a
         RDLONG volt_location_3v, VOLT_3v
         PAUSE 100
         RDLONG tenth_location_3v, VOLTtenth_3v
         PAUSE 100
         RDLONG hunds_location_3v, VOLThunds_3v
         PAUSE 100
         LCD_data_4a  DATA posCMD,134,"1",posCMD,136,"2",posCMD,137,"3",0
         LCD_data_4a(2) = STR VOLT_3v,1,5
         LCD_data_4a(5) = STR VOLTtenth_3v,1,5
         LCD_data_4a(8) = STR VOLThunds_3v,1,5
         SEROUT LCD_data_out, baud, LCD_data_4a
     LOOP 
    
  • BeanBean Posts: 8,129
    Denno,
    There is no need to use STR for 1 digit values. (STR generates a lot of code).

    Just do this:
      RDLONG volt_location, VOLT
      INC VOLT, "0"  ' Convert value to ascii digit (quote zero quote)
      WRBYTE LCD_data_3a(2), VOLT
    

    Just be sure to DEC VOLT, "0" if you want to use the value after using WRBYTE to put it in the data string.

    That will save a bunch of code...

    Bean
  • dennodenno Posts: 219
    edited 2018-09-18 12:19
    Good morning again Bean...been spending alot of time playing around with PROPBASIC, and filling up all the COG(s) with different programs to run and display on different parts of a Scott Edwards LCD. The DATA statements that you told me about and placing using indexing, works very well...

    I know I can do regular math in a COG, but I am wondering, (first)...why I have to send data as a STR XXXXXXX, X as in the following example: I am quite good at interger math, as that is what is used, as you know in PBASIC. But I find myself, having to do the same with PROPBASIC, to get it to the LCD...
         LCD_data_1aa  DATA posCMD,79,"11",posCMD,81,".",posCMD,82,"3",posCMD,83,degreeSYM,0
         LCD_data_1aa(2) = STR TEMP_100,2,5
         LCD_data_1aa(8) = STR TEMP_tenths,1,5
         SEROUT LCD_data_out, baud, LCD_data_1aa 
    

    In reading through your 1.48 "rules of the road", I see there is a VAL and a ABS, can't these be used to change a STRING to some decimal value. I know in PBASIC, if I modify something that I want to send to the display, I preface the VAR with DEC(x). I hope I am making since...

    As far as the example you gave me, (#2 below), I kept getting ERROR messages, when I was trying to use it for one "digit" to get it into a index DATA statement...instead of using as example the following code...(#1 below)

    #1..example
         LCD_data_3a  DATA posCMD,114," ",posCMD,116," ",posCMD,117," ",0
         LCD_data_3a(2) = STR VOLT,1,5
         LCD_data_3a(5) = STR VOLTtenth,1,5
         LCD_data_3a(8) = STR VOLThunds,1,5
         SEROUT LCD_data_out, baud, LCD_data_3a
    
    Bean, I keep getting an error message with the following code...
    #2 example
      RDLONG volt_location, VOLT
      INC VOLT, "0"  ' Convert value to ascii digit (quote zero quote)
    

    And, last, are you going to or is there a later "rules of the road" then 1.48? I just think that PROPBASIC is easier to use/learn, along the lines of PBASIC then SPIN...no offence to those that put SPIN language together.

    DennO





  • In BASIC, Print 4 X 2 will output 8

    Print "4 X 2“ will output 4 X 2

    Look at an ASCII chart, Print a decimal 13 and you will get a carriage return.
    Print a decimal 10 and you will get a line-feed.
  • dennodenno Posts: 219
    edited 2018-09-18 12:26
    Thank you Mickster, and I rewrote my last thread, to better explain what I am doing, and according to Bean, I do not have to use "STR" command for just one character, but instead can use the "INC" to save code space. In example #1, that does work, very well for indexing VAR(s) into a DATA statement...and I do not see any explaination of the "INC" or the "DEC" command in the 1.48...

    Keep in mind, I am writing to a stand alone LCD display, made by Scott Edwards, so one has to tell the display where to print stuff, by a position command...I am not sending stuff to the computer screen....

    DenO
  • Bean...just wondering if you have read my post/thread about using the INC command? I know you are busy....but I will ask again.
         LCD_data_3a  DATA posCMD,114," ",posCMD,116," ",posCMD,117," ",0
         LCD_data_3a(2) = STR VOLT,1,5
         LCD_data_3a(5) = STR VOLTtenth,1,5
         LCD_data_3a(8) = STR VOLThunds,1,5
         SEROUT LCD_data_out, baud, LCD_data_3a
    

    Now, the above code will run and place the VAR(s) in the proper locations on the LCD.

    But, if I change the code to:
         LCD_data_3a  DATA posCMD,114," ",posCMD,116," ",posCMD,117," ",0
         LCD_data_3a(2) = INC VOLT, "0"
         LCD_data_3a(5) = INC VOLTtenth, "0"
         LCD_data_3a(8) = INC VOLThunds, "0"
         SEROUT LCD_data_out, baud, LCD_data_3a
    
    to save code space, I get this....ERROR message
     150       LCD_data_3a  DATA posCMD,114," ",posCMD,116," ",posCMD,117," ",0
     151       LCD_data_3a(2) = INC VOLT, "0"
     ERROR  5  INVALID PARAMETER "INC"  ; 
    

    And, I am using the INC after a RDLONG command.

    So, what am I doing wrong...LOL...DennO
  • @denno:

    INC adds a value to an integer variable. It's completely different from STR, which converts an integer into a string. There's no general way to replace STR with INC. In the case of a one digit number you might be able to do something like:
      ' convert VOLT to ASCII (WARNING: changes VOLT)
      INC VOLT, "0"
      ' put it in the output data
      LCD_data_3a(2) = VOLT
    
    but that will ONLY work if VOLT is between 0 and 9; other values will fail badly. Also note that this changes VOLT, so if you want to use that value later save it off somewhere. The formatting will also be a bit different from the STR case.

    Eric
Sign In or Register to comment.