Shop OBEX P1 Docs P2 Docs Learn Events
display data from two functions from main — Parallax Forums

display data from two functions from main

chris joneschris jones Posts: 391
edited 2009-10-20 05:51 in BASIC Stamp
i have a few sub functions and i can call them and print from wiuthin the function but i want to display info from more than 1 function on the screen


HERE IS ALL OF MY CODE

' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Revision History ]

'
[noparse][[/noparse] I/O Definitions ]
Rx············· PIN···· 7············· ' Receiver(27981)DATA pin
TxEnable······· PIN···· 9············· ' Transmitter(27980)PDN pin
Tx············· PIN···· 8············· ' Transmitter(27980)DATA pin
SDA············ PIN···· 3············· ' I2C serial data line
SCL············ PIN···· 4············· ' I2C serial clock line
TxPin·········· CON···· 15
EN····· PIN 0······ ' Connect to SLED4C enable pin #5


'
[noparse][[/noparse] Constants ]
EOM············ CON···· 255············ ' Value to signal end-of-message
Address········ CON····· $A0··········· ' Address Of 24LC128
Ack············ CON····· 0············· ' Acknowledge Bit
#SELECT $STAMP························· ' Select Baud constants
· #CASE BS2, BS2E, BS2PE
··· T1200······ CON···· 813
··· T2400······ CON···· 396
··· T4800······ CON···· 188
··· T9600······ CON···· 84
··· T19K2······ CON···· 32
· #CASE BS2SX, BS2P
··· T1200······ CON···· 2063
··· T2400······ CON···· 1021
··· T4800······ CON···· 500
··· T9600······ CON···· 240
··· T19K2······ CON···· 110
· #CASE BS2PX
··· T1200······ CON···· 3313
··· T2400······ CON···· 1646
··· T4800······ CON···· 813
··· T9600······ CON···· 396
··· T19K2······ CON···· 188
#ENDSELECT
Inverted······· CON···· $4000·········· 'Value for inverted serial format
Baud··········· CON···· T9600+Inverted· '9600 baud, 8,N,1 inverted
Nak············ CON···· 1······················ ' no ack bit
EE24LC32······· CON···· %1010 << 4
Baud19200······ CON···· 32
'
[noparse][[/noparse] Variables ]
string········· VAR···· Byte(3)······· 'Array to hold received data
strLen········· VAR···· Byte··········· 'Length of string received
temp··········· VAR···· Byte··········· 'Temporary variable
packet········· VAR···· Byte··········· 'Current packet number
lastPacket····· VAR···· Byte··········· 'Last good packet number
cValue········· VAR···· Byte··········· 'Value to add to CRC value
crc············ VAR···· Word··········· 'Calculate CRC value
rcvdCrc········ VAR···· Word··········· 'Received CRC value
idx············ VAR···· Word··········· 'Index into message data
char··········· VAR···· Byte··········· 'Current character from message
'temp2·········· VAR····· Byte·········· ' Variable Used For Work
'i2cWork········ VAR····· Word·········· ' Work Byte For I2C I/O
'i2cAck········· VAR····· Bit··········· ' Ack Bit From Device
'eeprom_add····· VAR····· Word·········· ' EEPROM Address
cnt············ VAR····· Byte
test··········· VAR····· Nib
ADDR··········· VAR····· Byte
CFG············ VAR····· Byte··· ' Holds display configuration value
Hours·········· VAR····· Byte
Minutes········ VAR····· Byte
Days··········· VAR····· Byte················· ' FOR...NEXT loop index
seconds········ VAR····· Byte················· ' FOR...NEXT loop index


