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

📄 busio.c

📁 采用台湾MRT晶捷公司的MRT4方案的液晶电视的程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************
*                                               *
* BUSIO.C:  IO control routines.                *
*                                               *
*************************************************/
#include "mascot.h"
#include <reg51.h>
#include "global.h"


/**********************************************
* Send Table data to Mascot regs              *
***********************************************/
void RegDataTableOut(unsigned char *s)
{
	unsigned char cnd, index;

	while ((cnd = *s++) != -1) {
		index = *s++;
		RegDataOut(index, s, cnd);
		s += cnd;
	}
}


/**********************************************
* Receive byte of data from Mascot regs       *
***********************************************/
unsigned char RegByteIn(unsigned char index)
{
	unsigned char data val;

#if DISABLEINT0
	bit IntFlag;

	/* disable interrupt 0 */
	IntFlag = EX0;
	EX0 = 0;
#endif


	/* I2C Start and send slave address */
 	GoI2CMaster(SLAVEADDR_REGW);
	if (NoAck | BusFault) goto buserror;

	/* Send comm */
	SendI2CByte(READ_BYTE);
	if (NoAck) goto buserror;

	/* Send index */
	SendI2CByte(index);
	if (NoAck) goto buserror;

	SendI2CStop();

	/* I2C Start and send slave address */
 	GoI2CMaster(SLAVEADDR_REGR);
	if (NoAck | BusFault) goto buserror;

	/* data transmit */
	val = RcvI2CByte(1);

endi2c:
	/* Finish transmition */
	SendI2CStop();




#if DISABLEINT0
	/* restove interrupt 0 flag */
	EX0 =	IntFlag;
#endif

	return(val);

buserror:
#if DEBUGMSG
   printf("  BUS error (RegByteIn) !!!!\n");
#endif
    goto endi2c;
}

/**********************************************
* Receive bytes of data from Mascot regs      *
***********************************************/
void RegDataIn(unsigned char index, unsigned char *s, int cnt)
{
	int data byteCnt;

#if DISABLEINT0
	bit IntFlag;

	/* disable interrupt 0 */
	IntFlag = EX0;
	EX0 = 0;
#endif


	/* I2C Start and send slave address */
 	GoI2CMaster(SLAVEADDR_REGW);
	if (NoAck | BusFault) goto buserror;

	/* Send comm */
	SendI2CByte(READ_AUTOINC);
	if (NoAck) goto buserror;

	/* Send index */
	SendI2CByte(index);
	if (NoAck) goto buserror;

	SendI2CStop();

	/* I2C Start and send slave address */
 	GoI2CMaster(SLAVEADDR_REGR);
	if (NoAck | BusFault) goto buserror;

	/* data transmit */
	for(byteCnt = cnt; byteCnt > 0; byteCnt--) {
		*s++ = RcvI2CByte(byteCnt);
	}
	
endi2c:
	/* Finish transmition */
	SendI2CStop();



#if DISABLEINT0
	/* restove interrupt 0 flag */
	EX0 =	IntFlag;
#endif
    return;

buserror:
#if DEBUGMSG
   printf("    BUS error (RegDataIn) !!!!\n");
#endif   
    goto endi2c;
}

/**********************************************
* Write byte of data to Mascot regs           *
***********************************************/
void RegByteOut(unsigned char index, unsigned char val)
{
#if DISABLEINT0
	bit IntFlag;

	/* disable interrupt 0 */
	IntFlag = EX0;
	EX0 = 0;
#endif


	/* I2C Start and send slave address */
 	GoI2CMaster(SLAVEADDR_REGW);
	if (NoAck | BusFault) goto buserror;

	/* Send comm */
	SendI2CByte(WRITE_BYTE);
	if (NoAck) goto buserror;

	/* Send index */
	SendI2CByte(index);
	if (NoAck) goto buserror;

	/* data transmit */
	SendI2CByte(val);
 
endi2c:
	/* Finish transmition */
	SendI2CStop();




#if DISABLEINT0
	/* restove interrupt 0 flag */
	EX0 =	IntFlag;
#endif
    return;

buserror:
#if DEBUGMSG
   printf("    BUS error (RegByteOut) !!!!\n");
#endif   
    goto endi2c;
}


/**********************************************
* Write byte of data to Mascot regs           *
***********************************************/
void RegWordOut(unsigned char index, unsigned int val)
{
    unsigned char b[2];

    b[0] = val;
    b[1] = val>>8;
    RegDataOut(index, b, 2);
}


/**********************************************
* Write bit(s) of data to Mascot reg          *
***********************************************/
void RegBitOut(unsigned char index, unsigned char val, unsigned char mask)
{
	unsigned char b;
	
    b = RegByteIn(index);
	b = (b & ~mask) | val;
	RegByteOut(index, b);
}

/**********************************************
* Write bytes of data to Mascot regs          *
***********************************************/
void RegDataOut(unsigned char index, unsigned char *s, int cnt)
{
	int data byteCnt;

#if DISABLEINT0
	bit IntFlag;

	/* disable interrupt 0 */
	IntFlag = EX0;
	EX0 = 0;
#endif

	/* I2C Start and send slave address */
 	GoI2CMaster(SLAVEADDR_REGW);
	if (NoAck | BusFault) goto buserror;

	/* Send comm */
	SendI2CByte(WRITE_AUTOINC);
	if (NoAck) goto buserror;

	/* Send index */
	SendI2CByte(index);
	if (NoAck) goto buserror;

	/* data transmit */
	for(byteCnt = cnt; byteCnt > 0; byteCnt--) {
		SendI2CByte(*s++);
		if (NoAck) goto buserror;
	}

endi2c:   
	/* Finish transmition */
	SendI2CStop();



#if DISABLEINT0
	/* restove interrupt 0 flag */
	EX0 =	IntFlag;
#endif
    return;

buserror:
#if DEBUGMSG
    printf("    BUS error (RegDataOut) !!!!\n");
#endif
	goto endi2c;
}




 

