最近在调TM7707这块芯片,有大神用过这块芯片吗,这是我的初始化程序大家帮忙看看哪里出问题了:
void TM7707_init(void)
{
SCLK1_H();
DIN1_H();
udelay(1);
write_byte(0x50);
write_byte(0x00);
udelay(1);
write_byte(0x20);
write_byte(0x03);
udelay(1);
// write_byte(0x10);
// write_byte(0x04);
write_byte(0x10);
write_byte(0x44);
while(DRDY);
}
void write_byte(u8 data)
{
u8 i;
for(i=0; i<8; i++)
{
SCLK1_L();
udelay(1);
if((data & 0x80))
DIN1_H();
else
DIN1_L();
SCLK1_H();
data <<= 1;
}
}
u8 read_data(void)
{
u8 j = 0, rdata = 0;
u8 doutbit = 0;
for(j=0; j<8; j++)
{
SCLK1_L();
udelay(1);
if(DOUT == RESET)
doutbit = 0;
else
doutbit = 1;
rdata = ((rdata << 1)| doutbit);
SCLK1_H();
}
return rdata;
}
uint32_t read_ch1_result(void)
{
u32 tm_result = 0, a[3] = {0};
u8 sum[10] = { 0 };
u8 i = 0,flag = 0;
static u32 k = 0;
while(DRDY != RESET);
write_byte(0x38);
for(i=0; i<3; i++)
{
a[i] = read_data();
}
tm_result = a[0] + (a[1] * 256) + (a[2] * 65536);
return tm_result;
} |