|
各位大虾帮帮忙,我用51控制PLL AD4106的程序为什么老是控制不了,不懂了.....谁用过的能帮我看看么
//ODU
//*****************************
//*** L BAND PLL ***
//*** ODU C p=32 pd=10M
//*****************************
#include <INTRINS.H>
#include "math.h"
#include "absacc.h"
#include "reg51.h"
#define LOW 0
#define HIGH 1
#define TRUE 1
#define FALSE ~TRUE
sbit CLK=P3^1; // 时钟信号
sbit DATA=P3^0; // 数据信号
sbit LE=P2^7; // 使能信号
sbit key=P2^6; //
unsigned char REFCOUNT1=0x00;
unsigned char REFCOUNT2=0x01;
unsigned char REFCOUNT3=0x00;
unsigned char NCOUNT1=0x00;
unsigned char NCOUNT2=0x17;
unsigned char NCOUNT3=0x9d;
unsigned char FUNCTION1=0x00;
unsigned char FUNCTION2=0x00;
unsigned char FUNCTION3=0x93;
void delay(void)
{
unsigned int i;
for(i=0;i<100;i++);
}
/****************************************************************************
* Prototype: void I_start(void);
* Function: start I2C,start condition:when SCL=HIGH,SDA from HIGH to LOW
* I2C是一种芯片间的通讯方式,采用两条线进行通讯,一条数据线,一条时钟线。
****************************************************************************/
void PLL_start( void ) {
LE=LOW; //0,START
}
/****************************************************************************
* Prototype: void I_stop(void);
* Function: stop I2C,stop condition:when SCL=HIGH,SDA from LOW to HIGH
****************************************************************************/
void PLL_stop( void ) {
LE=HIGH; //1,STOP
}
/****************************************************************************
* Prototype: bit I_clock(void);
* Function: Provide CLK for I2C BUS,return SDA when CLK is HIGH,
* the function can be used in data transmitting and receiving
****************************************************************************/
void PLL_clock( void ) {
CLK = LOW ;
CLK = HIGH ;
_nop_();
CLK = LOW ;
}
/****************************************************************************
* Prototype: bit I_send(byte I_data);
* Function: send 8 bit data and ask an ACK signal
* if receive ACK return 1(TRUE),or else return 0(FALSE)
****************************************************************************/
void PLL_send( unsigned char I_data ) {
unsigned char i ;
// send 8 bit data
for ( i=0 ; i<8 ; i++ ) //发8位
{
DATA = (bit)( I_data & 0x80) ; //置DATA为最高位和1与的结果
I_data = I_data << 1 ; //I_data左移1位
PLL_clock() ; //发送DATA值
}
}
/****************************************************************************
* Prototype: bit I_send(byte I_data);
* Function: send 8 bit data and ask an ACK signal
* if receive ACK return 1(TRUE),or else return 0(FALSE)
****************************************************************************/
void PLL_send5( unsigned char I_data ) {
unsigned char i ;
I_data = I_data << 3 ; //I_data左移1位
// send 8 bit data
for ( i=0 ; i<5 ; i++ ) //发8位
{
DATA = (bit)( I_data & 0x80) ; //置DATA为最高位和1与的结果
I_data = I_data << 1 ; //I_data左移1位
PLL_clock() ; //发送DATA值
}
}
void main(){
unsigned char j;
PLL_start();
PLL_send5(FUNCTION1);
PLL_send(FUNCTION2);
PLL_send(FUNCTION3);
PLL_stop();
PLL_start();
PLL_send5(REFCOUNT1);
PLL_send(REFCOUNT2);
PLL_send(REFCOUNT3);
PLL_stop();
PLL_start();
PLL_send5(NCOUNT1);
PLL_send(NCOUNT2);
PLL_send(NCOUNT3);
PLL_stop();
key=0;
PLL_start();
while(1)
{
delay();
if(key)
{
PLL_start();
PLL_send5(FUNCTION1);
PLL_send(FUNCTION2);
PLL_send(FUNCTION3);
PLL_stop();
PLL_start();
PLL_send5(REFCOUNT1);
PLL_send(REFCOUNT2);
PLL_send(REFCOUNT3);
PLL_stop();
PLL_start();
PLL_send5(NCOUNT1);
PLL_send(NCOUNT2);
PLL_send(NCOUNT3);
PLL_stop();
PLL_start();
}
}
} |
|