Shop OBEX P1 Docs P2 Docs Learn Events
The DATA command — Parallax Forums

The DATA command

RobbanRobban Posts: 124
edited 2008-02-21 08:43 in BASIC Stamp
Hi!

i want my stamp to read several data and check if it is within the limits...it not then print a string...

here is my program.

' {$STAMP BS2p}
' {$PBASIC 2.5}
varv VAR Word
speed VAR Byte
cool VAR Byte
air VAR Byte
airflow VAR Byte
pressure VAR Byte
load VAR Byte
voltage VAR Byte
sp VAR Byte
rpm VAR Word
kylare VAR Byte
luft VAR Byte
flode VAR Byte
tryck VAR Byte
laddning VAR Byte
volt VAR Byte
spbp VAR Nib
char VAR Byte
· a VAR Byte

Tx············· CON···· 8······················ ' connects to Emic SIn
Rx············· CON···· 9······················ ' connects to Emic SOut
Busy··········· CON···· 10······················ ' 1 = busy
Rst············ CON···· 11······················ ' low to reset Emic TTS
AOut··········· CON···· 12····················· ' audio out from Stamp
Baud··········· CON···· 1021
OK············· CON···· $55
EOM············ CON···· $AA
Say············ CON···· $00

' read current value
main:
STORE 2
READ· 11,varv.LOWBYTE
READ 12,varv.HIGHBYTE
READ 13,speed
READ 14,COOL
READ 15,air
READ 16,airflow
READ 17,pressure
READ 18,load
READ 19,voltage
READ 20,spbp
'read limitvalues
STORE 4
READ 17,sp
READ 27,rpm
READ 37,kylare
READ 47,luft
READ 57,flode
READ 67,tryck
READ 77,laddning
READ 87,volt
'check values
IF speed>sp THEN highspeed
IF varv>rpm*100 THEN highrpm
IF cool>kylare THEN highcool
IF air>luft THEN HIGHair
IF airflow<flode THEN lowflow
IF pressure<tryck THEN lowpressure
IF load>laddning THEN highload
IF voltage<volt THEN lowvoltage

highspeed:
DATA "WARNING! HIGH SPEED!"
GOTO printit
highrpm:
DATA········ "WARNING! HIGH RPM!"
GOTO printit
highcool:
DATA··· "WARNING! HIGH COOLING TEMP!"
GOTO printit
highair:
DATA····· "WARNING! HIGH AIRTEMP!"
·GOTO printit
lowflow:
DATA····· "WARNING! LOW AIRFLOW!"
·GOTO printit
lowpressure:
DATA···· "WARNING! LOW AIRPRESSURE!"
·GOTO printit
highload:
DATA······ "WARNING! HIGH LOAD!"
GOTO printit
lowvoltage:
DATA······ "WARNING! LOW VOLTAGE!"
·GOTO printit

printit:
FOR a=1 TO 20
READ a,char
DEBUG char
NEXT
END


all i get is a bunch of yyyy.
why?

regards
Robban

