📄 t100_bak.c
字号:
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;
}
}
}
}
uCHAR Repeat_Times;
void KeyFunction(uCHAR cTemp)
{
switch(cTemp)
{
case kyFULL_43://0x40
bFULL_43=!bFULL_43;
SetMode();
if(!bFULL_43)I2CWriteByte(0x50,0xe0,0x00);
else I2CWriteByte(0x50,0xe0,0x9d);
Repeat_Times=0xff;
Delay_ms(50);
break;
case kyUD_LR://0x20
if(bUP_DOWN&bLEFT_RIGHT)
{
bUP_DOWN=0;
bLEFT_RIGHT=0;
}
else if(bUP_DOWN&!bLEFT_RIGHT)
{
bUP_DOWN=1;
bLEFT_RIGHT=1;
}
else if(!bUP_DOWN&bLEFT_RIGHT)
{
bUP_DOWN=1;
bLEFT_RIGHT=0;
}
else if(!bUP_DOWN&!bLEFT_RIGHT)
{
bUP_DOWN=0;
bLEFT_RIGHT=1;
}
SetUD_LR();
Repeat_Times=0xff;
I2CWriteByte(0x50,0xe0,0x8d);
Delay_ms(50);
break;
case kySOURCE://0x10
cSource++;
if(cSource>6)cSource=3;
SetSource();
SetMode();
Repeat_Times=0xff;
Delay_ms(50);
break;
#ifdef OSD_EN
case kyMENU://0x08
cOSDFunc+=1;
if(cOSDFunc>3)cOSDFunc=0;
OSDCtrl(0);
Repeat_Times=0xff;
break;
case kyDEC://0x04
OSDCtrl(-1);
if(Repeat_Times==0xff)Repeat_Times=5;
else Repeat_Times=0;
break;
case kyINC://0x02
OSDCtrl(1);
if(Repeat_Times==0xff)Repeat_Times=5;
else Repeat_Times=0;
break;
default: Repeat_Times=0xff;
#endif
}
}
void kyKeypad(void)
{
cKey_Curr =0xff -( KEYPORT | kyKEY_MSK );
if((cKey_Curr!=cKey_Pre)|(Repeat_Times==0))
{
cKey_Pre = cKey_Curr;
KeyFunction(cKey_Curr);
/* switch(cKey_Curr)
{
case kyFULL_43://0x40
bFULL_43=!bFULL_43;
SetMode();
if(!bFULL_43)I2CWriteByte(0x50,0xe0,0x00);
else I2CWriteByte(0x50,0xe0,0x9d);
Repeat_Times=0xff;
Delay_ms(50);
break;
case kyUD_LR://0x20
SetUD_LR();
Repeat_Times=0xff;
I2CWriteByte(0x50,0xe0,0x8d);
Delay_ms(50);
break;
case kySOURCE://0x10
cSource++;
if(cSource>6)cSource=3;
SetSource();
SetMode();
Repeat_Times=0xff;
Delay_ms(50);
break;
#ifdef OSD_EN
case kyMENU://0x08
cOSDFunc+=1;
if(cOSDFunc>3)cOSDFunc=0;
OSDCtrl(0);
Repeat_Times=0xff;
break;
case kyDEC://0x04
OSDCtrl(-1);
if(Repeat_Times==0xff)Repeat_Times=5;
else Repeat_Times=0;
break;
case kyINC://0x02
OSDCtrl(1);
if(Repeat_Times==0xff)Repeat_Times=5;
else Repeat_Times=0;
break;
default: Repeat_Times=0xff;
#endif
}//*/
/* if(!kyFULL_43) //P0^6
{
bFULL_43=!bFULL_43;
SetMode();
}
if(!kyUD_LR) //P0^5
SetUD_LR();
if(!kySOURCE) //P0^4
{
cSource++;
if(cSource>6)cSource=2;
SetSource();
SetMode();
}
/* P0 = 0xff;
cKey_Curr = 0xff -( P0 | 0x8F );*/
//Delay_ms(2);
}
else if(cKey_Curr&0x06){Repeat_Times-=1;Delay_ms(2);}
}
#ifdef OSD_EN
void OSDShowLine(uCHAR *string,uCHAR x,uCHAR y,uCHAR cColor);
void OSDDrawGauge(uCHAR cVal, uCHAR cMax, 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<36*18; i++){
Send_Byte(font_00[2*i]);
Send_Byte(font_00[2*i+1]);
}
//0xc00==1024*3;
for(; i<0xc00; 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,2,COL_NORMAL);
OSDShowLine(i4_3_ICON,LINE_LENGTH-2,3,COL_NORMAL);
}
void ShowOSDData(void)
{
uCHAR i;
switch(cOSDFunc)
{
case 1:
OSDDrawGauge(cBright,0x10,2,0,COL_GAUGE);
break;
case 2:
OSDDrawGauge(cColor,0x10,2,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 cMax, uCHAR x, uCHAR y, uCHAR cColor)
{
uCHAR cTemp1,cTemp2,i=8;
int wTemp,wTemp1,wTemp2;
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/100;
cTemp1=(cVal%100)/10;
cTemp2=cVal%10;//*/
OSDSetRamAddr(MENU_START_ADDR+((int)(y-1) << 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]=0x38+(cOSDFunc-1)*2;
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 + -