//**** 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);
}
}
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 | |
【分享评测,赢取加热台】使用8051单片机驱动WS2812被打赏40分 |