Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20577

BASCOM-AVR : Buffered serial in handling ASCII STX and ETX [solved] : REPLY

$
0
0
Hi, OK here's the code I'm using:- Serial ISR: [code:1:4681659e33] 'Function : Read serial character from com2. If it's &h02 reset buffer, ' If the bufer contains 13 characters, copy the array into user ' space and set flag 'Author : Ian Dobson 'Inputs : None. 'Outputs : None 'Limitations : Registers used r10,r11,r16,r23,r24,r26.r27,sreg : 'Date : 29.1.2013 Rfid_input: !push r10 'save r10 !push r11 'save r11 !push r16 'save r16 !push r23 'save r23 !push r24 'save r24 !push r26 'save r26 !push r27 'Save R27 !IN r27, SREG 'Copy SREG into R27 !Push r27 'Save it (sreg) Rfid_char = Inkey(#1) 'Read serial char If Rfid_char = 2 Then 'Chr 2 - Start of MSG Rfid_ptr = 0 'Reset pointer End If Incr Rfid_ptr 'Move to next byte Rfid_array(rfid_ptr) = Rfid_char 'Save char to array If Rfid_ptr = 13 Then 'and correct length Rfid_have_buffer = 1 'tell user space Rfid_ptr = 0 'Reset buffer End If !pop r27 'restore sreg into r27 !Out Sreg , R27 'copy to sreg !pop r27 'restore r27 !pop r26 'restore r26 !pop r24 'restore r24 !pop r23 'restore r23 !pop r16 'restore r16 !pop r11 'restore r11 !pop r10 'restore r10 Return 'go home [/code:1:4681659e33] and the Decoding Routine (just add a call to this Routine when the Rfid_have_buffer flag is set). [code:1:4681659e33] Sub Decode_rfid() Function : Decode RFID checking that the format and checksum is correct 'Author : Ian Dobson 'Inputs : None. 'Outputs : None 'Limitations : The routine only works with a IDTec OEM RFID reader : 'Changes : Changed "and" to nested if's 'Date : 12.2.2013 Chk_sum = 0 'Clear checksum For Temp_byte = 1 To 10 Step 2 'built checkum Temp_string = Mid(rfid_string , Temp_byte , 2) '2char=1byte Temp_byte1 = Hexval(temp_string) 'ASCII to HEX conversion Chk_sum = Chk_sum Xor Temp_byte1 'Build XOR csum Next Temp_byte If Rfid_array(12) = Chk_sum Then : If Rfid_array(13) = 3 Then 'CheckumOK? Rfid_array(12) = 0 'Tidy up string If Rfid_string <> "0000000000" Then 'RFID good #if Debg > 0 : Print #1 , "RFID:" ; Rfid_string : #endif If Alarm = 0 Then : If Status = 0 Then 'And no alarm Status = 1 'Inflate seal Rfid = Rfid_string 'And return it End If : End If End If End If : End If End Sub [/code:1:4681659e33] Just remove the references to Status and alarn and define the remaining variables as required. [code:1:4681659e33] '-- Variables Dim Rfid_ptr As Byte 'RFID input pointer Dim Rfid_have_buffer As Byte 'RFID data ready for decode Dim Rfid_char As Byte 'Char from RFID Dim Rfid_array(15) As Byte 'RFID checksum array Dim Rfid_string As String * 12 At Rfid_array(1) + 1 Overlay 'String RFID Nr. Dim Chk_sum As Byte 'Checksum byte Dim Rfid As String * 12 'Userspace RFID Nr [/code:1:4681659e33] Regards Ian Dobson

Viewing all articles
Browse latest Browse all 20577

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>