Hallo,
habe einen Code geschrieben, bei dem man die Frequenz und Duty mit hilfe von timer1 einstellen kann. Jedoch funktioniert es nicht richtig. Kann mir vieleicht jemand sagen, wo mein Fehler liegt?
Code:
$regfile = "2313def.dat"
$crystal = 10000000
$baud = 9600
Const True = 1
Const False = 0
Dim Hi As Single
Dim Lo As Single
Dim Freq As Word
Dim Phase As Bit
Dim Duty As Byte
Config Timer1 = Timer , Prescale = 1
On Timer1 Timer1_isr
Config Pinb.5 = Output
Enable Timer1
Enable Interrupts
Do
Input "Zeit [0-65535]" , Freq
Input "Duty [0-100%]" , Duty
Hi = Freq * 0.01
Hi = Duty * Hi
Hi = Int(hi)
Lo = Freq - Hi
Print "High: " ; Hi
Print "Low: " ; Lo
Loop
End
Timer1_isr:
If Phase = True Then
Timer1 = Lo
Phase = False
Else
Timer1 = Hi
Phase = True
End If
Toggle Portb.5
Return
Lesezeichen