'********************************************************************************** ' Gallerydrive - Zone Control Unit '********************************************************************************** ' ' pd0:............green lamp ' pd1:............red lamp ' pd2:............Status LED ' pb1(oc1a):......IR transmitting diode LD274 ' pc5(adc5):......laser barrier input ' pc4(adc4):......from next zone / last laser barrier ' pc3:............to previous zone ' ' pc0:............"test"-switch ' pc1(adc1):......poti adjust laser ' pc2(adc2):......poti adjust next zone / laser '********************************************************************************** $regfile = "m8def.dat" $crystal = 16000000 Ddrd = &B00000111 'relais at pd1 - status led at pd2 Ddrb = &B00000010 'IR diode at pb1 Ddrc = &B00001000 'signal out to prev. zone at pc3 Portd = &B11111111 Portb = &B11111101 Portc = &B11000111 Config Adc = Single , Prescaler = Auto Start Adc Dim I As Word Dim Test As Bit Dim Prev_test As Bit Dim Laser_adjust As Word 'potivalue laser adjust Dim Next_adjust As Word 'potivalue next adjust Dim Laser_in As Word 'control voltage coming from laser Dim Next_in As Word 'control voltage coming from next zone Dim Zone_occupied As Byte Dim Signal As Byte Dim Enter_zone As Bit Dim Exit_zone As Bit Dim Prev_enter_zone As Bit Dim Prev_exit_zone As Bit '------------------------------------------------------------------------------------------------------ '------------------------------------------------------------------------------------------------------ '------------------------------------------------------------------------------------------------------ Signal = 2 ' <-Fill in correct number of Signal here! '------------------------------------------------------------------------------------------------------ '------------------------------------------------------------------------------------------------------ '------------------------------------------------------------------------------------------------------ Portd.2 = 1 'turn on status led Readeeprom Zone_occupied , 0 If Zone_occupied = 1 Then Portd.1 = 1 : Portd.0 = 0 Else Portd.1 = 0 : Portd.0 = 1 End If Enter_zone = 0 Prev_enter_zone = 0 Exit_zone = 0 Prev_exit_zone = 0 Test = 0 Prev_test = 0 Do I = I + 1 If I = 400 Then I = 0 Prev_test = Test If Pinc.0 = 0 Then Test = 1 Else Test = 0 'read test switch If Test = 0 And Prev_test = 1 Then 'switch traffic lights if testmode was currently switched off Readeeprom Zone_occupied , 0 If Zone_occupied = 1 Then Portd.1 = 1 : Portd.0 = 0 Else Portd.1 = 0 : Portd.0 = 1 End If End If If Test = 1 Then If I = 0 Then Portd.2 = Not Portd.2 'status led blinks during test mode Portc.3 = Not Portc.3 'signal output to previous zone switches End If Else Portd.2 = 1 End If Laser_adjust = Getadc(1) Next_adjust = Getadc(2) Laser_in = Getadc(5) Next_in = Getadc(4) If Test = 1 Then 'testmode: If Laser_in > Laser_adjust Then Portd.1 = 1 Else Portd.1 = 0 'retroreflecting mat. detected - red light on If Next_in > Next_adjust Then Portd.0 = 1 Else Portd.0 = 0 'retroreflecting mat. detected - green light on Else 'normal mode Prev_enter_zone = Enter_zone Prev_exit_zone = Exit_zone If Laser_in > Laser_adjust Then Enter_zone = 1 Else Enter_zone = 0 'compare laser barriers with adjustet values If Next_in > Next_adjust Then Exit_zone = 1 Else Exit_zone = 0 If Enter_zone = 0 And Prev_enter_zone = 1 Then 'car entered zone Zone_occupied = 1 Writeeeprom Zone_occupied , 0 Portd.1 = 1 : Portd.0 = 0 'switch traffic light to red Portc.3 = 1 : Wait 1 : Portc.3 = 0 'send flange to previous zone End If If Exit_zone = 0 And Prev_exit_zone = 1 Then 'car left zone Zone_occupied = 0 Writeeeprom Zone_occupied , 0 Portd.1 = 0 : Portd.0 = 1 'switch traffic light to green End If If Zone_occupied = 0 Then Rc5send 0 , 6 , Signal 'send go signal End If End If Loop End