'18F4431 32MHz XTL PCB8 BASE_SLAVE match 2 strings E 170123 short 2
Define CONFIG1L = 0x00
Define CONFIG1H = 0x06 '8mHz x4 =32
Define CONFIG2L = 0x0c
Define CONFIG2H = 0x20
Define CONFIG3L = 0x04
Define CONFIG3H = 0x80
Define CONFIG4L = 0x80 'Set for HVP
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
'OSH config
Define CLOCK_FREQUENCY = 32
Define SINGLE_DECIMAL_PLACES = 2
Define STRING_MAX_LENGTH = 20
Define SEROUT_DELAYUS = 1000
'**********************************************************************
'* *
'* Register configuration *
'* *
'**********************************************************************
'------------- TARGET SETUP ------------------
'Const PR2set = 125 'use this for the live board: gets 5ms per interrupt
Const PR2set = 2 'use this for fast timing to speed up simulator
Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC
'**********************************************************************
'* *
'* IO Port configuration *
'* *
'**********************************************************************
'IN or OUT
Const TRISAinit = %11011000 '7=OSC, 6=OSC, 4=QEIB 3=QEIA 2=TEMP SEROUT
Const TRISBinit = %00000000
Const TRISCinit = %11000100 '7=1-RX, 6=1-slave4431_cs, 2=MOSI'RX<<<<<<<<<<<<<<<<<<<<<
Const TRISDinit = %00100000 '6=led, 7=led, 5=synch'D2=MOSI ??£
Const TRISEinit = %00000000 '2=TEST INDICATOR, 0= S2M_BUF_FULL
TRISA = TRISAinit
TRISB = TRISBinit
TRISC = TRISCinit
TRISD = TRISDinit
TRISE = TRISEinit
'SET BITS ON/OFF before TRIS!
Const LATAinit = %00000000 'ON/OFF
Const LATBinit = %00000000
Const LATCinit = %00000000
Const LATDinit = %00000000
Const LATEinit = %00000000 'POSS MCLR RE3
Symbol yled = PORTD.6
Symbol rled = PORTD.7
'START UP LEDS
rled = 1
WaitMs 1000
rled = 0
WaitMs 1000
yled = 1
WaitMs 1000
yled = 0
WaitMs 1000
Dim to_match_str As String ' the string to match
Dim gnrmc_str As String ' the string used for test purposes
Dim position As Byte ' the position in the main string to start from
main_loop: '/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Toggle rled
' set the string to be checked (in this case called gnrmc_str)
gnrmc_str = "$gnrmc0.00A3723."
to_match_str = "gnrmc"
position = 1
'check For the id String
' I have called this funtion "match" - you can call it anything you like as long as the name is consistent
' match uses 3 inputs. The first is the string to be tested. I have used gnrmc_str but it can be any valid string variable
' The second input is the position to start checking from. in this case it is the numbber 1
' (arrays start at 0 so the second character in the array is 1)
' The third input is the string of characters to be checked against. I hane used gnrmc in
' this example but it could be robi, ROBI, bori, BORI etc
Call match(gnrmc_str, position, to_match_str)
'Break
If match = 1 Then
'Break
' if OK go to good string found
Else
'Break
'if not ok goto bad string found
Endif
Goto main_loop
End
'the corresponding match function
Function match(ByVal input_str As String, ByVal str_ix As Byte, ByVal match_str As String) As Bit ' these variable names can be changes as wished
Dim match_str_len As Byte 'the number of characters to be match checked
Dim position_counter As Byte ' the index pointer for the character to be checked
Dim position_ix As Byte
Dim shortstring As Byte
Dim shortposition As Byte
position_ix = str_ix + match_str_len 'the position to start checking from
match_str_len = Len(match_str) ' find the length of the test string to be compared
For position_counter = str_ix To position_ix
shortstring = position_counter - match_str_len
'Break
If input_str(position_counter) = match_str(shortposition) Then
match = 1
Else
match = 0
Exit ' jump out of the loop
Endif
Next position_counter
End Function