This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

有關MSP430G2553控制LMX2531的暫存器程式問題 急

Other Parts Discussed in Thread: LMX2531

由於我是這方面的新手,初次撰寫以下的程式碼不確定是否正確

因此想要請問是否會發生問題,請各位不吝指教,謝謝。

另外想要請問 如果要delay 25ns要如何撰寫比較恰當。

圖片為LMX2531的selial data timing diagram

**************************************************************

include "io430.h"

#define uchar unsigned char
#define DATA P2OUT_bit.P0 // P2.0 (DATA)
#define CLK P2OUT_bit.P1 // P2.1 (CLK)
#define LE P2OUT_bit.P2 // P2.2 (LE)


void delay_us(unsigned int us) // delay fuction
{
while (us)
{
__delay_cycles(25);
us--;
}
}


// set register value
uchar R5_INIT1[3]={0x84,0x00,0x05};
uchar R5_INIT2[3]={0x80,0x00,0x05};
uchar R5[3]={0x80,0x07,0xF5};
uchar R12[3]={0x01,0x04,0x8C};
uchar R9[3]={0x00,0x0B,0xA9};
uchar R8[3]={0x03,0x00,0x08};
uchar R7[3]={0x00,0x6D,0x07};
uchar R6[3]={0x46,0xE6,0x56};
uchar R4[3]={0x00,0x00,0x04};
uchar R3[3]={0x6C,0xA6,0x23};
uchar R2[3]={0x56,0x80,0x12};
uchar R1[3]={0x20,0x00,0x01};
uchar R0[3]={0xF0,0x00,0x00};

void SendData(uchar Temp)
{
uchar i;
uchar j=0;
j=0;
for(i=0;i<8;i++)
{
CLK=0; delay_us(25);
j=Temp&0x80;
if(j==0)
{
DATA=0;
}
else
{
DATA=1;
}
CLK=1; delay_us(25);
Temp=Temp<<1;
}

}

void config_PLL() // 子程式(send register value)
{

LE=0;
SendData(R5_INIT1[0]);
SendData(R5_INIT1[1]);
SendData(R5_INIT1[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R5_INIT2[0]);
SendData(R5_INIT2[1]);
SendData(R5_INIT2[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R5[0]);
SendData(R5[1]);
SendData(R5[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R12[0]);
SendData(R12[1]);
SendData(R12[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R9[0]);
SendData(R9[1]);
SendData(R9[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R8[0]);
SendData(R8[1]);
SendData(R8[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R7[0]);
SendData(R7[1]);
SendData(R7[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R6[0]);
SendData(R6[1]);
SendData(R6[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R4[0]);
SendData(R4[1]);
SendData(R4[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R3[0]);
SendData(R3[1]);
SendData(R3[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R2[0]);
SendData(R2[1]);
SendData(R2[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R1[0]);
SendData(R1[1]);
SendData(R1[2]);
LE=1;
delay_us(10);
LE=0;
SendData(R0[0]);
SendData(R0[1]);
SendData(R0[2]);
LE=1;

}

int main( void )
{

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer to prevent time out reset

P2DIR = 0x07; // P2.0~P2.2設定為輸出, 其他為輸入
CLK=0;
LE=1; delay_us(25);
config_PLL();
delay_us(10);
CLK=0;
LE=0;
return 0;
}