#include "sys.h"
#include "my_LDC1314.h"
#include "myiic.h"
#include "delay.h"
u16 LDC1314_Read2Byte(u8 reg_addr){
u16 reg_data=0;
u16 temp=0;
IIC_Start();
IIC_Send_Byte(WRITE_ADDR);
if(IIC_Wait_Ack())return 0;
IIC_Send_Byte(reg_addr);
if(IIC_Wait_Ack())return 0;
IIC_Start();
IIC_Send_Byte(READ_ADDR);
if(IIC_Wait_Ack())return 0;
reg_data= IIC_Read_Byte(1);
reg_data=(reg_data<<8)&0xFF00;
temp=IIC_Read_Byte(0);
IIC_Stop();
reg_data|=temp;
return reg_data;
}
u8 LDC1314_Write2Byte(u8 reg_addr,u16 reg_data){
u8 data_high=(u8)((reg_data&0xFF00)>>8);
u8 data_low=(u8)reg_data&0x00FF;
IIC_Start();
IIC_Send_Byte(WRITE_ADDR);
if(IIC_Wait_Ack())return 0;
IIC_Send_Byte(reg_addr );
if(IIC_Wait_Ack())return 0;
IIC_Send_Byte(data_high);
if(IIC_Wait_Ack())return 0;
IIC_Send_Byte(data_low);
if(IIC_Wait_Ack())return 0;
IIC_Stop();
delay_ms(5);//ÕaàïóD5msÑó3ù
return 1;
}
void LDC1314_Init(){
LDC1314_Write2Byte(RCOUNT0,0x09C4);
LDC1314_Write2Byte(RCOUNT1,0x09C4);
LDC1314_Write2Byte(RCOUNT2,0x09C4);
LDC1314_Write2Byte(RCOUNT3,0x09C4);
LDC1314_Write2Byte(SETTLECOUNT0,0x04E2);//0a60
LDC1314_Write2Byte(SETTLECOUNT1,0x04E2);
LDC1314_Write2Byte(SETTLECOUNT2,0x04E2);
LDC1314_Write2Byte(SETTLECOUNT3,0x04E2);
LDC1314_Write2Byte(CLK_DIVIDERS0,0x1002);//500a
LDC1314_Write2Byte(CLK_DIVIDERS1,0x1002);
LDC1314_Write2Byte(CLK_DIVIDERS2,0x1002);
LDC1314_Write2Byte(CLK_DIVIDERS3,0x1002);
LDC1314_Write2Byte(RESET_DEV,0x0400);
LDC1314_Write2Byte(ERROR_CONFIG,0x0000);
LDC1314_Write2Byte(MUX_CONFIG,0xC20D);//??//0801
LDC1314_Write2Byte(DRIVE_CURRENT0,0x9000);//9800
LDC1314_Write2Byte(DRIVE_CURRENT1,0x9000);
LDC1314_Write2Byte(DRIVE_CURRENT2,0x9000);
LDC1314_Write2Byte(DRIVE_CURRENT3,0x9000);
LDC1314_Write2Byte(CONFIG,0x1681);//2451//1501
}
void LDC1314_Init_single(){
LDC1314_Write2Byte(RCOUNT0,0x09C4);
LDC1314_Write2Byte(SETTLECOUNT0,0x04E2);
LDC1314_Write2Byte(CLK_DIVIDERS0,0x1002);
LDC1314_Write2Byte(RESET_DEV,0x0200);
LDC1314_Write2Byte(ERROR_CONFIG,0x0000);
LDC1314_Write2Byte(MUX_CONFIG,0x020D);//??//0801
LDC1314_Write2Byte(DRIVE_CURRENT0,0x9000);//9800
LDC1314_Write2Byte(CONFIG,0x1281);//2451//1501
}
/////////////////////////////////////////////////////
#include "sys.h"
#define READ_ADDR 0x55
#define WRITE_ADDR 0x54
#define DATA0 0x00
#define DATA1 0x02
#define DATA2 0x04
#define DATA3 0x06
#define RCOUNT0 0x08
#define RCOUNT1 0x0A
#define RCOUNT2 0x0B
#define RCOUNT3 0x0C
#define SETTLECOUNT0 0x10
#define SETTLECOUNT1 0x11
#define SETTLECOUNT2 0x12
#define SETTLECOUNT3 0x13
#define CLK_DIVIDERS0 0x14
#define CLK_DIVIDERS1 0x15
#define CLK_DIVIDERS2 0x16
#define CLK_DIVIDERS3 0x17
#define ERROR_CONFIG 0x19
#define MUX_CONFIG 0x1B
#define RESET_DEV 0x1C
#define DRIVE_CURRENT0 0x1E
#define DRIVE_CURRENT1 0x1F
#define DRIVE_CURRENT2 0x20
#define DRIVE_CURRENT3 0x21
#define CONFIG 0x1A
void LDC1314_Init(void);//3é1|1꧰ü0
u16 LDC1314_Read2Byte(u8 reg_addr);//·μ»Ø½á1û
u8 LDC1314_Write2Byte(u8 reg_addr,u16 reg_data);//3é1|1꧰ü0
void LDC1314_Init_single(void);
亲测可用,不过1314的检测距离过短,还是考虑用1000
|