Eenvoudige projecten voor de microchip microcontrollers geschreven in picbasic, proton+.
vrijdag 18 januari 2013
ad9850 dds
Meetzender van 0-40mhz met de ad9850 module.
Device 18F4620
Xtal 20
LCD_DTPin PORTC.0
LCD_ENPin PORTC.4
LCD_RSPin PORTC.5
All_Digital = TRUE
INTCON.3 = 1
INTCON.4 = 1
INTCON2.6 = 0
INTCON2.7 = 0
INTCON2.5 = 0
INTCON3.3 = 1
Dim rotaryold As Byte
Dim rotary As Byte
Dim teller As Byte
Dim lcdfreq As Dword
Dim freq As Dword
Dim calfreq As Dword
Dim clock As Dword
Dim dds As Dword
Dim lcdmhz As Byte
Dim calbit As Word
Dim lcdkhz As Word
Dim lcdhz As Byte
Dim stap As Dword
clock = 12500500
freq = 1000000
stap = 100
Cls
freq = ERead 0
If freq > 4000000 Or freq < 0 Then freq = 1000000
Call calcad
main:
rotaryold = PORTB & $3
rotary=rotaryold
While rotary = 3
INTCON.0 = 0
INTCON.1 = 0
INTCON3.0 = 0
nap 7
' verwerk portb waarden rot encoder
rotary = PORTB & $3
Select Case INTCON.0
Case 1
If PORTB.7 = 0 Then Call chstap
End Select
Wend
' rustand rot enc 3, draaien we omlaag dan 2-1-3 omhoog 1-2-3 na int = dus oml een 1 en omh een 2
Select Case rotary
Case 0
GoTo main
Case 1
If rotaryold = 3 Then Call omlaag
Case 2
If rotaryold = 3 Then Call omhoog
End Select
GoTo main
omhoog:
freq = freq + stap
If freq > 4000000 Then freq = 0
Call calcad
Return
omlaag:
freq = freq - stap
If freq < 0 Then freq = 4000000
Call calcad
Return
calcad:
dds = 0
calfreq = freq
For teller = 31 To 0 Step -1 ' 32 bits berekenen
calfreq = calfreq // clock << 1 ' restant *2
calbit = calfreq / clock ' volgende bit
If calbit = 1 Then SetBit dds,teller
Next teller
SHOut PORTE.2,PORTE.0,0,[dds.Byte0,dds.Byte1,dds.Byte2,dds.Byte3,$00]
High PORTE.1
Low PORTE.1
EWrite 0,[freq]
lcdfreq = freq
lcdmhz = lcdfreq / 100000
lcdkhz = (lcdfreq // 1000000) / 100
lcdhz = lcdfreq // 100
Print At 1,1, Dec2 lcdmhz,".",Dec3 lcdkhz,",",Dec2 lcdhz,"0 Khz"
Select Case stap
Case 1
Print At 2,2," ^"
Case 10
Print At 2,2," ^ "
Case 100
Print At 2,2," ^ "
Case 1000
Print At 2,2," ^ "
Case 10000
Print At 2,2," ^ "
Case 100000
Print At 2,2,"^ "
End Select
Return
chstap:
Select Case stap
Case 1
stap = 10
Case 10
stap = 100
Case 100
stap = 1000
Case 1000
stap = 10000
Case 10000
stap = 100000
Case 100000
stap = 1
End Select
DelayMS 100
Call calcad
Return
Abonneren op:
Posts (Atom)