I2C打印
来源:互联网 发布:wish产品优化 编辑:程序博客网 时间:2024/06/15 07:47
#define LOW 0
#define HIGH 1
#define EXBUFF_LEN 100
unsigned char exbuff[EXBUFF_LEN]={0};
#define SDA_SET_AS_INPUT {PE_DDR2=0;}
#define SCL_SET_AS_INPUT {PE_DDR1=0;}
#define test_GET_SDA_VALUE PE_IDR2
#define test_GET_SCL_VALUE PE_IDR1
/*print from I2C Start to I2C End ,then return */
void PrintI2C(void)
{
unsigned char SDA_last,SDA_current;
unsigned char SCL_last,SCL_current;
unsigned char temp,stopState=0;
unsigned char inbyte=0;
unsigned int i,j,k;
static unsigned char ptr=0;
//PrintString("PrintI2C()...\n") ;
SDA_SET_AS_INPUT;
SCL_SET_AS_INPUT;
while(!test_GET_SDA_VALUE||!test_GET_SCL_VALUE);
//PrintString("two bus ready\n");
while(1)
{
//wait start
while(1)
{
if(test_GET_SCL_VALUE==HIGH && test_GET_SDA_VALUE==LOW)
{
//PrintString("st\n");
break;
}
}
//printf("wait two line low\n");
while(test_GET_SDA_VALUE||test_GET_SCL_VALUE);
while(1)
{
for(i=0;i<8;i++)
{
//printf("wait scl 1\n");
while(!test_GET_SCL_VALUE);//wait high
temp=test_GET_SDA_VALUE;
if(temp!=0)
{
inbyte |= (1<<(7-i));
}
//printf("wait scl 0\n");
while(test_GET_SCL_VALUE)//wait low
{
if(temp==0 && test_GET_SDA_VALUE==1)
{
//stop
return;
}
else if(temp==1 && test_GET_SDA_VALUE==0)
{
//restart
}
}
}
//PrintStringNumberHex(",",inbyte);
#if 1
exbuff[ptr++]=inbyte;
if(ptr==EXBUFF_LEN)
{
for(j=0;j<EXBUFF_LEN;j++)
{
PrintStringNumberHex(",",exbuff[j]);
}
while(1);
}
#endif
//check ACK or NACK
while(!test_GET_SCL_VALUE);//wait high
while(test_GET_SCL_VALUE); //wait low
//ack end
inbyte=0;
}
}
}
- I2C打印
- I2C
- I2C
- i2c
- I2C
- I2C
- i2c
- i2c
- I2C
- I2C
- I2c
- I2C
- I2C
- I2C
- I2C
- I2C
- i2c
- I2C
- BHO启动IE调试
- mybatis环境搭建
- LINUX下手动添加swap分区
- SAE笔记django 与 cron
- LeetCode Fraction to Recurring Decimal
- I2C打印
- iOS形成静态库方法
- mybatis使用示例
- StarUML使用
- 通过设置子窗体透明度,解决C# winform 子窗体设置背景图卡的问题
- libxml2对XML文件的
- confirm用法
- Initializing a Build Environment
- app审核问题