小弟我用MEGA48V+AD9834做了一个函数发生器,写了一个控制程序,但是ad9834始终没有结果出来,恳请各位高手指点。单片机与AD9834之间的通信采用SPI接口。 程序如下: #include <avr/io.h> #define ulong unsigned long #define uint unsigned int #define uchar unsigned char void send_byte(uchar byte) {SPDR=byte; while(!(SPSR&(1<<SPIF))) ; //SPSR&=~(1<<SPIF); } void spi_int(void) {DDRB=0xFF; PORTB=(1<<PD3)|(1<<PD5); DDRD=0xFF; PORTD=0x04; SPCR=0x54; SPSR|=0x01; } void send_word(uint word) {uchar word_high,word_low; word_low=word&0x00FF; word_high=(word&0xFF00)>>8; asm ("cbi 0x0B,2"); send_byte(word_high); send_byte(word_low); asm ("sbi 0x0B,2"); } int main(void) {volatile ulong FRE; volatile uint LSB; volatile uint MSB; FRE=0x3333333; LSB=(FRE&0x3FFF)+0x4000; //MSB=(FRE/0x4000)+0x4000; MSB=(FRE&0x3FFC000)>>14; MSB+=0x4000; //LSB=(FRE%0x4000)+0x4000; spi_int(); send_word(0x2100); send_word(MSB); send_word(LSB); send_word(0x2000); } 我的qq是47596382,E-mail:lysqlife@hotmail.com,欢迎大家一块交流。 |