Hallo
Bascom ist zwar etwas "sperriger" als C, aber grundsätzlich nicht schlechter ;) Mein "Grundgerüst" beherrscht nun die Tasten, die Leds, Motor-PWM, Liniensensoren und Odometry:
Code:
' nibobee mit Bascom 11.12.09 mic
$regfile = "m16def.dat"
$crystal = 15000000
$hwstack = 32
$swstack = 8
$framesize = 24
$baud = 19200
Led0 Alias Portb.0
Led1 Alias Portb.1
Led2 Alias Portb.2
Led3 Alias Portb.3
Lineled Alias Portb.4
Config Led0 = Output ' LEDs 0-3
Config Led1 = Output
Config Led2 = Output
Config Led3 = Output
Config Lineled = Output ' Lineled
Config Portc.4 = Input ' keys
Config Portc.5 = Input
Config Portc.6 = Input
Config Portc.7 = Input
Config Portd.2 = Input ' odo_l int0
Config Portd.3 = Input ' odo_r int1
Config Portd.4 = Output ' pmw_r
Config Portd.5 = Output ' pwm_l
Config Portd.6 = Output ' dir_l
Config Portd.7 = Output ' dir_r
'Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 1
Config Adc = Single , Prescaler = 64 , Reference = Avcc ' 235 kHz
Config Int0 = Change
Config Int1 = Change
Declare Sub Motorpwm(byval Pwm_l As Byte , Byval Pwm_r As Byte)
Declare Sub Motordir(byval Dir_l As Byte , Byval Dir_r As Byte)
Declare Sub Setleds(byval Leds As Byte)
Declare Function Getkeys() As Byte
Dim B As Byte , W As Word
Dim Odo_count_l As Word , Odo_count_r As Word
Start Adc
On Int0 Isr_int0
On Int1 Isr_int1
Enable Int0
Enable Int1
Enable Interrupts
Portc = &B11110000 'Tasten-PullUp Bit 4-7 einschalten
Call Setleds(0)
Lineled = 0 ' Lineled on
Waitms 10
Print
Print "nibobee in Bascom 11.12.09 mic"
Print
Print "Liniensensoren (l-m-r): " ; Getadc(5) ; "-" ; Getadc(6) ; "-" ; Getadc(7)
Lineled = 1 ' Lineled off
While Getkeys() = 0 'warten auf Taste (mit aktiver Odometry;)
Led1 = Not Pinb.1
Led2 = Not Pinb.1
Print Odo_count_l ; " - " ; Odo_count_r
Waitms 200
Wend
Call Setleds(0)
Wait 2
Do
Disable Interrupts
Odo_count_l = 0
Odo_count_r = 0
Enable Interrupts
Call Motordir(1 , 1)
Call Motorpwm(100 , 100)
Call Setleds(2)
Do
W = Odo_count_l + Odo_count_r
Loop Until W > 300
Call Motorpwm(0 , 0)
Wait 1
Disable Interrupts
Odo_count_l = 0
Odo_count_r = 0
Enable Interrupts
Call Motordir(1 , 0)
Call Motorpwm(100 , 100)
Call Setleds(4)
Do
W = Odo_count_l + Odo_count_r
Loop Until W > 115 'ca. 180°
Call Motorpwm(0 , 0)
Wait 1
Loop
End
Sub Motorpwm(byval Pwm_l As Byte , Byval Pwm_r As Byte)
Pwm1a = Pwm_l * 4
Pwm1b = Pwm_r * 4
End Sub
Sub Motordir(byval Dir_l As Byte , Byval Dir_r As Byte)
If Dir_l = 0 Then Portd.6 = 0 Else Portd.6 = 1
If Dir_r = 0 Then Portd.7 = 1 Else Portd.7 = 0
End Sub
Sub Setleds(byval Leds As Byte)
Led0 = Leds.0
Led1 = Leds.1
Led2 = Leds.2
Led3 = Leds.3
End Sub
Function Getkeys() As Byte
Getkeys = Pinc / 16 ' Pins einlesen und nach rechts schieben
Getkeys = Getkeys Xor 255 ' invertieren
Getkeys = Getkeys And 15 ' Bit4-7 ausblenden
End Function
Isr_int0:
Incr Odo_count_l
Led0 = Pind.2
Return
Isr_int1:
Incr Odo_count_r
Led3 = Pind.3
Return
In Motordir() hatte sich ein Bug eingeschlichen den ich in dieser Version erschlagen habe:)
Gruß
mic
Lesezeichen