/**** TI LDC1000 驱动程序
#include "msp430f149.h"
#define LDC1000_CS_L P3OUT &= ~BIT0 //片选
#define LDC1000_CS_H P3OUT |= BIT0
#define LDC1000_CLK_L P3OUT &= ~BIT3 //CLK
#define LDC1000_CLK_H P3OUT |= BIT3
#define LDC1000_OUT_L P3OUT &= ~BIT1 //Data Out
#define LDC1000_OUT_H P3OUT |= BIT1
#define LDC1000_IN (P3IN&BIT2) //Data In
void Init_LDC1000_Port()
{
P3DIR |= BIT0 + BIT1 + BIT3; //P3.0,P3.1,P3.3
P3DIR &= ~BIT2; //P3.2
LDC1000_CS_H;
LDC1000_CLK_L;
LDC1000_OUT_H;
}
void LDC1000_WriteData(uchar address, uchar data)
{
uchar i = 0;
uchar temp = 0;
temp = address;
LDC1000_CS_L;
LDC1000_CLK_L;
for(i=0;i<8;i++)
{
LDC1000_CLK_L;
if(temp&0x80)
{
LDC1000_OUT_H;
}
else
{
LDC1000_OUT_L;
}
LDC1000_CLK_H;
temp = temp<<1;
}
temp = data;
for(i=0;i<8;i++)
{
LDC1000_CLK_L;
if(temp&0x80)
{
LDC1000_OUT_H;
}
else
{
LDC1000_OUT_L;
}
LDC1000_CLK_H;
temp = temp<<1;
}
LDC1000_CLK_L;
LDC1000_CS_H;
}
uint LDC1000_ReadData(uchar address, unsigned long *f)
{
uchar i = 0;
uchar temp = 0;
uint rp1 = 0,rp2 = 0;
uint f1 = 0,f2 = 0;
unsigned long f3 = 0;
temp = address;
temp = temp|0x80;
LDC1000_CS_L;
LDC1000_CLK_L;
for(i=0;i<8;i++)
{
LDC1000_CLK_L;
if(temp&0x80)
{
LDC1000_OUT_H;
}
else
{
LDC1000_OUT_L;
}
LDC1000_CLK_H;
temp = temp<<1;
}
LDC1000_OUT_L;
for(i=0;i<8;i++)
{
LDC1000_CLK_L;
_NOP();
rp1 |= (LDC1000_IN>>2)<<(7-i);
LDC1000_CLK_H;
}
for(i=0;i<8;i++)
{
LDC1000_CLK_L;
_NOP();
rp2 |= (LDC1000_IN>>2)<<(7-i);
LDC1000_CLK_H;
}
rp2 = (rp2<<8 )+ rp1;
for(i=0;i<8;i++)
{
LDC1000_CLK_L;
_NOP();
f1 |= (LDC1000_IN>>2)<<(7-i);
LDC1000_CLK_H;
}
for(i=0;i<8;i++)
{
LDC1000_CLK_L;
_NOP();
f2 |= (LDC1000_IN>>2)<<(7-i);
LDC1000_CLK_H;
}
f2 = (f2<<8) + f1;
for(i=0;i<8;i++)
{
LDC1000_CLK_L;
_NOP();
f3 |= (LDC1000_IN>>2)<<(7-i);
LDC1000_CLK_H;
}
f3 = (f3<<16) +f2;
*f = f3;
LDC1000_CLK_L;
LDC1000_CS_H;
return rp2;
}
void Init_LDC1000_R(void)
{
Init_LDC1000_Port();
LDC1000_WriteData(0x01, 0x0A); //250k
LDC1000_WriteData(0x02, 0x3B); //2.4k
LDC1000_WriteData(0x03, 241); //low frequency
LDC1000_WriteData(0x04, 0x17); //4V, 6144
LDC1000_WriteData(0x05, 0x00); //TBCLK
LDC1000_WriteData(0x06, 0x50);
LDC1000_WriteData(0x07, 0xC3); //50k
LDC1000_WriteData(0x08, 0x88);
LDC1000_WriteData(0x09, 0x13); // 5k
LDC1000_WriteData(0x0A, 0x04); //DRDYB mode
LDC1000_WriteData(0x0B, 0x01); //Power on
}
void main()
{
WDTCTL = WDTPW + WDTHOLD;
volatile unsigned int i;
BCSCTL1 &= ~XT2OFF; //开启高频晶振,XT2=8MHZ
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG));
BCSCTL2 |= SELM1+SELS; //MCLK=SMCLK=XT2=8MHZ
P5SEL |= BIT4;
P5DIR |= BIT4;
unsigned int rp = 0;
unsigned long f = 0;
while(1)
{
rp = LCD1000_ReadData(0x21,&f);
}
}