📄 busio.c
字号:
/* Send the contest of C0 */
SendI2CByte(0xBC);
if(NoAck) goto buserror;
SendI2CStop();
/* ------------- Finish C0 -------------- */
/* ---- I2C Start and send slave address for 78 ---- */
GoI2CMaster(SLAVEADDR_REGW);
if(NoAck | BusFault) goto buserror;
/* Send command */
SendI2CByte(WRITE_BYTE);
if(NoAck) goto buserror;
/* Send C0 */
SendI2CByte(0x78);
if(NoAck) goto buserror;
/* Send the contest of C0 */
SendI2CByte(c0);
if(NoAck) goto buserror;
SendI2CStop();
/* ------------- Finish 78 -------------- */
if(index > 511)
{
index -= 512;
/* ---- I2C Start and send slave address for C0 ---- */
GoI2CMaster(SLAVEADDR_REGW);
if(NoAck | BusFault) goto buserror;
/* Send command */
SendI2CByte(WRITE_BYTE);
if(NoAck) goto buserror;
/* Send C0 */
SendI2CByte(0xC0);
if(NoAck) goto buserror;
/* Send the contest of C0 */
SendI2CByte(0x3D);
if(NoAck) goto buserror;
SendI2CStop();
/* ------------- Finish C0 -------------- */
}
else if (index > 255 & index<512)
{
index -= 256;
/* ---- I2C Start and send slave address for C0 ---- */
GoI2CMaster(SLAVEADDR_REGW);
if(NoAck | BusFault) goto buserror;
/* Send command */
SendI2CByte(WRITE_BYTE);
if(NoAck) goto buserror;
/* Send C0 */
SendI2CByte(0xC0);
if(NoAck) goto buserror;
/* Send the contest of C0 */
SendI2CByte(0x01);
if(NoAck) goto buserror;
SendI2CStop();
/* ------------- Finish C0 -------------- */
}
else
{
/* ---- I2C Start and send slave address for C0 ---- */
GoI2CMaster(SLAVEADDR_REGW);
if(NoAck | BusFault) goto buserror;
/* Send command */
SendI2CByte(WRITE_BYTE);
if(NoAck) goto buserror;
/* Send C0 */
SendI2CByte(0xC0);
if(NoAck) goto buserror;
/* Send the contest of C0 */
SendI2CByte(0x00);
if(NoAck) goto buserror;
SendI2CStop();
/* ------------- Finish C0 -------------- */
}
}
else //(c0 > 0x03)
{
if (index > 255)
{
c0++;
index -= 256;
}
/* ---- I2C Start and send slave address for C0 ---- */
GoI2CMaster(SLAVEADDR_REGW);
if(NoAck | BusFault) goto buserror;
/* Send command */
SendI2CByte(WRITE_BYTE);
if(NoAck) goto buserror;
/* Send C0 */
SendI2CByte(0xC0);
if(NoAck) goto buserror;
/* Send the contest of C0 */
SendI2CByte(c0);
if(NoAck) goto buserror;
SendI2CStop();
/* ------------- Finish C0 -------------- */
}
/* ---- I2C Start and send slave address for C1 ---- */
GoI2CMaster(SLAVEADDR_REGW);
if(NoAck | BusFault) goto buserror;
/* Send command */
SendI2CByte(WRITE_BYTE);
if(NoAck) goto buserror;
/* Send C1 */
SendI2CByte(0xC1);
if(NoAck) goto buserror;
SendI2CByte(index);
if(NoAck) goto buserror;
SendI2CStop();
/* ------------- Finish C1 -------------- */
/* ---- I2C Start and send slave address for C2 ---- */
GoI2CMaster(SLAVEADDR_REGW);
if(NoAck | BusFault) goto buserror;
/* Send command */
SendI2CByte(WRITE_AUTOINC);
if(NoAck) goto buserror;
/* Send C2 */
SendI2CByte(0xC2);
if(NoAck) goto buserror;
/* data transmit */
for(byteCnt = cnt; byteCnt > 0; byteCnt--) {
SendI2CByte(*s++);
if(NoAck) goto buserror;
}
goto endi2c;
/* ------------- Finish C2 -------------- */
buserror:
#if DEBUGMSG
printf("BUS error (PortDataOut) !!!!\n");
#endif
endi2c:
SendI2CStop();
#if DISABLEINT0
/* restove interrupt 0 flag */
EX0 = IntFlag;
#endif
}
/*********************************************
* Send bytes of data to standard device *
**********************************************/
void eepByteOut(unsigned int index, unsigned char val)
{
unsigned char slv;
#if DISABLEINT0
bit IntFlag;
/* disable interrupt 0 */
IntFlag = EX0;
EX0 = 0;
#endif
WPPin = 0;
if(index < 256)
slv = SLAVEADDR_EEPW0;
else
if(index < 512) {
slv = SLAVEADDR_EEPW1;
index -= 256;
} else
if(index < 768) {
slv = SLAVEADDR_EEPW2;
index -= 512;
} else {
slv = SLAVEADDR_EEPW3;
index -= 768;
}
/* I2C Start and send WRITE slave address */
GoI2CMaster(slv);
if(NoAck | BusFault) goto buserror;
/* Send index */
SendI2CByte((unsigned char)index);
if(NoAck) goto buserror;
/* data transmit */
SendI2CByte(val);
//miscDelay(20);
goto endi2c;
buserror:
#if DEBUGMSG
printf("BUS error (eepByteOut) !!!!\n");
#endif
endi2c:
SendI2CStop();
miscDelay(15);
// WPPin = 1;
#if DISABLEINT0
/* restove interrupt 0 flag */
EX0 = IntFlag;
#endif
}
unsigned char eepByteIn(unsigned int index)
{
unsigned char bval;
unsigned char slv;
if(index < 256)
slv = SLAVEADDR_EEPW0;
else
if(index < 512) {
slv = SLAVEADDR_EEPW1;
index -= 256;
} else
if(index < 768) {
slv = SLAVEADDR_EEPW2;
index -= 512;
} else {
slv = SLAVEADDR_EEPW3;
index -= 768;
}
/* I2C Start and send WRITE slave address */
GoI2CMaster(slv);
if(NoAck | BusFault) goto buserror;
/* Send index */
SendI2CByte((unsigned char) index);
if(NoAck) goto buserror;
/* I2C Start and send READ slave address */
GoI2CMaster(slv | 0x01);
if(NoAck) goto buserror;
/* data transmit */
bval = RcvI2CByte(1);
goto endi2c;
buserror:
#if DEBUGMSG
printf("BUS error (eepByteIn) !!!!\n");
#endif
endi2c:
/* Finish trasmition */
SendI2CStop();
return(bval);
}
/**********************************************
* Receive bytes of data from Standard device *
***********************************************/
void eepDataIn(unsigned int index, unsigned char *s, int cnt)
{
int data byteCnt;
unsigned char slv;
if(index < 256)
slv = SLAVEADDR_EEPW0;
else
if(index < 512) {
slv = SLAVEADDR_EEPW1;
index -= 256;
} else
if(index < 768) {
slv = SLAVEADDR_EEPW2;
index -= 512;
} else {
slv = SLAVEADDR_EEPW3;
index -= 768;
}
/* I2C Start and send WRITE slave address */
GoI2CMaster(slv);
if(NoAck | BusFault) goto buserror;
/* Send index */
SendI2CByte((unsigned char) index);
if(NoAck) goto buserror;
/* I2C Start and send READ slave address */
GoI2CMaster(slv | 0x01);
if(NoAck) goto buserror;
/* data transmit */
for(byteCnt = cnt; byteCnt > 0; byteCnt--) {
*s++ = RcvI2CByte(byteCnt);
}
goto endi2c;
buserror:
#if DEBUGMSG
printf("BUS error (eepDataIn) !!!!\n");
#endif
endi2c:
/* Finish trasmition */
SendI2CStop();
}
/*********************************************
* Send bytes of data to standard device *
**********************************************/
void eepDataOut(unsigned int index, unsigned char *s, int cnt)
{
int data byteCnt = cnt;
unsigned char data slv,i;
#if DISABLEINT0
bit IntFlag;
/* disable interrupt 0 */
IntFlag = EX0;
EX0 = 0;
#endif
WPPin = 0;
if(index < 256)
{
slv = SLAVEADDR_EEPW0;
}
else if(index < 512)
{
slv = SLAVEADDR_EEPW1;
index -= 256;
}
else if(index < 768)
{
slv = SLAVEADDR_EEPW2;
index -= 512;
}
else
{
slv = SLAVEADDR_EEPW3;
index -= 768;
}
while(1)
{
// Slave addr
GoI2CMaster(slv);
if(NoAck | BusFault) goto buserror;
// Start addr
SendI2CByte(index);
if(NoAck) goto buserror;
// Send Data
for (i = 0; i < 8; i++)
{
SendI2CByte(*s++);
if(NoAck) goto buserror;
if(--byteCnt == 0) goto endi2c;
index++;
if((index % 16 )== 0)
{
if(index == 256)
{
index = 0;
slv += 2;
}
break;
}
}
SendI2CStop();
miscDelay(15);
}
goto endi2c;
buserror:
#if DEBUGMSG
printf("BUS error (eepDataOut) !!!!\n");
#endif
endi2c:
SendI2CStop();
miscDelay(15);
// WPPin = 1;
#if DISABLEINT0
/* restove interrupt 0 flag */
EX0 = IntFlag;
#endif
}
/*********************************************
* Send data table to Philips TDA8752 *
**********************************************/
void TDADataTableOut(unsigned char *tbl)
{
RegDataOut(0x18, tbl, 4);
}
/*********************************************
* Set Att. Data *
**********************************************/
void SetOSDData(unsigned int index, unsigned char OSDfunction, unsigned char Data, unsigned int cnt)
{
int data byteCnt;
RegByteOut(0xC0, 0xBC); // Select OSD Registers
RegByteOut(0x78, OSDfunction); // OR78 - Select Update Att
if (index > 255)
{
RegByteOut(0xC0, 0x01);
index -= 256;
}
else
{
RegByteOut(0xC0, 0x00);
}
RegByteOut(0xC1, index);
// ---- I2C Start and send slave address for C2 ---- */
GoI2CMaster(SLAVEADDR_REGW);
if(NoAck | BusFault) goto buserror;
/* Send command */
SendI2CByte(WRITE_AUTOINC);
if(NoAck) goto buserror;
/* Send C2 */
SendI2CByte(0xC2);
if(NoAck) goto buserror;
/* data transmit */
for(byteCnt = cnt; byteCnt > 0; byteCnt--)
{
SendI2CByte(Data);
if(NoAck) goto buserror;
}
/* ------------- Finish C2 -------------- */
buserror:
SendI2CStop();
RegByteOut(0xC0, 0x3C); // Select Normal Registers
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -