'-------------------------------------------------------------- ' CIRC_bot_shell.bas ' Shell Program for CIRC_bot by Paul Pawelski '-------------------------------------------------------------- $regfile = "M48def.dat" 'identify the chip $crystal = 1000000 'the speed is 1 MHz 'NOTE: The previous line does not set the crystal speed! ' It only tells the compiler what the speed is suppose to be. ' to set a different speed, you will need to goto the lock and ' fuse bits settings tab in your programmer and set the correct ' fuses there. ' ' Please go to the forums at www.wrighthobbies.net for updates and ' variations on this program. '-------------------------------------------------------------- 'constants Const Neutral = 0 Const Lslow = 75 Const Rslow = 75 Const Lmedium = 190 Const Rmedium = 190 Const Lfast = 255 Const Rfast = 255 '-------------------------------------------------------------- 'aliases Speedleft Alias Pwm1a Speedright Alias Pwm1b '-------------------------------------------------------------- 'variables Dim X As Bit 'while loop indicator Dim Lsensor As Byte Dim Rsensor As Byte Dim C As Byte ' case indicator Dim Runblinddemo As Bit ' sensor / blind demo flag '-------------------------------------------------------------- 'Demo Configuration '******In Next Line RunBlindDemo =0 for sensor demo, =1 for blind demo *** Runblinddemo = 1 ' By changing the above line & recompiling, you can change which demo is run '-------------------------------------------------------------- 'config PWM Config Timer1 = Pwm , Pwm = 8 , Prescale = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down '-------------------------------------------------------------- 'configure ports Config Portb = Output Config Portd = Output '-------------------------------------------------------------- 'configure ADC Config Adc = Single , Prescaler = Auto 'Now give power to the chip Start Adc '-------------------------------------------------------------- 'start PWM Enable Interrupts Enable Timer1 Start Timer1 '-------------------------------------------------------------- 'MAIN CODE Set X ' Set X same as saying X=1 C = 0 While X = 1 ' the loop that never ends If Runblinddemo = 1 Then C = C + 1 'indexer for blind demo Else '--------------Start of sensor & decision opperation--------- Lsensor = Getadc(5) 'read left sensor Rsensor = Getadc(4) 'read right sensor Rsensor = Rsensor + 10 'adding half the tuning buffer If Lsensor > Rsensor Then 'decide on motor case C = 2 'turn right Else Rsensor = Rsensor - 20 'removing all the tuning buffer If Lsensor < Rsensor Then C = 1 'turn left ' Else 'uncommenting these two lines will cause ' C = 3 'bot to go forward if sensors are close End If End If End If '--------------End of sensor & decision opperation----------- '--------------Start of a motor switch opperation------------ Speedleft = Neutral 'always kill pwm first Speedright = Neutral Waitms 1 'wait one milisecond for shutdown Reset Portb.0 'and open all switches Reset Portd.6 Reset Portd.5 Reset Portd.7 Select Case C Case 1 'turn in place left Set Portd.6 'then turn on the necessary switches Set Portd.7 Speedleft = Lmedium 'and reactivate the pwm Speedright = Rmedium Case 2 'turn in place right Set Portb.0 'then turn on the necessary switches Set Portd.5 Speedleft = Lmedium 'and reactivate the pwm Speedright = Rmedium Case 3 'forward Set Portd.6 'then turn on the necessary switches Set Portd.5 Speedleft = Lmedium 'and reactivate the pwm Speedright = Rmedium Case 4 'reverse Set Portb.0 'then turn on the necessary switches Set Portd.7 Speedleft = Lmedium 'and reactivate the pwm Speedright = Rmedium C = 0 'needed for blind demo ( Case 5 'forward slow right Set Portd.6 'turn on the necessary switches Set Portd.5 Speedleft = Lslow 'and reactivate the pwm Speedright = Rmedium Case 6 'forward, slow left Set Portd.6 'turn on the necessary switches Set Portd.5 Speedleft = Lmedium 'and reactivate the pwm Speedright = Rslow End Select '--------------End of a motor switch opperation--------------- If Runblinddemo = 1 Then Wait 2 Else Waitms 1 'give sensor PWN a chance to operate End If Wend End '--------------------------------------------------------------