Dieses Programm spricht ein PLL-IC an, welches beim Startdurchgang 16,270 Mhz in 5khz Schritten einstellt.
PinC4 und PinC.5 sind UP/Down-Taster, die je Durchgang 5Khz rauf bzw runter schalten sollen.
Folgendes Problem:
Beim Startdurchgang wird fehlerfrei 16.270 ausgegeben. Nach Up oder Down kommt nur noch Müll aus dem PLL. Die Anzeige funktioniert aber genau so wie sie soll.
Variable "Kanal" beinhaltet beim Start 16270
die ans PLL übergebene Variable "Wert" ist "Kanal" / 5 = 3250
Beim Hochschalten erhöhe ich "Kanal" um 5 , also auf 16275.
"Wert" bekommt dann den Inhalt 16275 / 5 = 3255.
Wo liegt der Fehler?
PinC4 und PinC.5 sind UP/Down-Taster, die je Durchgang 5Khz rauf bzw runter schalten sollen.
Folgendes Problem:
Beim Startdurchgang wird fehlerfrei 16.270 ausgegeben. Nach Up oder Down kommt nur noch Müll aus dem PLL. Die Anzeige funktioniert aber genau so wie sie soll.
Variable "Kanal" beinhaltet beim Start 16270
die ans PLL übergebene Variable "Wert" ist "Kanal" / 5 = 3250
Beim Hochschalten erhöhe ich "Kanal" um 5 , also auf 16275.
"Wert" bekommt dann den Inhalt 16275 / 5 = 3255.
Wo liegt der Fehler?
Code:
$regfile = "m8def.dat"
$crystal = 8000000
'----------------- mux anzeige -------------
Config Timer0 = Timer , Prescale = 256
On Timer0 Mux
Const Timervorgabe = 178
Enable Timer0
Enable Interrupts
'------------------------------------
Dim A As Byte
Dim Kanal As Word
Dim Einer As Word
Dim Zehner As Word
Dim Hunni As Word
Dim Tausend As Word
Dim 10_tusin As Word
Dim Raus As Byte
Dim Led1 As Byte
Dim Led2 As Byte
Dim Led3 As Byte
Dim Led4 As Byte
Dim Led5 As Byte
Dim Wert As Long
Config Portb = Output 'BortB1- B3 = lm7001
Config Portc = Output 'mux tranis und up/down
Config Portd = Output ' 7-segment Anzeige
'-------------- C4 und C5 als up/down Eingabe ---------------------
Config Pinc.4 = Input
Config Pinc.5 = Input
Portc = 48
'----------------- Initialieren des LM7001 ------------------
Const Lm7001steuerwort = &B00000000111000000000000000000000
Lm7001_ce Alias Portb.3
Lm7001_clock Alias Portb.2
Lm7001_data Alias Portb.1
Declare Sub Radiofrequenz(byval Rfreq As Long)
Dim L As Long
'------------- Startdurchgang -------------------
Kanal = 16270
Gosub Leddisplay
'--------------- Haupprogramm --------------------------
Main:
Do
If Pinc.4 = 0 Then Gosub Rauf
If Pinc.5 = 0 Then Gosub Runter
Loop
' -----------------------------------------
Rauf:
Kanal = Kanal + 5
Gosub Leddisplay
Waitms 500
Return
'------------------------
Runter:
Kanal = Kanal - 5
Gosub Leddisplay
Waitms 500
Return
' -------------------------------------------
Leddisplay:
Wert = Kanal / 5
Einer = Kanal Mod 10
Zehner = Kanal / 10
Hunni = Kanal / 100
Tausend = Kanal / 1000
10_tusin = Kanal / 10000
If Kanal => 10000 Then Tausend = Tausend Mod 10
If Kanal => 1000 Then Hunni = Hunni Mod 10
If Kanal > 100 Then Zehner = Zehner Mod 10
Led1 = Lookup(einer , Segmente)
Led2 = Lookup(zehner , Segmente)
Led3 = Lookup(hunni , Segmente)
Led4 = Lookup(tausend , Segmente)
Led5 = Lookup(10_tusin , Segmente)
Call Radiofrequenz(wert)
Return
'-------------------------------
End
Segmente:
Data &B11000000 , &B11111001 , &B10100100 , &B10110000 , &B10011001 , &B10010010 , &B10000010 , &B11111000 , &B10000000 , &B10010000
'----------------------------------------------
Sub Radiofrequenz(byval Rfreq As Long)
Rfreq = Rfreq Or Lm7001steuerwort
Lm7001_ce = 1 'CE = Aktiv
Waitus 30
Shiftout Lm7001_data , Lm7001_clock , Rfreq , 3 , 24 , 4000000
Waitus 30
Lm7001_ce = 0
End Sub
'-------------------------------------------------
Mux:
Timer0 = Timervorgabe
A = A + 1
If A = 1 Then
Portc.0 = 1
Portc.1 = 0
Portc.2 = 0
Portc.3 = 0
Portd = Led1
End If
If A = 2 Then
Portc.0 = 0
Portc.1 = 1
Portc.2 = 0
Portc.3 = 0
Portd = Led2
End If
If A = 3 Then
Portc.0 = 0
Portc.1 = 0
Portc.2 = 1
Portc.3 = 0
Portd = Led3
End If
If A = 4 Then
Portc.0 = 0
Portc.1 = 0
Portc.2 = 0
Portc.3 = 1
Portd = Led4
A = 0
End If
Return