Академический Документы
Профессиональный Документы
Культура Документы
mbas
program encode
' Copyright 2012 by IZ1TDS - feel free to use and modify - Please credit if
' redistribute modified code
' For understanding refer to Analog Devices App Note AN 1070
' PIC 16F877a 4 Mhz XTAL (XT mode) - AD9834 single output on out 0
dim
LCD_EN as sbit at RB1_bit
LCD_RS as sbit at RD7_bit
LCD_D7 as sbit at RB5_bit
LCD_D6 as sbit at RB4_bit
LCD_D5 as sbit at RB3_bit
LCD_D4 as sbit at RB2_bit
dim
LCD_EN_Direction as sbit at TRISB1_bit
LCD_RS_Direction as sbit at TRISD7_bit
LCD_D7_Direction as sbit at TRISB5_bit
LCD_D6_Direction as sbit at TRISB4_bit
LCD_D5_Direction as sbit at TRISB3_bit
LCD_D4_Direction as sbit at TRISB2_bit
dim counter as longword
'
dim frequo as longword
dim sword, cword as longword
dim ach as float
dim freqs as string[16]
dim LSW,MSW as word
dim i as integer
const fixx as longword = 268435456 ' 2 ^ 28 (because 28 bit control word)
const mckl as longword = 50000000 ' master clock value - change if needed
sub procedure DDSend(dim value as word)
' Software SPI routine
16bit transfer
SetBit(PORTD, 5) ' SCLK
SetBit(PORTD, 4) ' CS
SetBit(PORTD, 1) ' DATA
ClearBit(PORTD, 4)
for i = 0 to 15
if ((value and $8000) = 0) then ClearBit(PORTD, 1) else SetBit(PORTD, 1) end if
value = value << 1
ClearBit(PORTD, 5)
SetBit(PORTD, 5)
next i
SetBit(PORTD, 4)
SetBit(PORTD, 1)
end sub
sub procedure DDSUpdate(dim freq as longword)
ach =
cword
LSW =
LSW =
sword
MSW =
DDSUpdate(counter)
INTCON.INTF = 0
' reset interrupt
end sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
main:
Lcd_Init()
Lcd_Cmd(_LCD_CLEAR)
Lcd_Cmd(_LCD_CURSOR_OFF)
Lcd_Out_Cp("IZ1TDS DDS 28bit")
delay_ms(50)
TRISD = 0
delay_ms(10)
SetBit(PORTD, 1) ' SPI Data
SetBit(PORTD, 4) ' SPI Chip Select
SetBit(PORTD, 5) ' SPI Clock
delay_ms(10)
ClearBit(PORTD, 0) '
delay_us(1)
SetBit(PORTD, 0) ' RESET
delay_us(1)
ClearBit(PORTD, 0) '
delay_ms(5000)
TRISB = 0
TRISB.0 = 1
TRISD.6 = 1
INTCON.GIE = 1
' set global int's
INTCON.INTE = 1 ' set interrupt
OPTION_REG.INTEDG = 0 ' set rising front
delay_ms(5000)
counter = 1000000
''' start frequency change to convenient value
while true
delay_ms(1000)
Lcd_Cmd(_LCD_CLEAR)
longwordtostr(counter,freqs)
Lcd_Out_cp(freqs)
wend
end.
-2-