⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dspic.cpp

📁 lpt to i2c converter source code
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if(buf[0] == 0xFA)
		return false;						// return false
	else
	{
		if(buf[0])
			state = true;
		else
			state = false;
		return true;							// else return true
	}
}

bool CdsPic::Read8(bool &state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xE8;			// Load buf with read8 Command
	buf[1]=0x00;			// Second byte dummy byte, required
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] == 0xFA)
		return false;						// return false
	else
	{
		if(buf[0])
			state = true;
		else
			state = false;
		return true;							// else return true
	}
}
bool CdsPic::Read9(bool &state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xE9;			// Load buf with read9 Command
	buf[1]=0x00;			// Second byte dummy byte, required
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] == 0xFA)
		return false;						// return false
	else
	{
		if(buf[0])
			state = true;
		else
			state = false;
		return true;							// else return true
	}
}

bool CdsPic::Read10(bool &state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xEA;			// Load buf with read10 Command
	buf[1]=0x00;			// Second byte dummy byte, required
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] == 0xFA)
		return false;						// return false
	else
	{
		if(buf[0])
			state = true;
		else
			state = false;
		return true;							// else return true
	}
}

bool CdsPic::Read11(bool &state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xEB;			// Load buf with read11 Command
	buf[1]=0x00;			// Second byte dummy byte, required
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] == 0xFA)
		return false;						// return false
	else
	{
		if(buf[0])
			state = true;
		else
			state = false;
		return true;							// else return true
	}
}

bool CdsPic::ReadSlave2W(UCHAR &data, bool ACK)
{	// reads slave w/ or wo/ACK, returns data and success
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]= 0xA2;			// Load buf with 2-wire ReadSlave Command
	buf[1]= ACK;			// Second byte determines ACK/NACK for this command
							// ACK=1, send read with ACK, ACK=0, read with NACK
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,2,buf);		// Read for PIC Command Ack (0xb2h, for readslave)
	if(buf[1] != 0xB2)
	{
		data = buf[0];
		return false;						// and return false
	}
	else
	{
		data = buf[0];
		return true;							// else return true
	}
}

bool CdsPic::ResetBoard()
{
	// Just pulse DTR to reset micro
		if (EscapeCommFunction(ComID[0], CLRDTR))
		{
			if (EscapeCommFunction(ComID[0], SETDTR))
				return TRUE;
			else
				return FALSE;
		}		
		else
			return FALSE;
}

bool CdsPic::Start2W()
{	//Sends Start Command, returns success
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xA0;			// Load buf with 2-wire Start Command
	buf[1]=0x00;			// Second byte dummy byte for this command
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xb0h, for start)
	if(buf[0] != 0xB0)
		return false;						// and return false
	return true;							// else return true
}
bool CdsPic::Stop2W()
{	//Sends Stop Command, returns success
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xA3;			// Load buf with 2-wire Stop Command
	buf[1]=0x00;			// Second byte dummy byte for this command
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xb3h, for stop)
	if(buf[0] != 0xB3)
		return false;						// and return false
	return true;							// else return true
}

bool CdsPic::ToggleSCL9x()
{	//Sends Toggle SCL9 Command, returns success
	// toggles SCL 9 times to enable the slave to output data and ready for a stop
	// command.  When followed by a stop command the bus should be free and reset.

	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xA4;			// Load buf with 2-wire Toggle SCL 9x Command
	buf[1]=0x00;			// Second byte dummy byte for this command
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xb4h, for toggle9x command)
	if(buf[0] != 0xB4)
		return false;						// and return false
	return true;							// else return true
}

bool CdsPic::Write1(bool state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xF1;			// Load buf with write1 Command
	buf[1]=state;			// Second byte pin state to write
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] != 0xF0)
		return false;						// and return false
	return true;							// else return true
}

bool CdsPic::Write2(bool state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xF2;			// Load buf with write2 Command
	buf[1]=state;			// Second byte pin state to write
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] != 0xF0)
		return false;						// and return false
	return true;							// else return true
}

bool CdsPic::Write3(bool state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xF3;			// Load buf with write3 Command
	buf[1]=state;			// Second byte pin state to write
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] != 0xF0)
		return false;						// and return false
	return true;							// else return true
}

bool CdsPic::Write4(bool state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xF4;			// Load buf with write4 Command
	buf[1]=state;			// Second byte pin state to write
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] != 0xF0)
		return false;						// and return false
	return true;							// else return true
}

bool CdsPic::Write5(bool state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xF5;			// Load buf with write5 Command
	buf[1]=state;			// Second byte pin state to write
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] != 0xF0)
		return false;						// and return false
	return true;							// else return true
}

bool CdsPic::Write6(bool state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xF6;			// Load buf with write6 Command
	buf[1]=state;			// Second byte pin state to write
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] != 0xF0)
		return false;						// and return false
	return true;							// else return true
}

bool CdsPic::Write7(bool state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xF7;			// Load buf with write7 Command
	buf[1]=state;			// Second byte pin state to write
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] != 0xF0)
		return false;						// and return false
	return true;							// else return true
}

bool CdsPic::Write8(bool state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xF8;			// Load buf with write8 Command
	buf[1]=state;			// Second byte pin state to write
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] != 0xF0)
		return false;						// and return false
	return true;							// else return true
}

bool CdsPic::Write9(bool state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xF9;			// Load buf with write9 Command
	buf[1]=state;			// Second byte pin state to write
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] != 0xF0)
		return false;						// and return false
	return true;							// else return true
}

bool CdsPic::Write10(bool state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xFA;			// Load buf with write10 Command
	buf[1]=state;			// Second byte pin state to write
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] != 0xF0)
		return false;						// and return false
	return true;							// else return true
}


bool CdsPic::Write11(bool state)
{
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xFB;			// Load buf with write11 Command
	buf[1]=state;			// Second byte pin state to write
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xf0h)
	if(buf[0] != 0xF0)
		return false;						// and return false
	return true;							// else return true

}

bool CdsPic::WriteSlave2W(UCHAR data)
{	// writes data to slave returns success based on slave acknoledgement
	unsigned char buf[2];	// Local Rx/Tx com buffer 
	FlushCOM(0);			// Clear COM Port Hardware Buffers
	buf[0]=0xA1;			// Load buf with 2-wire Write Slave Command
	buf[1]=data;			// Second byte data byte for this command
	WriteCOM(0,2,buf);		// Send Data via Serial Port
	ReadCOM(0,1,buf);		// Read for PIC Command Ack (0xb1h, for write slave command)
	if(buf[0] != 0xB1)
		return false;						// and return false
	return true;							// else return true
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -