VK3342,VK3344,VK3362,VK3366,VK3368 IIC2UART 驱动C语言代码
myeducs.cn
// VK3342,VK3344,VK3362,VK3366,VK3368 IIC2UART 驱动C语言代码
/*
IIC 宽工作电压2通道16级FIFO的UART VK3342 SSOP16
http://www.fosvos.com/datasheet/VKFV/VK3342_DS_CN_FV_V01.pdf
I IC 宽工作电压4通道16级FIFO的UART VK3344 SOP20
http://www.fosvos.com/datasheet/VKFV/VK3344_DS_CN_FV_V01.pdf
SPI/I IC/ UART /8位并行总线接口宽工作电压2通道16级FIFO的UART VK3362 SOP28
http://www.fosvos.com/datasheet/VKFV/VK3362_DS_CN_FV_V01.pdf
SPI/I IC/ UART /8位并行总线接口宽工作电压4通道16级FIFO的UART VK3366 QFP44
http://www.fosvos.com/datasheet/VKFV/VK3366_DS_CN_FV_V01.pdf
SPI/IIC/UART/8位并行总线接口1.8V QFN封装4通道16级FIFO的UART VK3368 QFN32
http://www.fosvos.com/datasheet/VKFV/VK3368_DS_CN_FV_V012.pdf
*/
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// 51单片机 采用IIC 转UART VK33XX
// main.c
//
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "def.h"
#include "vk33.h"
#include
//在各种方式中,main.c函数和vkxx.h是通用的def.h在spi和parallel方式是通用的uart
//的多了两个批量读写fifo的函数;底层函数不同
void delay (unsigned int delaydata)
{
unsigned int tempdata=delaydata;
while(tempdata)
{
tempdata=tempdata-1;
}
}
void Init_led(void)
{
unsigned int tempdata=0x0ffff;
CH4_LED = 0;
CH3_LED = 0;
VK3342,VK3344,VK3362,VK3366,VK3368 IIC2UART 驱动C语言代码
CH2_LED = 0;
CH1_LED = 0;
PAR_LED = 0;
SPI_LED = 0;
UART_LED = 0;
IIC_LED = 0;
while(tempdata)
{
tempdata=tempdata-1;
}
CH4_LED = 1;
CH3_LED = 1;
CH2_LED = 1;
CH1_LED = 1;
PAR_LED = 1;
SPI_LED = 1;
UART_LED = 1;
IIC_LED = 1;
tempdata=0x0ffff;
while(tempdata)
{
tempdata=tempdata-1;
}
CH4_LED = 0;
CH3_LED = 0;
CH2_LED = 0;
CH1_LED = 0;
PAR_LED = 0;
SPI_LED = 0;
UART_LED = 0;
IIC_LED = 0;
tempdata=0x0ffff;
while(tempdata)
{
tempdata=tempdata-1;
}
CH4_LED = 1;
CH3_LED = 1;
CH2_LED = 1;
CH1_LED = 1;
PAR_LED = 1;
SPI_LED = 1;
UART_LED = 1;
IIC_LED = 1;
VK3342,VK3344,VK3362,VK3366,VK3368 IIC2UART 驱动C语言代码
tempdata=0x0ffff;
while(tempdata)
{
tempdata=tempdata-1;
}
CH4_LED = 0;
CH3_LED = 0;
CH2_LED = 0;
CH1_LED = 0;
PAR_LED = 0;
SPI_LED = 0;
UART_LED = 0;
IIC_LED = 0;
tempdata=0x0ffff;
while(tempdata)
{
tempdata=tempdata-1;
}
}
main()
{
static unsigned char dat1,dat2,dat3,dat4,m,n;
unsigned int tmp=0xfff;
unsigned char err_fla=0,err_flb=0,err_flc=0,err_fld=0;
n=0;
m=0;
//初试化MCU
config();
//初试化LED
Init_led();
//初始化VK;
config_vkxx();
//主IIC接口测试;亮起IIC_LED
CH4_LED = 1;
CH3_LED = 1;
CH2_LED = 1;
CH1_LED = 1;
PAR_LED = 1;
SPI_LED = 1;
UART_LED = 1;
IIC_LED = 0;
VK3342,VK3344,VK3362,VK3366,VK3368 IIC2UART 驱动C语言代码
while(1)
{
//写出数据分别到4个子UART
write_reg(1,SFDR,m);
write_reg(2,SFDR,m);
write_reg(3,SFDR,m);
write_reg(4,SFDR,m);
//延迟后读取FIFO数据
delay(0x8ff);
delay(0x8ff);
dat1=read_reg(1,SFDR);
dat2=read_reg(2,SFDR);
dat3=read_reg(3,SFDR);
dat4=read_reg(4,SFDR);
//delay(0x8ff);
//delay(0x8ff);
//比较读回的数据是否为发出的数据后设置LED的状态.
if(dat1==m)
CH1_LED =0;
else
err_fla =1;
if(dat2==m)
CH2_LED =0;
else
err_flb =1;
if(dat3==m)
CH3_LED =0;
else
err_f