Es läuft nicht, was ist falsch am Code für den Robosapien. Habe ihn gemäss oberer Timingbeschreibung erstellt. Ir-Diode funktioniert, wird durch Cmoscam angezeigt. Ein Programm ähnlichem Aufbaues für den RC5-Code funktioniert (siehe unten).
Ps: Waitus=1 sind im Programmablauf 10us, weil durch den internen Schleifenurchlauf ca 6 us verbraucht werden, wird er auf 10us festgesetzt.
Code:
$Device= m16
$Stack = 32
$Clock = 8
$Timer1=Timer, Prescale=1, CompareA=Toggle, Clear
Dim command As Byte
Dim i As Byte
Declare Sub RCout()
Const Delay83=83
Const Delay333=333
Const Delay666=666
DDRD.5=1
Compare1A=102
Start Timer1
$Timer1=Timer, CompareA=Reset
command=132
Do
Wait 1
RCout()
Loop
Sub RCout()
$Timer1=Timer, CompareA=Toggle
WaitUs 666
Nop 6
$Timer1=Timer, CompareA=Reset
For i=0 To 7
If command.7 =0 Then
$Timer1=Timer, CompareA=Toggle
WaitUs 83
Nop 3
$Timer1=Timer, CompareA=Reset
WaitUs 83
Else
$Timer1=Timer, CompareA=Toggle
WaitUs 333
Nop 3
$Timer1=Timer, CompareA=Reset
WaitUs 83
End If
Shift(Left,1,command)
Next
$Timer1=Timer, CompareA=Reset
End Sub
Beispiel für RC5 funktioniert:
Code:
$Device= m16
$Stack = 32
$Clock = 8
$Timer1=Timer, Prescale=1, CompareA=Toggle, Clear
Dim ToggleBit As Bit
Dim Adr As Byte, Command As Byte
Declare Sub RC5out(adr As Byte, command As Byte)
Declare Sub BitLow()
Declare Sub BitHigh()
Const Delay=89
Set DDRD.5
Compare1A=101
Start Timer1
Adr=0
Command=5
Do
RC5out(Adr,Command)
WaitMs 90
Loop
Sub RC5out(adr As Byte, command As Byte)
Local i As Byte
BitHigh()
BitHigh()
If ToggleBit Then
BitHigh()
Else
BitLow()
End If
For i=0 To 4
If adr.4 Then
BitHigh()
Else
BitLow()
End If
Shift(Left,1,adr)
Next
For i=0 To 5
If command.5 Then
BitHigh()
Else
BitLow()
End If
Shift(Left,1,command)
Next
$Timer1=Timer, CompareA=Reset
End Sub
Sub BitLow()
$Timer1=Timer, CompareA=Toggle
WaitUs Delay
$Timer1=Timer, CompareA=Reset
WaitUs Delay
End Sub
Sub BitHigh()
WaitUs Delay
$Timer1=Timer, CompareA=Toggle
WaitUs Delay
$Timer1=Timer, CompareA=Reset
End Sub
Lesezeichen