'======================================================================================= '= = '= Gallerydrive Crumb128 Entertainment Control Unit = '= = '= Code by Niklas Roy 13.1.2007 = '= = '======================================================================================= ' ' connected devices: ' 'pb7 : out - status led (on crumb128) 'pe0./.rxd0.:.in..-.serial data from rfid reader 'pe1 / txd0 : out - serial data to mp3 player 'pe2........:.in..-.busy in from mp3 player 'pe3 : out - speedconnect#3 / to drivecontrol 'pe5........:.out.-.speedconnect#2 / to drivecontrol 'pe7 : out - speedconnect#1 / to drivecontrol 'pb6........:.in..-.alert / error from drivecontrol 'pb5 / oc1a : out - ir send 'pd0 / scl : out - i²c display 'pd1./.sda..:.out.-.i²c display 'pd2./.rxd1.:.in..-.serial data from mp3 player 'pd5........:.in..-.ir receive 'pd6 : out - microphone volume up/!down 'pd7........:.out.-.microphone volume !increment 'pf0 : in - display button 0 (A) 'pf2........:.in..-.display button 1 (B) 'pf5 / adc5 : in - battery voltage 'pf7./.adc7.:.in..-.ir distance sensor ' '======================================================================================= $regfile = "m128def.dat" 'Atmega128-declarations $crystal = 14745600 $baud = 9600 'baud rate for rfid reader $baud1 = 19200 'baud rate for yampp i3 mp3-player $lib "mcsbyte.lbx" On Urxc Onrxd 'set interrupt routine for receiving rfid serial data Ddrb = &B10100000 Portb = &B10111111 Ddrd = &B11000011 Portd = &B00111000 Ddre = &B10101010 Porte = &B01010101 Ddrf = &B00000000 Portf = &B01010010 'switch on pullups for portb.0 and portb.1 '----- variables used in dspl and readvol subroutines ----- Dim Send$ As String * 64 At &H0102 'string, which will be sent to eDIP 240-7 | fill this string with up to 62 characters before calling the "dspl"-subroutine Dim Send(64) As Byte At &H0102 Overlay 'pointer of send$ Dim Sendlength As Byte 'is used in dspl subroutine Dim Receivevol(5) As Byte 'is used in "readvol"-subroutine Dim Volume As Byte 'will be returned from "readvol"-subroutine | values go from 0 to 100 Dim Sendvol As Byte 'volume value which will be sent to the mp3-player '----- variables used to toggle debug function -------------------- Dim Debugmode As Bit 'set debugmode=0 for normal mode // debugmode=1 for debug mode '----- variables used for rfid readout -------------------- Dim Rfid_in As String * 13 'variable to compose rfid-number Dim Rfid_tag As String * 12 'complete rfid-number. The number starts always with R and is followed by 5 hex numbers (11 characters altogether) Dim Rfid_tag_old As String * 12 'number of last rfid-tag Dim Byte_in As Byte 'single byte that comes from the rfid reader '----- variables used for ir communication -------------------- Dim Address As Byte , Command As Byte 'RC5 ir variables Dim Minbat As Byte 'minimum battery voltage Minbat = 255 Dim Actbat As Byte 'actual battery voltage Dim Adcbat As Integer Dim Actbat_debug As Word Dim Minbat_debug As Word '----- variable used for store distance to next car ------------ Dim Adcdist As Word Dim Distbyte As Byte '----- variables used in general -------------------- Dim Cycle As Word '"cycle" counts program loop cycles Dim Condition As Integer 'stores the current entertainment condition Dim Prevcondition As Integer 'stores entertainment condition of last program cycle Condition = -1 'set default condition Prevcondition = 255 Dim I As Byte 'general purpose counter var Dim J As Word Dim K As Integer Enable Urxc 'switch on urxc for receiving data from rfid reader Enable Interrupts 'allow global interrupts Config Sda = Portd.1 Config Scl = Portd.0 Config I2cdelay = 10 Config Rc5 = Pind.5 Config Adc = Single , Prescaler = Auto , Reference = Internal Start Adc '======================================================================================= '= = '= = '= STARTUP CODE - PERFORMED ONCE AT BEGINNING = '= = '= = '======================================================================================= Waitms 100 Send$ = "{027}TA" Gosub Dspl Waitms 50 Send$ = "#MN0" 'Macro#0: gallerydrive logoanim Gosub Dspl Waitms 1500 Send$ = "{027}AE{002}" 'define button style Gosub Dspl Waitms 50 Send$ = "{027}AI1" 'invert button when pushed Gosub Dspl Waitms 50 Send$ = "{027}AT{050}{097}{190}{114}{001}{002}DEBUG MODE?" 'define "debug?" button Gosub Dspl Waitms 50 Debugmode = 0 For J = 1 To 3500 Waitms 1 If Pinf.0 = 1 Then 'check if "debug?" button was pushed Debugmode = 1 Exit For End If Next J Send$ = "{027}AV{055}{100}" 'delete touch button Gosub Dspl Waitms 50 Send$ = "{027}MN{001}" 'Macro#1: gallerydrive screen Gosub Dspl Waitms 50 If Debugmode = 1 Then Send$ = "#ZF0" Gosub Dspl Waitms 50 Send$ = "{027}ZL{010}{110}Running in ~DEBUG MODE~" Gosub Dspl Waitms 50 End If '======================================================================================= '= = '= = '= END STARTUP CODE = '= = '= = '======================================================================================= '*************************************************************************************** '* * '* * '* START PROGLOOP * '* * '* * '*************************************************************************************** Do Cycle = Cycle + 1 If Cycle = 10000 Then '*************** Code is only performed every 1000 program cycles ********************** '* * '* * Cycle = 0 Portb.7 = Not Portb.7 'switching status led Adcbat = Getadc(5) 'read battery voltage (1o-bit adc -> value ranges theoretically from 0-1023) Adcbat = Adcbat - 624 'voltage value has to be between 0 (empty battery) Adcbat = Adcbat / 2 'and 63 (full battery) 'use your own code to calculate/adjust these values If Adcbat > 62 Then Adcbat = 62 'values have to be clipped, that they can be sent via IR If Adcbat < 0 Then Adcbat = 0 Actbat = Adcbat If Actbat < Minbat Then Minbat = Actbat Gosub Readvol 'reads volume bargraph at display - returns volume (0-100) Sendvol = Volume / 9 Sendvol = Sendvol + 173 Open "COM2:" For Binary As #1 Printbin #1 , Sendvol 'send volume to mp3-player (accepted values rqange from 128-184) Printbin #1 , 192 'balance left off Printbin #1 , 208 'balance right off Close #1 If Debugmode = 1 And Pinb.6 = 1 Then 'display alarm in debugmode Send$ = "#ZF0" Gosub Dspl Waitms 50 Send$ = "{027}ZL{010}{110}Out of line / Error " Gosub Dspl Waitms 50 End If '* * '* * '*************************************************************************************** End If '****************************** Check RFID reader ************************************** '* * '* * If Rfid_tag <> Rfid_tag_old Then 'if car rolls over a new RFID-tag -> set according condition Disable Urxc 'new rfid-tag received? (there have to be at least TWO different rfid-tags in the course!) Rfid_tag_old = Rfid_tag Enable Urxc Select Case Rfid_tag_old Case "R8A2224ADAD" : Condition = 0 'sets car into "enter" condition Case "R022224ADB5" : Condition = 1 'zone 1 Case "R0A33242D30" : Condition = 2 'zone 2 Case "R033304AD67" : Condition = 10 'sets car into "exit and queue" condition Case "R0233242DB8" : Gosub Speed100 'speed=100% Case "RA0C80680CE" : Gosub Speed43 'speed=43% Case "R21D0242043" : Gosub Speed100 'speed=100% Case "R8A32062DEF" : Gosub Speed43 'speed=43% Case "R0222042D15" : Gosub Speed71 'speed=71% Case "R0B3204AD8C" : Gosub Speed43 'speed=43% Case Else : Goto Rfid_error 'rfid_error - code can be found in 'subroutines' End Select Error_return: End If '* * '* * '*************************************************************************************** '*********************** Branch to different condition codes *************************** '* * '* * Select Case Condition Case -1 : Gosub Default_go_slow Case 0 : Gosub Enter_car Case 1 : Gosub Zone1 Case 2 : Gosub Zone2 Case 4 : Gosub Drive_1 Case 10 : Gosub Exit_and_queue End Select '* * '* * '*************************************************************************************** Loop '*************************************************************************************** '* * '* * '* END PROGLOOP * '* * '* * '*************************************************************************************** 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'X X 'X X 'X START CONDITIONS X 'X X 'X X 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX '----------------------- CONDITION ( -1 ) : DEFAULT / GO SLOW --------------------------- 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Default_go_slow: If Prevcondition <> Condition Then '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'the following code will only be performed one time at the beginning of this condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - If Debugmode = 1 Then Send$ = "#ZF0" Gosub Dspl Send$ = "{027}ZL{010}{110}DEFAULT: SPEED=29% " Gosub Dspl End If Porte.7 = 0 : Porte.5 = 1 : Porte.3 = 0 'speed=29% End If Prevcondition = Condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ' the following code will be performed continously during this condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Return 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX '---------------------- CONDITION ( 0 ) : START / ENTER CAR ---------------------------- 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Enter_car: If Prevcondition <> Condition Then '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'the following code will only be performed one time at the beginning of this condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Porte.7 = 0 : Porte.5 = 0 : Porte.3 = 0 'speed=0% Wait 1 Send$ = "{027}MN{001}" 'Macro#1: gallerydrive screen Gosub Dspl Waitms 300 Send$ = "{027}ZF{001}" 'select small pixel font Gosub Dspl Waitms 100 Send$ = "{027}ZL{020}{025}BY PUSHING THE ~START~ BUTTON, I DECLARE," Gosub Dspl Waitms 100 Send$ = "{027}ZL{020}{032}THAT I'VE READ AND UNDERSTOOD THE TERMS" Gosub Dspl Waitms 100 Send$ = "{027}ZL{020}{041}AND CONDITIONS UNDER WHICH I DRIVE THIS" Gosub Dspl Waitms 100 Send$ = "{027}ZL{020}{049}RIDE. I KNOW, THAT I WILL DRIVE ON MY OWN" Gosub Dspl Waitms 100 Send$ = "{027}ZL{020}{057}RISK. I WILL BEHAVE GENTLE DURING THE RIDE" Gosub Dspl Waitms 100 Send$ = "{027}ZL{020}{065}AND OF COURSE, I WILL FOLLOW THE INSTRUC-" Gosub Dspl Waitms 100 Send$ = "{027}ZL{020}{073}TIONS OF THE SERVICE STAFF." Gosub Dspl Waitms 500 Send$ = "{027}MN{004}" 'displays start button (out 1&2=high, when pushed) Gosub Dspl Waitms 100 If Debugmode = 1 Then Send$ = "#ZF0" Gosub Dspl Send$ = "{027}ZL{010}{110}WAIT FOR START... " Gosub Dspl End If Open "COM2:" For Binary As #1 Printbin #1 , 3 'play track on mp3-player Close #1 End If Prevcondition = Condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ' the following code will be performed continously during this condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - If Pinf.0 = 1 Then 'waiting for "start" button to be pushed Send$ = "{027}MN{003}" 'sets button outputs to low Gosub Dspl Send$ = "{027}MN{002}" 'clears display inside gallerydrive frame Gosub Dspl Condition = 4 'set car into "drive_1" condition End If Return 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX '-------------------------- CONDITION ( 1 ) : zone1 --------------------------------- 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Zone1: If Prevcondition <> Condition Then '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'the following code will only be performed one time at the beginning of this condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Porte.7 = 0 : Porte.5 = 0 : Porte.3 = 0 'speed=0% If Debugmode = 1 Then Send$ = "#ZF0" Gosub Dspl Send$ = "{027}ZL{010}{110}WAIT AT ZONE 1... " Gosub Dspl End If Wait4go_zone1: 'open ir receiver and wait for "go" signal Getrc5(address , Command) Command = Command And &B01111111 If Address <> 6 Or Command <> 1 Then Goto Wait4go_zone1 If Debugmode = 1 Then Send$ = "#ZF0" Gosub Dspl Send$ = "{027}ZL{010}{110}ZONE 1 CLEAR... " Gosub Dspl End If Porte.7 = 1 : Porte.5 = 1 : Porte.3 = 0 'go signal received: speed=43% End If Prevcondition = Condition Return 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX '-------------------------- CONDITION ( 2 ) : zone2 --------------------------------- 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Zone2: If Prevcondition <> Condition Then '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'the following code will only be performed one time at the beginning of this condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Porte.7 = 0 : Porte.5 = 0 : Porte.3 = 0 'speed=0% If Debugmode = 1 Then Send$ = "#ZF0" Gosub Dspl Send$ = "{027}ZL{010}{110}WAIT AT ZONE 2... " Gosub Dspl End If Wait4go_zone2: 'open ir receiver and wait for "go" signal Getrc5(address , Command) Command = Command And &B01111111 If Address <> 6 Or Command <> 2 Then Goto Wait4go_zone2 If Debugmode = 1 Then Send$ = "#ZF0" Gosub Dspl Send$ = "{027}ZL{010}{110}ZONE 2 CLEAR... " Gosub Dspl End If Porte.7 = 1 : Porte.5 = 1 : Porte.3 = 1 'speed=100% End If Prevcondition = Condition Return 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX '-------------------------- CONDITION ( 4 ) : DRIVE_1 --------------------------------- 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Drive_1: If Prevcondition <> Condition Then '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'the following code will only be performed one time at the beginning of this condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Open "COM2:" For Binary As #1 Printbin #1 , 4 'play track on mp3-player Close #1 Waitms 200 Porte.7 = 1 : Porte.5 = 1 : Porte.3 = 0 'speed=43% Waitms 200 If Debugmode = 1 Then Send$ = "#ZF0" Gosub Dspl Send$ = "{027}ZL{010}{110}CONDITION:4 / DRIVE_1" Gosub Dspl End If End If Prevcondition = Condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ' the following code will be performed continously during this condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Return 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX '-------------------------- CONDITION ( 10 ) : EXIT & QUEUE ----------------------------- 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Exit_and_queue: If Prevcondition <> Condition Then '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'the following code will only be performed one time at the beginning of this condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Open "COM2:" For Binary As #1 Print #1 , Chr(2); 'play track on mp3-player Close #1 Send$ = "#MN0" 'Macro#0: gallerydrive logoanim Gosub Dspl Waitms 50 If Debugmode = 1 Then Send$ = "#ZF0" Gosub Dspl Send$ = "{027}ZL{010}{110}RFID#1: Exit Point " Gosub Dspl End If Porte.7 = 0 : Porte.5 = 0 : Porte.3 = 0 'speed=0% Actbat = Actbat + 1 Minbat = Minbat + 1 '--------------- IR communication with Enhanced Queue Control Unit ------------------ Wait 1 Rc5send 0 , 19 , 0 'sending sync 'nul' Rc5send 0 , 19 , 0 'sending sync 'nul' Rc5send 0 , 19 , 0 'sending sync 'nul' Rc5send 0 , 19 , 0 'sending sync 'nul' Rc5send 0 , 18 , 1 'coming next: value#1 Rc5send 0 , 18 , 1 Rc5send 0 , 18 , 1 Rc5send 0 , 18 , 1 Rc5send 0 , 19 , 1 'sending car number (1) Rc5send 0 , 19 , 1 'sending car number (1) Rc5send 0 , 19 , 1 'sending car number (1) Rc5send 0 , 19 , 1 'sending car number (1) Rc5send 0 , 18 , 2 'coming next: value#2 Rc5send 0 , 18 , 2 Rc5send 0 , 18 , 2 Rc5send 0 , 18 , 2 Rc5send 0 , 19 , Minbat 'sending minimum battery voltage during last round Rc5send 0 , 19 , Minbat 'sending minimum battery voltage during last round Rc5send 0 , 19 , Minbat 'sending minimum battery voltage during last round Rc5send 0 , 19 , Minbat 'sending minimum battery voltage during last round Rc5send 0 , 18 , 3 'coming next: value#3 Rc5send 0 , 18 , 3 Rc5send 0 , 18 , 3 Rc5send 0 , 18 , 3 Rc5send 0 , 19 , Actbat 'sending actual battery voltage Rc5send 0 , 19 , Actbat 'sending actual battery voltage Rc5send 0 , 19 , Actbat 'sending actual battery voltage Rc5send 0 , 19 , Actbat 'sending actual battery voltage Rc5send 0 , 18 , 4 'end signal Rc5send 0 , 18 , 4 Rc5send 0 , 18 , 4 Rc5send 0 , 18 , 4 If Debugmode = 1 Then Minbat_debug = Minbat - 1 'same calculation as performed in the queue control unit Minbat_debug = Minbat_debug * 100 'to get battery charge percentage Minbat_debug = Minbat_debug / 62 Actbat_debug = Actbat - 1 Actbat_debug = Actbat_debug * 100 Actbat_debug = Actbat_debug / 62 Minbat = Minbat_debug Actbat = Actbat_debug Send$ = "#ZF0" Gosub Dspl Send$ = "{027}ZL{010}{110}BATTERY MIN:" + Str(minbat) + "% ACT:" + Str(actbat) + "% " Gosub Dspl End If Ddrb.5 = 0 'switching off IR led Minbat = 255 'reseting minbat value Wait4queue: 'open ir receiver and wait for "go & queue" signal Getrc5(address , Command) Command = Command And &B01111111 If Address <> 6 Or Command <> 10 Then Goto Wait4queue 'device address of wheelchair= 6 / command for "go & queue" = 10 End If Prevcondition = Condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ' the following code will be performed continously during this condition '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '----------------------------------- queueing ------------------------------------ Adcdist = Getadc(7) 'read out GP2D12 IR distance sensor If Debugmode = 1 Then Distbyte = Adcdist Send$ = "{027}ZL{010}{110}QUEUE DIST:" + Str(distbyte) + " " Gosub Dspl End If If Adcdist < 80 Then Porte.7 = 0 : Porte.5 = 1 : Porte.3 = 0 'speed=29% Else Porte.7 = 0 : Porte.5 = 0 : Porte.3 = 0 'speed=0% End If Return 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'X X 'X X 'X END CONDITIONS X 'X X 'X X 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX '~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ '~ ~ '~ ~ '~ SUBROUTINES & INTERRUPTS ~ '~ ~ '~ ~ '~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ '~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ' rfid error '~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 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~ ~ ~ ~ ~ ~ ~ ~ ~ ' RFID scanner interrupt '~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Onrxd: Byte_in = Udr 'read byte from rfid reader and copy it into byte_in If Byte_in = 82 Then Rfid_in = "" 'rfid tag starts always with "R" (=ascii 82). So if an R arrived, the old string can be removed - a new string starts Rfid_in = Rfid_in + Chr(byte_in) 'this composes the whole rfid-tag-number by pasting the new received byte to the end of the string If Len(rfid_in) = 11 Then 'if the string is complete ("R"+xxxxxxxxxx) - copy this string into rfid_tag Rfid_tag = Rfid_in Rfid_in = "" End If Return '~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ' Speed routines '~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Speed0: Porte.7 = 0 : Porte.5 = 0 : Porte.3 = 0 'speed=0% Return Speed14: Porte.7 = 1 : Porte.5 = 0 : Porte.3 = 0 'speed=14% Return Speed29: Porte.7 = 0 : Porte.5 = 1 : Porte.3 = 0 'speed=29% Return Speed43: Porte.7 = 1 : Porte.5 = 1 : Porte.3 = 0 'speed=43% Return Speed57: Porte.7 = 0 : Porte.5 = 0 : Porte.3 = 1 'speed=57% Return Speed71: Porte.7 = 1 : Porte.5 = 0 : Porte.3 = 1 'speed=71% Return Speed86: Porte.7 = 0 : Porte.5 = 1 : Porte.3 = 1 'speed=86% Return Speed100: Porte.7 = 1 : Porte.5 = 1 : Porte.3 = 1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