$regfile = "M328Pdef.dat" $crystal = 16000000 'CONFIGURATIE Config Portd.3 = Output 'relais Config Portd.4 = Output 'dir L Config Portd.7 = Output 'dir R Config Portb.6 = Output 'maaimotor Config Portd.5 = Output 'pwm L Config Portd.6 = Output 'pwm R Config Sda = Portc.4 'sda Config Scl = Portc.5 'scl Config I2cdelay = 10 Const Pcf8574write = &H70 Const Pcf8574read = &H71 Const Pcf8574ledw = &H72 Const Pcf8574ledr = &H73 Config Portd.2 = Input 'int van remote control Config Int0 = Falling Dim Pcf8574port As Integer Dim Slow As Integer Dim Fast As Integer Dim Adc_x As Integer Dim Ir_links As Bit Dim Ir_rechts As Bit Dim Ir_achter As Bit Dim Bump As Bit Dim Ledmod As Integer Dim Remote As Byte 'SETTIGS Ir_links = 0 Ir_rechts = 0 Ir_achter = 0 Bump = 0 Slow = 380 Fast = 512 'Config Lcdpin = Pin , Rs = Portb.5 , E = Portb.4 , Db4 = Portb.3 , Db5 = Portc.7 , Db6 = Portb.1 , Db7 = Portb.0 'Config Lcdbus = 4 'Config Lcd = 20 * 4 'Cursor Off Config Timer1 = Pwm , Pwm = 10 , Prescale = 1 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up Portd.3 = 1 'relais Config Adc = Single , Prescaler = Auto Start Adc '( 'MAIN AUTOMATISCH Do Gosub _display_routine Gosub _links_snel_vooruit Gosub _rechts_snel_vooruit Gosub _analoge_ingangen_opvragen If Ir_links = 1 Then Gosub _links_stop Gosub _rechts_stop Waitms 300 Gosub _links_traag_achteruit Gosub _rechts_traag_achteruit Waitms 1000 Gosub _links_stop Gosub _rechts_stop Waitms 1000 Gosub _links_traag_vooruit Gosub _rechts_traag_achteruit Waitms 500 'draaitijd Gosub _links_snel_vooruit Gosub _rechts_snel_vooruit Elseif Ir_rechts = 1 Then Gosub _links_stop Gosub _rechts_stop Waitms 1000 Gosub _links_traag_achteruit Gosub _rechts_traag_achteruit Waitms 1000 Gosub _links_stop Gosub _rechts_stop Waitms 1000 Gosub _rechts_traag_vooruit Gosub _links_traag_achteruit Waitms 500 'draaitijd Gosub _links_snel_vooruit Gosub _rechts_snel_vooruit Elseif Bump = 1 Then Gosub _links_stop Gosub _rechts_stop Waitms 1000 Gosub _links_traag_achteruit Gosub _rechts_traag_achteruit Waitms 1000 Gosub _links_traag_vooruit Gosub _rechts_traag_achteruit Waitms 500 'draaitijd Gosub _links_stop Gosub _rechts_stop W4aitms 1000 Gosub _links_snel_vooruit Gosub _rechts_snel_vooruit Elseif Ir_achter = 1 Then Gosub _links_stop Gosub _rechts_stop Waitms 1000 Gosub _links_traag_vooruit Gosub _rechts_traag_vooruit Waitms 1000 Gosub _links_traag_vooruit Gosub _rechts_traag_achteruit Waitms 250 'draaitijd Gosub _links_stop Gosub _rechts_stop Waitms 1000 Gosub _links_snel_vooruit Gosub _rechts_snel_vooruit End If Loop ') '******************************************* Remote = Pcf8574port Lcd Remote 'main manueel Do Gosub Remote_control Remote = Pcf8574port If Remote = 0 Then Gosub _links_stop Gosub _rechts_stop Elseif Remote = 32 Then Gosub _rechts_snel_vooruit Gosub _links_snel_vooruit Elseif Remote = 16 Then Gosub _links_snel_achteruit Gosub _rechts_snel_achteruit Elseif Remote = 64 Then Gosub _links_traag_achteruit Gosub _rechts_traag_vooruit Elseif Remote = 128 Then Gosub _links_traag_vooruit Gosub _rechts_traag_achteruit Elseif Remote = 1 Then Gosub _links_stop Gosub _rechts_traag_vooruit Elseif Remote = 2 Then Gosub _links_traag_vooruit Gosub _rechts_stop Elseif Remote = 4 Then Gosub _links_stop Gosub _rechts_traag_achteruit Elseif Remote = 8 Then Gosub _links_traag_achteruit Gosub _rechts_stop End If Loop '( _analoge_ingangen_opvragen: Adc_x = Getadc(0) If Adc_x > 500 Then Ir_links = 1 Else Ir_links = 0 End If Adc_x = Getadc(1) If Adc_x > 500 Then Ir_rechts = 1 Else Ir_rechts = 0 End If Adc_x = Getadc(2) If Adc_x < 200 Then Ir_achter = 1 Else Ir_achter = 0 End If Adc_x = Getadc(5) '7,2V Locate 2 , 1 Lcd Adc_x ; "..........." If Adc_x < 250 Then Led1 = 1 Else Led1 = 0 Gosub Led_module End If Adc_x = Getadc(6) If Adc_x > 800 Then Bump = 1 Else Bump = 0 End If Adc_x = Getadc(7) '5Vdc Locate 2 , 15 Lcd Adc_x ; "..." If Adc_x < 250 Then Led2 = 2 Else Led2 = 0 Gosub Led_module End If Return ') '*************************************** _links_traag_vooruit: Portd.4 = 0 'dir L fwdL Pwm0b = Slow 'speed L Return _links_traag_achteruit: Portd.4 = 1 'Dir L Rev Pwm0b = Slow 'speed Return _links_snel_vooruit: Portd.4 = 0 'dir L fwd Pwm0b = Fast 'speed L Return _links_snel_achteruit: Portd.4 = 1 'dir L rev Pwm0b = Fast 'speed L Return _links_stop: Return _rechts_traag_vooruit: Portd.7 = 0 'dir R fwd Pwm0a = Slow 'speed R Return _rechts_traag_achteruit: Portd.7 = 1 'dir R rev Pwm0a = Slow 'speed R Return _rechts_snel_vooruit: Portd.7 = 0 'dir R fwd Pwm0a = Fast 'speed R Return _rechts_snel_achteruit: Portd.7 = 1 'dir R rev Pwm0a = Fast 'speed R Return _rechts_stop: Pwm0a = 0 'speed R Return Remote_control: On Int0 Pcfint Gosub Ledmodule Enable Interrupts Enable Int0 'Make all Pcf8574 pins high = input I2cstart I2cwbyte Pcf8574write '&H70 I2cwbyte 255 I2cstop 'pcf8574 Interrupt Routine Pcfint: 'read the input pins I2cstart I2cwbyte Pcf8574read '&H71 I2crbyte Pcf8574port , Nack I2cstop Return Ledmodule: I2cstart I2cwbyte Pcf8574ledw '&H72 I2cwbyte Pcf8574port I2cstop Return End 'end program