标题:
并口模拟IIC的经验之谈(8)
[打印本页]
作者:
yuyang911220
时间:
2014-8-18 17:24
标题:
并口模拟IIC的经验之谈(8)
/*************************************/
//函数名称:IIC 读一个字符函数
/*************************************/
char port2iicbase::i2c_readbyte()
{
unsigned short count=8;
char d,e,f='\x0';
DWORD dwPortVal;while(count>0)
{
SetPortVal(PORT1,0x07,1);/*scl 0, sda 1*/
delay(1);/***/
SetPortVal(PORT1,0x0f,1);/*scl 1, sda 1*/
delay(1);
GetPortVal(PORT2, &dwPortVal, 1);
e = (char)dwPortVal;
d=e>>4;
d=d<<7;
if(d=='\x80')
d='\x1';
f=f<<1;
f=(f+d); //组合成字节
count--;
}
return f;
}
/*************************************/
//函数名称:主机(并口)的发送应答
/*************************************/
void port2iicbase::i2c_ask()
{
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);
}
//////////////////////////////////
//发送数据按钮
/////////////////////////////////
void Cport2iicdlg1::OnWriteok()
{
// TOD Add your control notification handler code here
port2iicbase port2iic;
char s[100];
char temp[3];
int len;
int i;
char m_cValue;
unsigned int WriValue=0;
int time = 0;
unsigned short c;
char d,e;
#ifdef _PORT2IIC
SetDlgItemText(IDC_WRITE_STATUS,"正在发送....");
GetDlgItem(IDC_EDIT_WRITE)->GetWindowText(s, 100);
len = strlen(s);
c = len/2;
e='\x0';
d='\x0';
i = 0;
c = 5;
//写一页
//启动开始信号;
port2iic.i2c_start();
//发送控制信息
//"\xa0" = 1010(A2)(A1)(A0)(R/W) 其中(R/w) = 0 写
//"\xa1" = 1010(A2)(A1)(A0)(R/W) 其中(R/w) = 1 读
port2iic.i2c_writebyte('\xa0');
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0