/**********************************************
* Receive byte of data from Mascot regs       *
***********************************************/
unsigned char OSDRegByteIn(unsigned char index)
{
	unsigned char data val;

#if DISABLEINT0
	bit IntFlag;

	/* disable interrupt 0 */
	IntFlag = EX0;
	EX0 = 0;
#endif


	RegByteOut(0xC0, 0xBC);	// Select OSD Registers

	/* I2C Start and send slave address */
 	GoI2CMaster(SLAVEADDR_REGW);
	if (NoAck | BusFault) goto buserror;

	/* Send comm */
	SendI2CByte(READ_BYTE);
	if (NoAck) goto buserror;

	/* Send index */
	SendI2CByte(index);
	if (NoAck) goto buserror;

	SendI2CStop();

	/* I2C Start and send slave address */
 	GoI2CMaster(SLAVEADDR_REGR);
	if (NoAck | BusFault) goto buserror;

	/* data transmit */
	val = RcvI2CByte(1);

endi2c:
	/* Finish transmition */
	SendI2CStop();
	RegByteOut(0xC0, 0x3C);	// Select Normal Registers


#if DISABLEINT0
	/* restove interrupt 0 flag */
	EX0 =	IntFlag;
#endif

	return(val);

buserror:
#if DEBUGMSG
   printf("  BUS error (RegByteIn) !!!!\n");
#endif
    goto endi2c;
}

/**********************************************
* Write bit(s) of data to Mascot reg          *
***********************************************/
void OSDRegBitOut(unsigned char index, unsigned char val, unsigned char mask)
{
	unsigned char b;
	
	RegByteOut(0xC0, 0xBC);	// Select OSD Registers
	
	b = RegByteIn(index);
	b = (b & ~mask) | val;
	OSDRegByteOut(index, b);
	
	RegByteOut(0xC0, 0x3C);	// Select Normal Registers
}

/**********************************************
* Write byte of data to Mascot regs           *
***********************************************/
void OSDRegByteOut(unsigned char index, unsigned char val)
{
#if DISABLEINT0
	bit IntFlag;

	/* disable interrupt 0 */
	IntFlag = EX0;
	EX0 = 0;
#endif


	RegByteOut(0xC0, 0xBC);	// Select OSD Registers
	
	/* I2C Start and send slave address */
 	GoI2CMaster(SLAVEADDR_REGW);
	if (NoAck | BusFault) goto buserror;

	/* Send comm */
	SendI2CByte(WRITE_BYTE);
	if (NoAck) goto buserror;

	/* Send index */
	SendI2CByte(index);
	if (NoAck) goto buserror;

	/* data transmit */
	SendI2CByte(val);
 
endi2c:
	/* Finish transmition */
	SendI2CStop();
	RegByteOut(0xC0, 0x3C);	// Select Normal Registers


#if DISABLEINT0
	/* restove interrupt 0 flag */
	EX0 =	IntFlag;
#endif
    return;

buserror:
#if DEBUGMSG
   printf("    BUS error (RegByteOut) !!!!\n");
#endif   
    goto endi2c;
}

/**********************************************
* Write bytes of data to Mascot regs          *
***********************************************/
void OSDRegDataOut(unsigned char index, unsigned char *s, int cnt)
{
	int data byteCnt;

#if DISABLEINT0
	bit IntFlag;

	/* disable interrupt 0 */
	IntFlag = EX0;
	EX0 = 0;
#endif


	RegByteOut(0xC0, 0xBC);	// Select OSD Registers
	
	/* I2C Start and send slave address */
 	GoI2CMaster(SLAVEADDR_REGW);
	if (NoAck | BusFault) goto buserror;

	/* Send comm */
	SendI2CByte(WRITE_AUTOINC);
	if (NoAck) goto buserror;

	/* Send index */
	SendI2CByte(index);
	if (NoAck) goto buserror;

	/* data transmit */
	for(byteCnt = cnt; byteCnt > 0; byteCnt--) {
		SendI2CByte(*s++);
		if (NoAck) goto buserror;
	}

endi2c:   
	/* Finish transmition */
	SendI2CStop();
	RegByteOut(0xC0, 0x3C);	// Select Normal Registers


#if DISABLEINT0
	/* restove interrupt 0 flag */
	EX0 =	IntFlag;
#endif
    return;

buserror:
#if DEBUGMSG
    printf("    BUS error (RegDataOut) !!!!\n");
#endif
	goto endi2c;
}



#if USE_TCON
void TconByteOut(unsigned char index, unsigned char val)
{
	RegByteOut(0xC0, 0x40);
    RegByteOut(index, val);
	RegByteOut(0xC0, 0x3C);	// Select Normal Registers
}
#endif 

/*********************************************
* Send bytes of data to an Mascot device     *
**********************************************/
void PortDataOut(int index, unsigned char c0, unsigned char *s, int cnt)
{
	int data byteCnt;

#if DISABLEINT0
	bit IntFlag;

	/* disable interrupt 0 */
	IntFlag = EX0;
	EX0 = 0;
#endif


	if (c0 <= 0x03)	//UPDATE_HCD_REGATT 
	{
		/* ---- 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;

⌨️ 快捷键说明

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