PDA

View Full Version : Parsing data from debugin



ardhuru
- 5th July 2013, 22:32
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!

Archangel
- 6th July 2013, 00:37
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.


@ __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

HenrikOlsson
- 6th July 2013, 08:44
Hi,
How about

Value_A VAR BYTE
Value_B VAR BYTE
Value_C VAR WORD
Value_D VAR WORD

DEBUGIN [WAIT("8"), DEC1 Value_A, DEC1 Value_B, DEC3 Value_C, DEC3 Value_D]

Untested so take it for what it is.

/Henrik.

ardhuru
- 6th July 2013, 13:03
Thanks Archangel, Henrik, worked a treat.

Couldnt imagine it would be that simple.

And now for one more related question; how reliable would it be if I use the MCLR pin as the debugin input?

Thanks for the prompt response, guys!