delay(1);
clk=0;
delay(1);
if(!(_data1&0x01))
{
if(_data3&0x80)
sda=1;
else sda=0;
delay(1);
clk=1;
delay(1);
clk=0;
delay(1);
if(_data3&0x40)
sda=1;
else sda=0;
delay(1);
clk=1;
delay(1);
clk=0;
delay(1);
if(_data3&0x20)
sda=1;
VK3342,VK3344,VK3362,VK3366,VK3368 IIC2UART 驱动C语言代码
else sda=0;
delay(1);
clk=1;
delay(1);
clk=0;
delay(1);
if(_data3&0x10)
sda=1;
else sda=0;
delay(1);
clk=1;
delay(1);
clk=0;
delay(1);
if(_data3&0x08)
sda=1;
else sda=0;
delay(1);
clk=1;
delay(1);
clk=0;
delay(1);
if(_data3&0x04)
sda=1;
else sda=0;
delay(1);
clk=1;
delay(1);
clk=0;
delay(1);
if(_data3&0x02)
sda=1;
else sda=0;
delay(1);
clk=1;
delay(1);
clk=0;
delay(1);
if(_data3&0x01)
VK3342,VK3344,VK3362,VK3366,VK3368 IIC2UART 驱动C语言代码
sda=1;
else sda=0;
delay(1);
clk=1;
delay(1);
clk=0;
delay(1);
clk=1; //ack
delay(1);
clk=0;
delay(1);
sda=0;//stop bit
delay(1);
clk=1;
delay(1);
sda=1;
}
else
{
clk=1;
delay(1);
if(sda)
i=i+128;
clk=0;
delay(1);
clk=1;
delay(1);
if(sda)
i=i+64;
clk=0;
delay(1);
clk=1;
delay(1);
if(sda)
i=i+32;
clk=0;
delay(1);
clk=1;
delay(1);
if(sda)
i=i+16;
VK3342,VK3344,VK3362,VK3366,VK3368 IIC2UART 驱动C语言代码
clk=0;
delay(1);
clk=1;
delay(1);
if(sda)
i=i+8;
clk=0;
delay(1);
clk=1;
delay(1);
if(sda)
i=i+4;
clk=0;
delay(1);
clk=1;
delay(1);
if(sda)
i=i+2;
clk=0;
delay(1);
clk=1;
delay(1);
if(sda)
i=i+1;
clk=0;
delay(1);
sda=0;
delay(1);
clk=1; //ack
delay(1);
clk=0;
delay(1);
sda=0;//stop bit
delay(1);
clk=1;
delay(1);
sda=1;
}
return i;
}
VK3342,VK3344,VK3362,VK3366,VK3368 IIC2UART 驱动C语言代码
//模拟SPI时序,data1,data2是写入的两个数据,这里仅返回第二个数据
//*************************************************************************
//*************************************************************************
void write_reg(unsigned char port,unsigned char reg,unsigned char dat)
{
send(0x90,(((port-1)<<4)+reg),dat);
}
//写寄存器,port为子串口的路数,reg为寄存器的地址,dat为写入寄存器的数据
//*************************************************************************
//*************************************************************************
unsigned char read_reg(unsigned char port,unsigned char reg)
{
return send(0x91,(((port-1)<<4)+reg),0x00);
}
//读寄存器,琾ort为子串口的路数,reg为寄存器的地址,返回寄存器的值
//***************************************************************************
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// 51单片机 采用IIC 转UART VK33XX
// VK33.c
//
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "def.h"
//*****************************************************************************
*******
void config_vkxx()
{
//***********************************************************
write_reg(1,SCTLR,0X38);
write_reg(2,SCTLR,0X38);
write_reg(3,SCTLR,0X38);
write_reg(4,SCTLR,0X38);
//使能子串口,设置子串口的波特率,具体参看数据手册中,子串口波特率设置