微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 硬件工程师文库 > LDC1000的底层驱动程序

LDC1000的底层驱动程序

时间:07-08 来源: 点击:

?输出? 1为输出 0输入 * :uint8 data 电平

  *******************************************************************************/

  void DATA_OUT(uint8 pin,uint8 level) {

  if(level) {

  GPIO_PDOR_REG(PTB_BASE_PTR) |= 1《《pin; //第0位输出1 } else {

  GPIO_PDOR_REG(PTB_BASE_PTR) &= ~(1《《pin); //第0位输出0 } }

  void LDC1000_write(char ADDR, char data) {

  uint8 addr=0,dat=0,i=0;

  addr = ADDR & 0x7f; dat = data;

  LDC1000_CS_CLR(); //片选低 Dly_LDC1000CLK();

  LDC1000_CLK_CLR(); // Set clock line low for(i=0;i《16;i++) {

  if(i《8)//写8位命令段 {

  if(addr&0X80) LDC1000_DI_SET(); else LDC1000_DI_CLR(); Dly_LDC1000CLK();

  LDC1000_CLK_SET(); // Set clock line high

  addr 《《= 1; // Shift DATA_BUF Dly_LDC1000CLK();

  LDC1000_CLK_CLR(); // Set clock line low } else {

  if(dat&0X80) LDC1000_DI_SET(); else LDC1000_DI_CLR(); Dly_LDC1000CLK();

  LDC1000_CLK_SET(); // Set clock line high dat 《《= 1; // Shift DATA_BUF Dly_LDC1000CLK();

  LDC1000_CLK_CLR(); // Set clock line low } }

  Dly_LDC1000CLK();

  LDC1000_CS_SET(); //片选高 }

  void LDC1000_read(uint8 ADDR,char *DATA,char len) {

  uint8 addr=0,dat=0,i=0,j=0;

  addr = ADDR | 0x80;

  LDC1000_CLK_CLR(); // Set clock line low for(i=0;i《8;i++)//写8位命令段 {

  if(addr&0X80) LDC1000_DI_SET(); else LDC1000_DI_CLR(); Dly_LDC1000CLK(); LDC1000_CLK_SET();

  addr 《《= 1; // Shift DATA_BUF Dly_LDC1000CLK();

  LDC1000_CLK_CLR(); // Set clock line high }

  for(i=0;i《len;i++) {

  dat=0;

  for(j=0;j《8;j++) {

  dat 《《=1 // Right shift DATA_BUF

  Dly_LDC1000CLK(); LDC1000_CLK_SET(); // Set clock line high

  Dly_LDC1000CLK();

  if(LDC1000_DO_IN) dat |= 0x01; // Read data LDC1000_CLK_CLR(); // Set clock line low }

  DATA[i] = dat; } }

  void LDC1000_init() {

  /* 打开B端口的时钟源 */

  SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK

  /* LDC使用IO端口初始化 */

  PORTB_PCR3 = PORT_PCR_MUX(1); PORTB_PCR5 = PORT_PCR_MUX(1); PORTB_PCR6 = PORT_PCR_MUX(1); PORTB_PCR7 = PORT_PCR_MUX(1);

  gpio_init(PORTB,LDC1000_CLK,GPO,LOW); gpio_init(PORTB,LDC1000_DI,GPO,LOW); gpio_init(PORTB,LDC1000_CS,GPO,LOW); gpio_init(PORTB,LDC1000_DO,GPI,LOW);

  /* LDC寄存器初始化 */

  LDC1000_write(LDC1000_CMD_RPMAX, RPMAX); LDC1000_write(LDC1000_CMD_RPMIN, RPMIN); LDC1000_write(LDC1000_CMD_SENSORFREQ, 0x94); LDC1000_write(LDC1000_CMD_LDCCONFIG, 0x17); LDC1000_write(LDC1000_CMD_CLKCONFIG, 0x02); LDC1000_write(LDC1000_CMD_INTCONFIG, 0x02);

  LDC1000_write(LDC1000_CMD_THRESHILSB, 0x50); LDC1000_write(LDC1000_CMD_THRESHIMSB, 0x14); LDC1000_write(LDC1000_CMD_THRESLOLSB, 0xC0); LDC1000_write(LDC1000_CMD_THRESLOMSB, 0x12);

  LDC1000_write(LDC1000_CMD_PWRCONFIG, 0x01);

  //read all registers LDC1000_CS_CLR(); Dly_LDC1000CLK();

  LDC1000_read(LDC1000_CMD_REVID , orgVal , 12); Dly_LDC1000CLK();LDC1000_CS_SET(); }

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top