Re: Parsing data from debugin

Originally Posted by
ardhuru
Hi,
Its been some time since I used PBP on a serious project, and I'm afraid I've gone a bit rusty.
I get a string of 9 characters (numerals only) from a device; the 1st character is always an '8'.
How would I split up the remaining 8 characters as 4 nos of 1,1,3 and 3 digits respectively?
I am using debug to read the incoming string. I suspect the first character, a constant "8", can be used as a qualifier.
What would the syntax for the debugin line be?
And then, suppose I receive a string ""812345678", how would I assign values to variables a,b,c,d such that a=1, b=2, c=345 and d=678?
Thanks for the help, guys!
Here is a program that has a qualifier and 2 variables to control relays.
Code:
@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
DEFINE OSC 4
DEFINE DEBUG_MODE 0 ' Debug sending True serial data
DEFINE DEBUG_REG_PORTA ' Debug Port = PortA as required by PICKIT2 serial Monitor
DEFINE DEBUG_BIT 0 ' Debug.bit = PortA.0
DEFINE DEBUG_BAUD 9600 ' Default baud rate = 9600
DEFINE DEBUGIN_REG PORTA' Debug Port = PortA as required by PICKIT2 serial Monitor
DEFINE DEBUGIN_BIT 1 ' Debugin bit PortA.1
DEFINE DEBUGIN_BAUD 9600' Default baud rate = 9600
DEFINE DEBUGIN_MODE 0 ' Debugin receiving data true = 0 inverted = 1
relay var byte 'relay number storage variable
state var byte 'relay state of ON/OFF variable
state = 0
relay = 0
PORTC = 0
ANSEL=0
ANSELH=0
ADCON0 = 0
ADCON1 = 0
CCP1CON = %10001100 ;Dual PWM 10xx11xx P1A/RC5 P1B/RC4 RC3/AN7 RC2/AN6
TRISA = %00001110
TRISB = %00000000
TrisC = %00000000
main:
DEBUGIN [WAIT($FF),state,RELAY]
PAUSE 30
ON RELAY GOSUB RELAY0,RELAY1,RELAY2,RELAY3,RELAY4
DEBUG state,RELAY
;TOGGLE PORTC.0
goto main
RELAY0:
IF state = 1 THEN
PORTC.0 = 1
ELSE
PORTC.0 = 0
ENDIF
RETURN
RELAY1:
IF state = 1 THEN
PORTC.1 = 1
ELSE
PORTC.1 = 0
ENDIF
RETURN
RELAY2:
IF state = 1 THEN
PORTC.2 = 1
ELSE
PORTC.2 = 0
ENDIF
RETURN
RELAY3:
IF state = 1 THEN
PORTC.3 = 1
ELSE
PORTC.3 = 0
ENDIF
RETURN
RELAY4: 'controls all ports simultaneously
IF state = 1 THEN
PORTC = 15
ELSE
PORTC = 0
ENDIF
RETURN
end
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Bookmarks