'
[noparse][[/noparse] Initialization ]
Message DATA "WSN A"
······· DATA EOM
Check_Module:
· #IF ($STAMP >= BS2P) #THEN
··· #ERROR "Use I2COUT and I2CIN!"
· #ENDIF
Setup:
HIGH TxPin ' Set pin high to be a serial port
PAUSE 100 ' Pause for Serial LCD to initialize
BoardID DATA "A1"
·' DEBUG CLS
SEROUT TxPin, Baud19200, [noparse][[/noparse]$0C]· ' clear LCD
SEROUT TxPin, Baud19200,[noparse][[/noparse]"WSN", CR,
······· "
", CR,
····· '· "Address...···· ", CR,
······ ' "Output....···· ", CR,
······ ' "Input.....···· ", CR,
····· '· "Status....···· ", CR,
····· '· "Errors....···· ", CR,
····· '· "Light.....···· ", CR,
····· '· "Battery....··· ", CR,
····· '· "Sensors....··· ", CR,
······· "TPacket. ", CR,
······· "RPacket. "]

· '·· GOTO main
'
[noparse][[/noparse] Program Code ]
main:
DO
GOSUB clock
GOSUB transmit
LOOP

clock:
DO
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86,DEC Hours, ":", DEC2 Minutes, ":",DEC2 seconds] ' display the time ell
PAUSE 1000 ' This may need to be adj for how long it take to run this routine
seconds = seconds + 1
IF seconds = 60 THEN
minutes = minutes + 1
seconds = 0
ENDIF
IF hours = 23 AND minutes = 59 THEN
days = days + 1
ELSE
IF minutes = 60 THEN
hours = hours + 1
minutes = 0
ENDIF
ENDIF
LOOP ' never stop the loop
'
[noparse][[/noparse] Subroutines ]
Transmit:
' Send the test data to another node
LOW Tx································· 'Initialize transceiver interface
LOW TxEnable··························· 'Disable transmitter
packet = 1····························· 'Initialize packet number
··· DO
· idx = message······················· 'Point idx to start of message data
················ DO
··· strLen = 0························· 'Set string length to zero
··· crc = 0···························· 'Start Crc at zero
··· DO
····· strLen = strLen + 1
····· READ idx, char··················· 'Read a character from message data
····· idx = idx + 1···················· 'Point to next character in message
····· string(strLen-1) = char·········· 'Put character into string array
····· temp = char······················ 'Prepare to add char to Crc value
····· GOSUB CalcCRC2···················· 'Add cValue to Crc value
····· IF (strLen = 2) OR (char = EOM) THEN EXIT ' Exit if done
LOOP······················· 'Keep reading message characters
DO
RecvTimeOut:
····· PAUSE 100························ 'Give receiver time to process
····· SEROUT TxPin, Baud19200,[noparse][[/noparse] DEC packet,$0a,$B1]· ' set num
····· HIGH TxEnable···················· 'Enable transmitter
····· ' Send packet
····· PULSOUT Tx,1200·················· 'Send sync pulse to radio
····· ' Send preample "UUUU!", packet #, string length, string data, crc
····· SEROUT Tx, Baud, [noparse][[/noparse]"UUUU!", packet, strLen, STR string\strLen,
······················· crc.LOWBYTE, crc.HIGHBYTE]
····· LOW TxEnable····················· 'Disable transmitter
····· ' Wait for response from receiver
GetResponse:
····· ' Receive up to 100 characters looking for a "!"
····· ' Use rcvdCrc as temporary variables
····· FOR rcvdCrc.LOWBYTE = 1 TO 10
······· SERIN Rx,Baud,600,RecvTimeOut,[noparse][[/noparse]rcvdCrc.HIGHBYTE]
······· IF rcvdCrc.HIGHBYTE = "!" THEN EXIT
····· NEXT
····· ' If we didn't receive a "!" then timeout
····· IF rcvdCrc.HIGHBYTE <> "!" THEN RecvTimeOut
····· ' Receive the Crc value
····· SERIN Rx,Baud,600,RecvTimeOut,[noparse][[/noparse]rcvdCrc.LOWBYTE,rcvdCrc.HIGHBYTE]
··· LOOP UNTIL crc = rcvdCrc··········· 'Repeat packet until crc match
··· packet = packet + 1················ 'Advance packet value
··· packet = packet MIN 1·············· 'Don't use packet value zero
· LOOP WHILE char <> EOM··············· 'Keep sending until EOM
LOOP···························· 'Start all over at the beginning
Recive:
' recive data from another node
LOW Tx
LOW TxEnable
DO
· ' Wait for preamble, then receive data and crc value
· SERIN Rx,Baud,[noparse][[/noparse]WAIT ("U!"), packet, strLen, STR string\strLen,
················ rcvdCrc.LOWBYTE,rcvdCrc.HIGHBYTE]
· ' Calculate crc of received data
· crc = 0
· FOR temp = 0 TO strLen-1
··· cValue = string(temp)
··· GOSUB CalcCRC
· NEXT
· ' See if received crc value matches calculated crc value
· IF rcvdCrc = crc THEN
··· ' Check if this is a repeated packet
··· IF packet <> lastPacket THEN
····· ' Is last character the "end-of-message" marker ?
····· IF string(strLen-1) <> EOM THEN
······ SEROUT TxPin, Baud19200,[noparse][[/noparse]STR string\strLen ,$0a,$B1] ' set num·· ]·········· ' Display string on debug screen
····· ELSE
······· strLen = strLen -1··············· ' Don't display EOM
······· SEROUT TxPin, Baud19200,[noparse][[/noparse] STR string\strLen,$0a,$B1] ' set num·· ]
····· ENDIF
··· ENDIF
··· lastPacket = packet
··· ' Send acknoledgement back to transmitter
··· HIGH TxEnable
··· PULSOUT Tx,1200
··· SEROUT Tx, Baud, [noparse][[/noparse]"UUUU"]
··· PAUSE 3···························· ' Give transmitter time to process
··· SEROUT Tx,Baud, [noparse][[/noparse]"!"]
··· PAUSE 3···························· ' Give transmitter time to process
··· SEROUT Tx, Baud, [noparse][[/noparse]crc.LOWBYTE, crc.HIGHBYTE]
··· LOW TxEnable
· ELSE
··· ' Received crc did NOT match calculated crc
··· SEROUT TxPin, Baud19200, [noparse][[/noparse]"· ** RECEIVE ERROR **· ",BELL,$0a,$B1] ' set num·· ]
· ENDIF
LOOP
' CRC Checksum Calculation Routine
CalcCRC:
· CValue= crc.HIGHBYTE ^ cValue >> 4 ^ (crc.HIGHBYTE ^ cValue)
· crc = cValue ^ (cValue << 5) ^ (cValue << 12) ^ (crc << 8)
RETURN