Post Edited (Robban) : 2/12/2008 7:08:39 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-12 21:30
    The DATA statement is like the VAR statement. It only puts the data into the memory. It doesn't do anything with it.
    Perhaps you want to use a DEBUG statement as in DEBUG "WARNING! LOW VOLTAGE!" rather than a DATA statement.
    If you still want to use the DATA statement, you need a label on it so that you have some way to refer to the address
    where the data is stored in the program memory. You would then use the label when you GOTO the printit routine.
    char   var   byte
    address  var  word
    message1 DATA "WARNING! PHASER ON STUN!",0 ' the zero marks the end of the message
    message2 DATA "WARNING! PHASER ON KILL!",0
    
    showMsg1: address = message1
      GOTO printit
    showMsg2: address = message2
      GOTO printit
    
    printit:
      READ address,char
      IF char = 0 THEN GOTO printExit
      address = address + 1
      DEBUG char
      GOTO printit
    printExit:
      END
    
  • RobbanRobban Posts: 124
    edited 2008-02-17 20:31
    OK,.Thanks...i got it working...
    but how would it look like if i want to use a string of hex...like the following

    $1E,$11,$11,$1E,$11,$11,$1E,$00

    i tried B var $1E,$11,$11,$1E,$11,$11,$1E,$00

    but all i got what "Expected a varible"
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-17 21:17
    You can use hex or decimal values in a DATA statement just like the character strings and they'll get stored in successive bytes in program memory. Read the chapter on the DATA, READ, and STORE statements in the manual for examples.
  • RobbanRobban Posts: 124
    edited 2008-02-18 18:58
    I tried the data command but couldn´t find it out with hex...
    So i wrote a tedious program, now i wonder if it is possible to make this smaller with the same function??
    here is the program

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}


    CHAR VAR Word
    Q VAR Byte
    Q=0

    Z VAR Byte
    SEROUT 2,2409,[noparse][[/noparse]$19]


    test:
    DATA "HELLO WORLD",0


    printit:
    DO
    Q=Q+8
    READ Z, char
    GOSUB CHARS
    Z=Z+1
    LOOP UNTIL (CHAR=0)

    END

    CHARS:
    IF CHAR="A" THEN A
    IF CHAR="B" THEN B
    IF CHAR="C" THEN C
    IF CHAR="D" THEN D
    IF CHAR="E" THEN E
    IF CHAR="F" THEN F
    IF CHAR="G" THEN G
    IF CHAR="J" THEN J
    IF CHAR="K" THEN K
    IF CHAR="L" THEN L
    IF CHAR="M" THEN M
    IF CHAR="N" THEN N
    IF CHAR="P" THEN P
    IF CHAR="R" THEN R
    IF CHAR="S" THEN S
    IF CHAR="T" THEN T
    IF CHAR="U" THEN U
    IF CHAR="V" THEN V
    IF CHAR="W" THEN W
    IF CHAR="0" THEN ZERO
    IF CHAR="1" THEN ONE
    IF CHAR="2" THEN TWO
    IF CHAR="3" THEN THREE
    IF CHAR="4" THEN FORE
    IF CHAR="5" THEN FIVE
    IF CHAR="6" THEN SIX
    IF CHAR="7" THEN SEVEN
    IF CHAR="9" THEN NINE
    GOTO CH
    RETURN

    A:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$11,$11,$1F,$11,$11,$0A,$04,$00]
    RETURN

    B:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$1E,$11,$11,$1E,$11,$11,$1E,$00]
    RETURN
    C:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$0E,$11,$10,$10,$10,$11,$0E,$00]
    RETURN
    D:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$1E,$11,$11,$11,$11,$11,$1E,$00]
    RETURN
    E:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$1F,$10,$10,$1C,$10,$10,$1F,$00]
    RETURN
    F:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$10,$10,$10,$1C,$10,$10,$1F,$00]
    RETURN
    G:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$0E,$11,$11,$13,$10,$11,$0E,$00 ]
    RETURN
    J:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$0C,$12,$02,$02,$02,$02,$07,$00]
    RETURN
    K:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$11,$12,$14,$18,$14,$12,$11,$00]
    RETURN
    L:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$1E,$10,$10,$10,$10,$10,$10,$00]
    RETURN
    M: SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$11,$11,$11,$11,$15,$1B,$11,$00]
    RETURN

    N:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$11,$11,$13,$15,$19,$11,$11,$00]
    RETURN
    P:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$10,$10,$10,$1E,$11,$11,$1E,$00]
    RETURN
    R:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$11,$12,$14,$1E,$11,$11,$1E,$00]
    RETURN
    S:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$0E,$11,$01,$0E,$10,$11,$0E,$00]
    RETURN
    T:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$04,$04,$04,$04,$04,$04,$1F,$00]
    RETURN
    U:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$0E,$11,$11,$11,$11,$11,$11,$00]
    RETURN
    V:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$04,$0A,$11,$11,$11,$11,$11,$00]
    RETURN
    W:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$11,$1B,$15,$11,$11,$11,$11,$00]
    RETURN

    ZERO:
    SEROUT 2,240,[noparse][[/noparse]$1A,$40,$10,Q,10,$18,$08,$0E,$11,$19,$15,$13,$11,$0E,$00]
    RETURN
    ONE:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$0E,$04,$04,$04,$04,$0C,$04,$00 ]
    RETURN
    TWO:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$1F,$08,$04,$02,$01,$11,$0E,$00]
    RETURN
    THREE:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$0E,$11,$01,$06,$01,$11,$0E,$00]
    RETURN
    FORE:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$02,$02,$1F,$12,$0A,$06,$02,$00 ]
    RETURN
    FIVE:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08, $0E,$11,$01,$0E,$10,$10,$1F,$00 ]
    RETURN
    SIX:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$0E,$11,$11,$1E,$10,$08,$06,$00 ]
    RETURN
    SEVEN:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08, $08,$08,$08,$04,$02,$01,$1F,$00 ]
    RETURN
    NINE:
    SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,10, $18,$08,$0E,$11,$01,$0F,$11,$11,$0E,$00 ]
    RETURN

    CH:
    SEROUT 2,240,[noparse][[/noparse] $10,Q+3,17,CHAR ]
    RETURN
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-18 20:53
    Robban -

    I'm not sure what you're trying to accomplish with this program, but as it it is it probably won't do anything useful, and will·may terminate prematurely. All of the statements in the A: - NINE: routines terminate with a RETURN statement and a GOSUB was never issued. The problem begins in the CHARS routine as you can see below in this line extracted from your program:

    CHARS:
    IF CHAR="A" THEN A
    ...

    The THEN is an implied GOTO with the target routine as "A:", and is not a GOSUB. You must either change the implied GOTO to a GOSUB or change the A: - NINE: routines appropriately.

    As far as the DATA statement is concerned, HEX is fine in a DATA statement, if that's what you were trying to do:

    HexData DATA $10,$99,$A1,$B7,$D4,$C2,$A9,$BB,$55,$21 etc

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Genius is one percent inspiration and ninety-nine percent perspiration."

    Thomas Alva Edison

    Post Edited (Bruce Bates) : 2/18/2008 8:58:39 PM GMT
  • RobbanRobban Posts: 124
    edited 2008-02-19 21:31
    i tried to make another more compact program and this is what i did



    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    AA VAR Byte
    CHAR VAR Word
    Z VAR Byte
    CH VAR Word
    Q VAR Byte
    X VAR Byte


    DATA "S",0


    ' MASK OUT ONE FONT
    TESTA:
    DO
    READ Z, ch
    GOSUB MAIN
    Z=Z+1
    LOOP UNTIL (CH=0)
    END

    MAIN:

    SEROUT 2,240,[noparse][[/noparse]$1A ,$40, $10, 10,$1C, $18, $08] ' SET THE VFD TO GRAPHIC MODE


    LOOKUP CH,[noparse][[/noparse]A,B,C,D,E,F,G,J,K,L,M,N,P,R,S,T,U,V],AA ' LOOK FOR "S"

    ' EEPROM DATA
    A DATA $11,$11,$1F,$11,$11,$0A,$04,$00
    B DATA $1E,$11,$11,$1E,$11,$11,$1E,$00
    C DATA $0E,$11,$10,$10,$10,$11,$0E,$00
    D DATA $1E,$11,$11,$11,$11,$11,$1E,$00
    E DATA $1F,$10,$10,$1C,$10,$10,$1F,$00
    F DATA $10,$10,$10,$1C,$10,$10,$1F,$00
    G DATA $0E,$11,$11,$13,$10,$11,$0E,$00
    J DATA $0C,$12,$02,$02,$02,$02,$07,$00
    K DATA $11,$12,$14,$18,$14,$12,$11,$00
    L DATA $1E,$10,$10,$10,$10,$10,$10,$00
    M DATA $11,$11,$11,$11,$15,$1B,$11,$00
    N DATA $11,$11,$19,$15,$13,$11,$11
    P DATA $10,$10,$10,$1E,$11,$11,$1E,$00
    R DATA $11,$12,$14,$1E,$11,$11,$1E,$00
    S DATA $0E,$11,$01,$0E,$10,$11,$0E,$00
    T DATA $04,$04,$04,$04,$04,$04,$1F,$00
    U DATA $0E,$11,$11,$11,$11,$11,$11,$00
    V DATA $04,$0A,$11,$11,$11,$11,$11,$00


    ' TRANSFORM TO FLIPPED FONT (S)
    DO
    READ (AA+CH),char
    AA=AA+1
    IF (char=0) THEN END
    SEROUT 2,240,[noparse][[/noparse]CHAR] ' put into VFD
    LOOP
    RETURN



    now another problem..

    in this case when i choose an "S" i get the M on the VFD

    but then i change the row : READ (AA+CH),char
    to READ (AA+S),CHAR

    i get my S



    please help

    Robban

    Post Edited (Robban) : 2/19/2008 9:31:23 PM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-19 22:43
    Robban -

    At the risk of sounding like I'm not being helpful, have you considered just using a rectangular mirror to reverse the image from the VFD? If necessary you can add reflecting prisms to change the angles any way you might need them. If you need lenses after the image is reversed, that is certainly doable as well.

    This whole exercise seems rather tedious to me, unless there is some unknown reason for attempting to do this in software. Sometimes a software solution is the better or less expensive approach, other times it's a hardware solution that is more appropriate. In this case I'd choose a hardware solution, and that's not like me because I'm a programmer at heart!

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Genius is one percent inspiration and ninety-nine percent perspiration."

    Thomas Alva Edison
  • RobbanRobban Posts: 124
    edited 2008-02-20 06:52
    The reson i want to make this in software is that if i use a mirror i would have to use o box and i cannot build this in the dashboard since there is only 3 cm,wich is perfect for just the display to lay...the display itself isn´t more than 1,5 cm height.
    And i have not found any lenses that can flip the display.

    wonder? is my programming correct ?

    Robban
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-02-20 15:40
    Robban,

    Didn’t you already have a thread on this where someone mentioned that there was no need to flip certain characters? It seems you are still trying to flip characters such as ‘A’ and ‘U’ which yield no change in output but do take up more memory.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • RobbanRobban Posts: 124
    edited 2008-02-21 06:58
    yes i did,but i came to think that moving the vfd so that i flip the charters instead would be much easier because in mirrored mode i would had to write the text backwards aswell..

    What is prisms?

    Robban
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-21 08:43
    Robban -

    Due to your lack of space, I doubt a prism will help you. There is no kind of lens that will help either, but that's not due to the space problem.

    IF you were able to use a prism, the reversion prism (Dove prism) would be the one to use. Here is how a Dove prism operates to reverse the image: http://en.wikipedia.org/wiki/Dove_prism

    As far as prisms in general are concerned, take a look at this article: http://en.wikipedia.org/wiki/Prism_(optics)

    Sorry about the space problem. Your present software approach may well be the best one in this case.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Genius is one percent inspiration and ninety-nine percent perspiration."

    Thomas Alva Edison
Sign In or Register to comment.