USART Charcter Comparison
Posted: Sat Jan 19, 2008 4:24 pm
Hi All,
I am stumped on trying compare characters coming in from the USART. I thought I understood it the other day when I asked about it but I guess I don't. Listed below is what I tried but I think my issue is I am trying to compare a HEX constant to a character coming in, and I can't seem to figure out how to convert the character coming in as a hex byte. I am using the ReadSerial() routine to get the characters from the UART. Any help would be appreciated
Thanks
Public const TEST(4) as byte = ($42 $4F $4F $54) // Ascii "BOOT"
// Read serial port
Sub ReadSerial()
Dim Index As Byte
SDataSize = 0
While ISRRX.DataAvailable
SData(SDataSize) = ISRRX.ReadByte()
Inc(SDataSize)
Inc (ByteCount)
Wend
If SDataSize > 0 Then
For Index = 0 To (SDataSize - 1)
RXData(Index) = SData(Index)
Next
EndIf
End Sub
While ByteCount <= 3 // Sits And Waits For The BOOT string to come in
ReadSerial
Wend
For I = 0 To 3 Step 1 // Loop Thru All 4 Charcters To Verify Them
If SData(I) = Boot(I) Then
Inc (BytesCorrect,1) // If Charcter Matched Increment Counter
Else
Goto END // If Charcter Fails Exit
Endif
Next
I am stumped on trying compare characters coming in from the USART. I thought I understood it the other day when I asked about it but I guess I don't. Listed below is what I tried but I think my issue is I am trying to compare a HEX constant to a character coming in, and I can't seem to figure out how to convert the character coming in as a hex byte. I am using the ReadSerial() routine to get the characters from the UART. Any help would be appreciated
Thanks
Public const TEST(4) as byte = ($42 $4F $4F $54) // Ascii "BOOT"
// Read serial port
Sub ReadSerial()
Dim Index As Byte
SDataSize = 0
While ISRRX.DataAvailable
SData(SDataSize) = ISRRX.ReadByte()
Inc(SDataSize)
Inc (ByteCount)
Wend
If SDataSize > 0 Then
For Index = 0 To (SDataSize - 1)
RXData(Index) = SData(Index)
Next
EndIf
End Sub
While ByteCount <= 3 // Sits And Waits For The BOOT string to come in
ReadSerial
Wend
For I = 0 To 3 Step 1 // Loop Thru All 4 Charcters To Verify Them
If SData(I) = Boot(I) Then
Inc (BytesCorrect,1) // If Charcter Matched Increment Counter
Else
Goto END // If Charcter Fails Exit
Endif
Next