📄 t100.c
字号:
cAcknowledge = 0;
for(ix = 0; ix < 8; ix++)
{
Set_SCL_Low;
for(j = 0; j < TWD_SHORT_TIME; j++)
{ };
if(cData&0x80)Set_SDA_High;
else Set_SDA_Low;
cData<<=1;
for(j = 0; j < TWD_SHORT_TIME; j++)
{ };
Set_SCL_High;
while(SCL_Low && ++cTWtrytime)
{ };
for(j = 0; j < TWD_SHORT_TIME; j++)
{ };
}
for(j = 0; j < TWD_SHORT_TIME; j++)
{ };
Set_SCL_Low;
for(j = 0; j < TWD_SHORT_TIME; j++)
{ };
Set_SDA_High; /* release data line for acknowledge */
for(j = 0; j < TWD_SHORT_TIME; j++)
{ };
Set_SCL_High; /* Send a clock for Acknowledge */
while(SCL_Low)
{ };
for(j = 0; j < TWD_SHORT_TIME; j++)
{ };
if(SDA_High) cAcknowledge = 1; /* No Acknowledge */
Set_SCL_Low; /* Finish Acknoledge */
for(j = 0; j < TWD_SHORT_TIME; j++)
{ };
return(cAcknowledge);
}
//--------------------------------------------------
// Read_Byte
// Read a byte from master with a acknowledge bit
//--------------------------------------------------
uCHAR Read_Byte(uCHAR cNum)
{
uCHAR ix, j;
uCHAR cRetval=0;
for(ix=0;ix<8;ix++){
Set_SCL_High;
while(SCL_Low){};
for(j=0;j<TWD_SHORT_TIME;j++){};
cRetval = (SDA_High)? (cRetval|(1<<(7-ix))):cRetval ; /* MSB First */
Set_SCL_Low;
}
if(cNum==1)
Set_SDA_High;
else
Set_SDA_Low;
//SDA = (cNum==1) 1:0;
Set_SCL_High;
while(SCL_Low){};
for(j = 0; j < TWD_SHORT_TIME; j++)
{ };
Set_SCL_Low;
Set_SDA_High;
for(j = 0; j < TWD_SHORT_TIME; j++)
{ };
return cRetval;
}
uCHAR I2CReadByte(uCHAR cAddr, uCHAR cReg)
{
uCHAR cTemp;
StartCondition();
Send_Byte(cAddr);
Send_Byte(cReg);
StartCondition();
Send_Byte(cAddr|0x01);
cTemp=Read_Byte(1);
StopCondition();
return cTemp;
}
uCHAR I2CWriteByte(uCHAR cAddr,uCHAR cReg,uCHAR cData)
{
StartCondition();
Send_Byte(cAddr);
Send_Byte(cReg);
Send_Byte(cData);
StopCondition();
return 0;
}
void I2CWriteTbl(char *pString)
{
uCHAR cAddr,cReg,cNum0,cNum1,cINC;
while(*pString != EOT)
{
cAddr = *pString++;
cNum0 = *pString++;
while(cNum0)
{
cReg = *pString++;
cNum1 = *pString++;
cNum0 -= (cNum1+2);
if(cNum1!=1)
{
cINC = *pString++;
cNum1 -= 1;
}
while(cNum1--)
{
I2CWriteByte(cAddr,cReg,*pString++);
cReg+=cINC;
}
}
}
}
//****************************************************************
#ifdef OSD_EN
void OSDShowLine(uCHAR *string,uCHAR x,uCHAR y,uCHAR cColor);
void OSDDrawGauge(uCHAR cVal, uCHAR x, uCHAR y, uCHAR cColor);
void LoadFont(void);
void LoadMenu(void);
void ShowOSDData(void);
void LoadData(void);
void SaveData(void);
void InitOSD(void)
{
LoadFont();
LoadMenu();
LoadData();
ShowOSDData();
OSDDisable();
}
void LoadFont(void)
{
unsigned int i;
StartCondition();
Send_Byte(0x50);
Send_Byte(0xA4);
for(i=0; i<35*18; i++){
Send_Byte(font_00[2*i]);
Send_Byte(font_00[2*i+1]);
}
//0xc00==1024*3;
for(; i<0x360; i++){
Send_Byte(0x00);
Send_Byte(0x00);
}//*/
StopCondition();
}
void LoadMenu(void)
{
uCHAR i;
for(i=0;i<4;i++)
{
OSDShowLine(iBlankLine,0,i,COL_NORMAL);
}
OSDShowLine(iBright_ICON,0,0,COL_NORMAL);
OSDShowLine(iColor_ICON,0,1,COL_NORMAL);
OSDShowLine(iScreen_ICON,0,2,COL_NORMAL);
OSDShowLine(iScreen_ICON,0,3,COL_NORMAL);
OSDShowLine(iFULL_ICON,LINE_LENGTH-2,3,COL_NORMAL);
OSDShowLine(i4_3_ICON,LINE_LENGTH-3,2,COL_NORMAL);
OSDDrawGauge(cColor,3,1,COL_GAUGE);
OSDDrawGauge(cBright,3,0,COL_GAUGE);
}
void ShowOSDData(void)
{
switch(cOSDFunc)
{
case 1:
OSDDrawGauge(cBright,3,0,COL_GAUGE);
break;
case 2:
OSDDrawGauge(cColor,3,1,COL_GAUGE);
break;
case 3: break;
}
}
void OSDSetRamAddr(int address)
{
I2CWriteByte(TW100,0xA3,(uCHAR)(address>>8));
I2CWriteByte(TW100,0xA2,(uCHAR)(address & 0xff));
}
void OSDShowLine(uCHAR *string,uCHAR x,uCHAR y,uCHAR cColor)
{
if((x < 30) && ( y < 0x28))
{
OSDSetRamAddr(MENU_START_ADDR+((int)y << 5)+x);
StartCondition();
Send_Byte(0x50);
Send_Byte(0xA4);
while((*string) != EOL && (x < LINE_LENGTH))
{
Send_Byte(*string++);
Send_Byte(cColor );
x++;
}
StopCondition();
}
}
void OSDDrawGauge(uCHAR cVal, uCHAR x, uCHAR y, uCHAR cColor)
{
uCHAR cTemp1,cTemp2,i=8;
cTemp1=cVal/2;
cTemp2=cVal%2;
OSDSetRamAddr(MENU_START_ADDR+((int)y << 5)+x);
StartCondition();
Send_Byte(0x50);
Send_Byte(0xA4);
while(i)
{
if(cTemp1==0)
{
if(i==8)Send_Byte(0x0A+cTemp2);
else if(i==1)Send_Byte(0x10+cTemp2);
else Send_Byte(0x0D+cTemp2);
Send_Byte(cColor);
i--;
break;
}
else
{
if(i==8)Send_Byte(0x0C);
else if(i==1)Send_Byte(0x12);
else Send_Byte(0x0F);
}
Send_Byte(cColor);
cTemp1--;
i--;
}
while(i)
{
if(i>1)Send_Byte(0x0D);
else Send_Byte(0x10);
Send_Byte(cColor);
i--;
}
StopCondition();
//Num
cTemp1=cVal/10;
cTemp2=cVal%10;
i=cVal/10;
/* cTemp1=(cVal%100)/10;
cTemp2=cVal%10;//*/
OSDSetRamAddr(MENU_START_ADDR+((int)(y) << 5)+(LINE_LENGTH-2));
StartCondition();
Send_Byte(0x50);
Send_Byte(0xA4);
if(i)Send_Byte(i+0x13);
else Send_Byte(BLANK);
Send_Byte(cColor);
Send_Byte(cTemp2+0x13);
Send_Byte(cColor);
StopCondition();
}
void OSDDisable(void)
{
I2CWriteTbl(OSDDisableTbl);
}
void OSDEnable(void)
{
uCHAR cTemp[8];
cTemp[0]=TW100;
cTemp[1]=5;
cTemp[2]=0xa0;
cTemp[3]=3;
cTemp[4]=Y_INC;
cTemp[5]=0x05;
cTemp[6]=23+(cOSDFunc-1);
if((cOSDFunc==3)&&bFULL_43)cTemp[6]+=1;
cTemp[7]=EOT;
I2CWriteTbl(cTemp);
cTemp[5]=0x1E;
I2CWriteTbl(cTemp);
I2CWriteTbl(OSDEnableTbl);
}
void OSDCtrl(char cDir)
{
uCHAR cTemp;
switch(cOSDFunc)
{
case 0: OSDDisable();return;
case 1:
if((cBright==0x10)&&(cDir==1))return;
if((cBright==0x00)&&(cDir==-1))return;
cBright+=cDir;
if(cBright<16)cTemp=cBright*16;
else cTemp=0xff;
I2CWriteByte(TW100,0x69,cTemp);
break;
case 2:
if((cColor==0xfc)&&(cDir==1))return;
if((cColor==0x00)&&(cDir==-1))return;
cColor+=cDir*4;
if(cColor<16)cTemp=cColor*16;
else cTemp=0xff;
I2CWriteByte(TW100,0x6c,cTemp);
break;
case 3:
if(Repeat_Times==0)return;
if(cDir)
{
bFULL_43=!bFULL_43;
SetMode();
}
break;
}
SaveData();
ShowOSDData();
OSDEnable();
}
void LoadData(void)
{
#ifdef NVRAM
#else
cBright=BRIGHT;
cColor=COLOR;
#endif
}
void SaveData(void)
{
#ifdef NVRAM
#endif
}
#endif
bit m_bBKPowerOn =1;
bit m_bKyPowerOn =1;
bit m_bChipPowerOn =1;
void PowerManage(void)
{
if(m_bKyPowerOn) //Power on
{
I2CWriteByte(TW100, 0xE0, I2CReadByte(TW100, 0xE0)|0x80);
//When power on chip, force to reset chip
m_bChipPowerOn=1;
Delay_ms(50);
OpenPanel();
if(!m_bBKPowerOn)
BL_EN=0;
// BKPower();
}
else //Forced Power Off
{
if(m_bChipPowerOn)
{
Delay_ms(50);
if(m_bBKPowerOn)
BL_EN=1;
// BKPower();
ClosePanel();
Delay_ms(100);
I2CWriteByte(TW100, 0xE0, I2CReadByte(TW100, 0xE0)&0x7F);
m_bChipPowerOn=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -