'********************************************************************************** ' Gallerydrive Enhanced Queue Control Unit '********************************************************************************** ' ' Bascom code from 13.1.2007 by Niklas Roy ' '********************************************************************************** ' ' This unit communicates with the wheelchairs via RC5 (IR). ' ' Please have a look in the "galleryzone proposal" pdf to find out, ' what this device does. ' ' The device code for the wheelchair is 6 (decimal) ' The device code for the Queue Contr. Unit is 19 ' According to the Philips RC5 declarations, those both device codes ' are reserved for experimental use. ' ' Connected devices are: ' ' portc.2 : piezo speaker ' portc.3 : button ' portd.2 : status led ' portb.1 : IR led (LD274) ' portd.0 : IR receiver (TSOP34836) ' ' There's also a 4-Bit parallel 4*16 LCD display conneted to the controller ' Please have a look in the code (Config Lcdpin=...) to find out, ' how this is connected. ' '********************************************************************************** $regfile = "m8def.dat" 'Atmega8-declarations $crystal = 16000000 '$baud=19200 $hwstack = 32 $swstack = 10 $framesize = 40 Ddrc.2 = 1 'piezo speaker on portc.2 Portc.2 = 0 Ddrc.3 = 0 'button on portc.3 Portc.3 = 1 Ddrd.2 = 1 ' status led on portd.2 Ddrb.1 = 1 'ir led on portb.1 Portb.1 = 0 Config Lcdpin = Pin , Db4 = Portd.3 , Db5 = Portd.4 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portd.1 , Rs = Portb.2 Config Lcd = 16 * 4 Config Rc5 = Pind.0 'receiving ir signals at port Enable Interrupts Dim Address As Byte , Command As Byte 'used for ir communication Dim Receive(5) As Integer Dim I As Word Dim J As Word Dim Timeout As Word Dim Printlcd As String * 17 Dim Error As Bit Cursor Off Noblink Cls Lcd " Gallerydrive " Locate 2 , 1 Lcd "----------------" Locate 3 , 1 Lcd " Enhanced Queue " Locate 4 , 1 Lcd "Control Unit V01" For I = 1 To 160 'startup sound Waitus 1000 Portc.2 = Not Portc.2 Next I For I = 1 To 320 Waitus 500 Portc.2 = Not Portc.2 Next I For I = 1 To 1600 Waitus 250 Portc.2 = Not Portc.2 Next I Locate 2 , 1 Lcd "*" Waitms 100 For I = 1 To 15 Locate 2 , I Lcd "-*" Waitms 150 Next I Locate 2 , 16 Lcd "-" Waitms 1500 For J = 1 To 800 Waitus 250 Portc.2 = Not Portc.2 Next J Cls Lcd "WAITING FOR CAR." Main: Getrc5(address , Command) Command = Command And &B01111111 If Address = 19 And Command = 0 Then 'received 'nul': start reading data sequence Timeout = 0 Wait_for_value1: Getrc5(address , Command) 'wait for 18,1 Portc.2 = Not Portc.2 Timeout = Timeout + 1 : If Timeout = 50 Then Goto Ir_error Command = Command And &B01111111 If Address <> 18 Or Command <> 1 Then Goto Wait_for_value1 Get_car_number: 'wait for car number Portc.2 = Not Portc.2 Timeout = Timeout + 1 : If Timeout = 50 Then Goto Ir_error Getrc5(address , Command) If Address = 19 Then Command = Command And &B01111111 Receive(2) = Command Else Goto Get_car_number End If Wait_for_value2: 'wait for 18,2 Portc.2 = Not Portc.2 Timeout = Timeout + 1 : If Timeout = 50 Then Goto Ir_error Getrc5(address , Command) Command = Command And &B01111111 If Address <> 18 Or Command <> 2 Then Goto Wait_for_value2 Get_min_battery: 'wait for minbat Portc.2 = Not Portc.2 Timeout = Timeout + 1 : If Timeout = 50 Then Goto Ir_error Getrc5(address , Command) If Address = 19 Then Command = Command And &B01111111 Receive(3) = Command Else Goto Get_min_battery End If Wait_for_value3: 'wait for 18,3 Portc.2 = Not Portc.2 Timeout = Timeout + 1 : If Timeout = 50 Then Goto Ir_error Getrc5(address , Command) Command = Command And &B01111111 If Address <> 18 Or Command <> 3 Then Goto Wait_for_value3 Get_av_battery: 'wait for actbat Portc.2 = Not Portc.2 Timeout = Timeout + 1 : If Timeout = 50 Then Goto Ir_error Getrc5(address , Command) If Address = 19 Then Command = Command And &B01111111 Receive(4) = Command Else Goto Get_av_battery End If Wait_for_value4: 'wait for 18,4 Portc.2 = Not Portc.2 Timeout = Timeout + 1 : If Timeout = 50 Then Goto Ir_error Getrc5(address , Command) Command = Command And &B01111111 If Address <> 18 Or Command <> 4 Then Goto Wait_for_value4 Cls For I = 1 To 200 'sound - for car arrives Waitus 1000 Portc.2 = Not Portc.2 Next I For I = 1 To 160 Waitus 500 Portc.2 = Not Portc.2 Next I For I = 1 To 320 Waitus 250 Portc.2 = Not Portc.2 Next I Locate 1 , 1 Printlcd = "CAR #" + Str(receive(2)) + " ARRIVED" Lcd Printlcd Locate 2 , 1 Receive(3) = Receive(3) - 1 'value for minimum battery voltage was shifted up by 1 Receive(3) = Receive(3) * 100 'value goes from 0 to 62 -- calculate percentage Receive(3) = Receive(3) / 62 Printlcd = "MIN BATTERY:" + Str(receive(3)) + "%" 'in entertainment control to avoid 'nul' Lcd Printlcd Locate 3 , 1 Receive(4) = Receive(4) - 1 'value for actual voltage was shifted up by 1 in entertainment control Receive(4) = Receive(4) * 100 'value goes from 0 to 62 -- calculate percentage Receive(4) = Receive(4) / 62 Printlcd = "ACT BATTERY:" + Str(receive(4)) + "%" 'in entertainment control to avoid 'nul' Lcd Printlcd Goto Jump_over_error Ir_error: For I = 1 To 1000 Waitus 1000 Portc.2 = Not Portc.2 Next I Cls Locate 2 , 1 Lcd "IR-RECEIVE ERROR" Jump_over_error: End If If Pinc.3 = 0 Then Locate 4 , 1 Lcd "SEND: GO & QUEUE" For I = 1 To 320 'sound - for car exit Waitus 250 Portc.2 = Not Portc.2 Next I For I = 1 To 160 Waitus 500 Portc.2 = Not Portc.2 Next I For I = 1 To 200 Waitus 1000 Portc.2 = Not Portc.2 Next I Rc5send 0 , 6 , 10 'sending "go & queue" Rc5send 0 , 6 , 10 'sending "go & queue" Rc5send 0 , 6 , 10 'sending "go & queue" Rc5send 0 , 6 , 10 'sending "go & queue" Rc5send 0 , 6 , 10 'sending "go & queue" Rc5send 0 , 6 , 10 'sending "go & queue" Ddrb.1 = 0 'switch sending diode off Waitms 2000 End If Portd.2 = Not Portd.2 'led blink Waitms 10 Goto Main