' CRC Checksum Calculation Routine
CalcCRC2:
· temp= crc.HIGHBYTE ^ temp >> 4 ^ (crc.HIGHBYTE ^ temp)
· crc = temp ^ (temp << 5) ^ (temp << 12) ^ (crc << 8)
RETURN
I2C_Stop:····························· ' I2C Stop Bit Sequence
· LOW SDA
· INPUT SCL
· INPUT SDA··························· ' SDA --> High While SCL High
RETURN
I2C_Start:···························· ' I2C Start Bit Sequence
· INPUT SDA
· INPUT SCL
· LOW SDA····························· ' SDA --> Low While SCL High
RETURN
Addrs:································ ' I2C Address Byte Sequence
·' i2cWork = eeprom_add
· 'SHIFTOUT SDA, SCL, MSBFIRST, [noparse][[/noparse]i2cWork.HIGHBYTE\8] ' Send Byte To Device
·' SHIFTIN SDA, SCL, MSBPRE, [noparse][[/noparse]i2cAck\1] ' Get Acknowledge Bit
·' SHIFTOUT SDA, SCL, MSBFIRST, [noparse][[/noparse]i2cWork.LOWBYTE\8] ' Send Byte To Device
·' SHIFTIN SDA, SCL, MSBPRE, [noparse][[/noparse]i2cAck\1] ' Get Acknowledge Bit
RETURN
Control_Byte_Write:··················· ' I2C Control Write Byte Sequence
·' i2cWork = Address
·' i2cWork.BIT0 = 0···················· ' Sets Unit To Write
·' SHIFTOUT SDA, SCL, MSBFIRST, [noparse][[/noparse]i2cWork\8] ' Send Byte To Device
·' SHIFTIN SDA, SCL, MSBPRE, [noparse][[/noparse]i2cAck\1] ' Get Acknowledge Bit
RETURN
Control_Byte_Read:···················· ' I2C Control Read Byte Sequence
·' i2cWork = Address
·' i2cWork.BIT0 = 1···················· ' Sets Device To Read
·' SHIFTOUT SDA, SCL, MSBFIRST, [noparse][[/noparse]i2cWork\8] ' Send Byte To Device
·' SHIFTIN SDA, SCL, MSBPRE, [noparse][[/noparse]i2cAck\1] ' Get Acknowledge Bit
RETURN
Write_Data:··························· ' I2C Write Byte Sequence
·' i2cWork = temp
· 'SHIFTOUT SDA, SCL, MSBFIRST, [noparse][[/noparse]i2cWork\8] 'Send Byte To Device
·' SHIFTIN SDA, SCL, MSBPRE, [noparse][[/noparse]i2cAck\1] ' Get Acknowledge Bit
RETURN

