'18F4431 32MHz XTL PCB8 BASE_SLAVE MATCH SHORT D 210123 1501
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 str_to_match 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 = "$GNRMCY.00A3723." 'edit the gnrmc bit to produce an invalid string while testing
str_to_match = "GNRMC" ' the string to be checked for
position = 1 ' the starting position of the long string (in this case gnmrc_str
'check For the id String
'This funtion is called "match"
'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 have used gnrmc in
'this example but it could be robi, ROBI, bori, BORI etc
If match(gnrmc_str, position, str_to_match) = 1 Then
Serout PORTB.0, 9600, "GOOD ", gnrmc_str(0), gnrmc_str(1), gnrmc_str(2), gnrmc_str(3), gnrmc_str(4), gnrmc_str(5), gnrmc_str(6), gnrmc_str(7), CrLf
Else
Serout PORTB.0, 9600, "BAD ", gnrmc_str(0), gnrmc_str(1), gnrmc_str(2), gnrmc_str(3), gnrmc_str(4), gnrmc_str(5), gnrmc_str(6), gnrmc_str(7), CrLf
Endif
Break ' remove this line when finished testing
Goto main_loop
End
'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 'the position to start checking from
Dim shortstring As Byte ' needed to make the loop work
Dim shortposition As Byte 'the current position in the short string
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 match_str_len
Break '<<<<<<<<<<<<<<
shortstring = position_counter - match_str_len
If input_str(position_counter) = match_str(shortposition) Then
match = 1 ' set the match indicator to valid
shortposition = shortposition + 1 ' increment the short string position counter
Else
match = 0 'set the match indicator To Not valid
Exit ' jump out of the loop
Endif
Next position_counter
End Function