Hallo,
ich habe mir einen Bascom Code zurechtgelegt, der die LEDs, das Display und die Motoren bedient:
Code:
'=======================================
'==== 3PI goes Bascom
'==== December 2012, pinsel120866
'=======================================
$regfile = "m328pdef.dat" ' Set the chip as a Mega 328p
$crystal = 20000000 ' Clock speed 20 MHZ
'=== Generic Port Setup ===
Config Portb = Output
Config Portc = Output
Config Portd = Output
re_led Alias Portd.7 ' Green User LED
li_led Alias Portd.1 ' Red User LED
'=== LCD SETUP ===
Config Lcdpin = Pin , Db4 = Portb.1 , Db5 = Portb.4 , Db6 = Portb.5 , Db7 = Portd.7 , E = Portd.4 , Rs = Portd.2
Config Lcd = 16 * 2 ' Actually 8x2 but that is not recognized by BASCOM.
Rw Alias Portb.0 : Rw = 0 ' Set to Zero to write to the LCD
Cursor = Off
'=== PWM SETUP ===
Config Timer0 = Pwm , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
Config Timer2 = Pwm , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
'------------------------------------------------------------------------------------------------------------------------------
' Pin Configurations
' Portb.0 - LCD Function R/W
' Portb.1 - LCD Data DB4 ( Switch A )
' Portb.2 - Buzzer
' Portb.3 - Motor 2 Control Line
' Portb.4 - LCD Data DB5 ( Switch B )
' Portb.5 - LCD Data DB6 ( Switch C )
' Portb.6 -
' Portb.7 -
' Portc.0 - IR Sensor #1 ( Left )
' Portc.1 - IR Sensor #2
' Portc.2 - IR Sensor #3 ( Center )
' Portc.3 - IR Sensor #4
' Portc.4 - IR Sensor #5 ( Right )
' Portc.5 - ADC5
' Portc.6 - Motor Controller Not Standby
' Portc.7 -
' Portd.0 - RXD
' Portd.1 - TXD (RED LED)
' Portd.2 - LCD Function RS
' Portd.3 - Motor 2 Control Line
' Portd.4 - LCD Function E
' Portd.5 - Motor 1 Control Line
' Portd.6 - Motor 1 Control Line
' Portd.7 - LCD Data DB7 (GRN LED)
' ADC6 - Battery Power Indicator
' ADC7 - User Trim Pot on underside
'------------------------------------------------------------------------------------------------------------------------------
'=======================================
' Program Start Here
'=======================================
Dim X As Word ' Set up a simple variable
Cls
Lcd "START"
Locate 2 , 1
For X = 1 To 5
Lcd "*"
Wait 1
re_led = 1
li_led = 1
Next X
Cls
Lcd "Gerade"
X=60
re_led = 0
li_led = 0
Gosub Robot_forward
Waitms 1000
Cls
Lcd "Rechts"
X=100
re_led = 1
li_led = 0
Gosub Robot_right
Waitms 1000
cls
lcd "Zurück"
x=60
re_led = 0
li_led = 0
gosub ROBOT_REVERSE
waitms 1000
cls
lcd"Links"
x=100
re_led = 0
li_led = 1
gosub ROBOT_LEFT
waitms 1000
re_led = 0
li_led = 0
Cls
Lcd "Fertig"
Gosub Robot_stop
waitms 1000
'=======================================
Do ' Just waste time at the end
Loop
End 'end program
'=======================================
' Subroutines Here
'=======================================
Robot_forward:
Pwm0a = X : Pwm0b = 0 : Pwm2a = X : Pwm2b = 0
Return
Robot_stop:
Pwm0a = 0 : Pwm0b = 0 : Pwm2a = 0 : Pwm2b = 0
Return
Robot_reverse:
Pwm0a = 0 : Pwm0b = X : Pwm2a = 0 : Pwm2b = X
Return
Robot_right:
Pwm0a = 0 : Pwm0b = X : Pwm2a = X : Pwm2b = 0
Return
Robot_left:
Pwm0a = X : Pwm0b = 0 : Pwm2a = 0 : Pwm2b = X
Return
Läuft soweit ganz gut, bei den Liniensensoren komme ich nicht weiter.
Kann mich bitte jemand dabei unterstützen?
Wäre nett...
Lesezeichen