Comments

  • Mike2545Mike2545 Posts: 433
    edited 2009-10-20 01:16
    Use the debug command and it will display the information on the screen.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike2545

    This message sent to you on 100% recycled electrons.
  • chris joneschris jones Posts: 391
    edited 2009-10-20 01:32
    i know and i have been doing that but for exmaple in my code

    i want to display
    SEROUT TxPin, Baud19200,[noparse][[/noparse]$86,DEC Hours, ":", DEC2 Minutes, ":",DEC2 seconds] ' display the time ell
    PAUSE 1000 ' This may need to be adj for how long it take to run this routine
    SEROUT TxPin, Baud19200, [noparse][[/noparse]" ** RECEIVE ERROR ** ",BELL,$0a,$B1] ' set num ]


    but the line of code that states
    SEROUT TxPin, Baud19200, [noparse][[/noparse]" ** RECEIVE ERROR ** ",BELL,$0a,$B1] ' set num ]

    that is in another function/ SUB
  • FranklinFranklin Posts: 4,747
    edited 2009-10-20 02:46
    Your code goes into the time loop and never comes out. That is how you have it programmed.

    You also have too many threads on the same or similar issues, next time think before you post and then post ONE good thread and get your answers there.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen

    Post Edited (Franklin) : 10/20/2009 2:52:10 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-20 04:18
    Apropos Franklin's comment ... You've obviously used the code I suggested in one of your other threads where I asked you repeatedly what you're trying to do and you answered several times that you wanted to display elapsed time. I tried to make it clear that, if your program was only for keeping track of elapsed time, there was one solution (that I gave). If your program was to do anything else, then you needed a different solution (an external real time clock chip). Please don't waste our time. Answer the questions we ask. They're not asked just for the fun of it. The answers are important.

    In this case, your program is partly hanging up because you're using a solution you've been given that's intended for other situations. It won't work for the situation you've now presented.
  • chris joneschris jones Posts: 391
    edited 2009-10-20 05:50
    Hello

    sorry for asking the questions i missunderstood how i can ask questions, so i can open 1 thread and ask as many questions as i need in that thred.i will start to do that but how do i name my subject if there are more than 1 topic in 1 thread?
  • chris joneschris jones Posts: 391
    edited 2009-10-20 05:51
    and sorry for waste everyones time with my questions
Sign In or Register to comment.