'AD-Wandler 1,1 V
$regfile = "attiny13.dat"
$crystal = 1200000
Dim D As Byte
Dim Ad As Word
Dim K As Byte
Config Adc = Single , Prescaler = Auto ,
Reference = Internal
Start Adc
Config Timer0 = Pwm , Prescale = 1 ,
Compare A Pwm = Clear Down
Open "comb.1:9600,8,n,1,INVERTED" For Output As #1
Open "comb.2:9600,8,n,1,INVERTED" For Input As #2
Ddrb.0 = 1
Do
Get #2 , K
If K = 56 Then
Ad = Getadc(2)
D = High(ad)
Put #1 , D
D = Low(ad)
Put #1 , D
End If
If K = 57 Then
Ad = Getadc(3)
D = High(ad)
Put #1 , D
D = Low(ad)
Put #1 , D
End If
If K = 64 Then
Get #2 , D
Pwm0a = D
End If
Loop
End
'Vier Ports
$regfile = "attiny13.dat"
$crystal = 1200000
Dim D As Byte
Dim K As Byte
Open "comb.2:9600,8,n,1,INVERTED" For Input As #2
Ddrb.0 = 1
Ddrb.1 = 1
Ddrb.3 = 1
Ddrb.4 = 1
Do
Get #2 , K
If K = 16 Then
Get #2 , D
D = D And &B00011011
Portb = D
End If
Loop
Bascom besitzt spezielle Befehle für die Servosteuerung. Sie verwenden jedoch einen Timer-Interrupt, der mit der Software-COM-Schnittstelle kollidiert. Deshalb werden die Impulse hier mit einfachen Zählschleifen erzeugt. Für jeden Impuls sendet der PC den Kanal (1 oder 2) und die Impulslänge (80 bis 160 für 1 ms bis 2 ms). Das PC-Programm legt daher auch die Wiederholrate fest.
'Servo-Controller
'Servo 1 an PB3
'Servo 2 an PB4
$regfile = "attiny13.dat"
$crystal = 1200000
Dim N As Byte
Dim D As Byte
Dim K As Byte
Open "comb.2:9600,8,n,1,INVERTED" For Input As #2
Declare Sub Servo1
Declare Sub Servo2
Ddrb.3 = 1
Ddrb.4 = 1
Do
Get #2 , K
Get #2 , D
If K = 1 Then Servo1
If K = 2 Then Servo2
Loop
Sub Servo1
Portb.3 = 1
For N = 1 To D
Next D
Portb.3 = 0
End Sub
Sub Servo2
Portb.4 = 1
For N = 1 To D
Next D
Portb.4 = 0
End Sub
End