标题:
并口模拟IIC的经验之谈(7)
[打印本页]
作者:
yuyang911220
时间:
2014-8-18 17:23
标题:
并口模拟IIC的经验之谈(7)
void port2iicbase::i2c_stop()
{
SetPortVal(PORT1,0x07,1);/*scl 0, sda 1*/
delay(1);
SetPortVal(PORT1,0x0d,1);/*scl 1, sda 0*/
delay(1);/***/
SetPortVal(PORT1,0x0f,1);/*scl 1, sda 1*/
delay(1);/**/
SetPortVal(PORT1,0x05,1);/*scl 0, sda 0*/
}
/*************************************/
//函数名称:IIC 写一个字节函数
/*************************************/
int port2iicbase::i2c_writebyte(char c)
{
short int count=7;
char temp;
DWORD dwPortVal;
char e;while(count>=0)
{
temp=c>>count;
temp=temp<<7; //确定传输的字节
if (temp=='\x80') //传输"1"
{
SetPortVal(PORT1,0x05,1);/*scl 0, sda 0*/
delay(1);
SetPortVal(PORT1,0x07,1);/*scl 0, sda 1*/
delay(1);
SetPortVal(PORT1,0x0f,1);/*scl 1, sda 1*/
delay(1);
SetPortVal(PORT1,0x07,1);/*scl 0, sda 1*/
delay(1);
}
else //传输"0"
{
SetPortVal(PORT1,0x05,1);/*scl 0, sda 0*/
delay(1);
SetPortVal(PORT1,0x0d,1);/*scl 1, sda 0*/
delay(1);
SetPortVal(PORT1,0x05,1);/*scl 0, sda 0*/
delay(1);
}
count--;
}
/**ask**/
SetPortVal(PORT1,0x07,1);/*scl 0, sda 1*/
delay(1);/***/
SetPortVal(PORT1,0x0f,1);/*scl 1, sda 1*/
delay(1);
// SetPortVal(PORT1,0x05,1);/*scl 0, sda 0*/
// delay(1);/***/
GetPortVal(PORT2, &dwPortVal, 1);
e = (char)dwPortVal;
temp=e>>4;
temp=temp<<7;
if (temp=='\x0')
return 0;
else
MessageBox(NULL,"Not Acknowledge!!","发送错误",MB_OKCANCEL);
return 1;
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0