📄 function.c
字号:
{
Byte i;
code unsigned char V_Scaling[2][53][2] =
{// 8 mode7228_8060
{{0x00, 0xD0}, {0x01, 0x02}, {0x02, 0x20}, {0x03, 0x01}, {0x10, 0x1C}, {0x11, 0x0F}, {0x12, 0x7A},
{0x13, 0x00}, {0x14, 0x00}, {0x15, 0x00}, {0x16, 0x00}, {0x17, 0x00}, {0x19, 0x02}, {0x20, 0xAA},
{0x21, 0x07}, {0x22, 0xFF}, {0x23, 0x0F}, {0x20, 0x65}, {0x21, 0x0E}, {0x22, 0xFF}, {0x23, 0x1F},
{0x24, 0x00}, {0x25, 0x00}, {0x24, 0x00}, {0x25, 0x04}, {0x27, 0x01}, {0xA0, 0x00}, {0xA1, 0x2A},//00,2A,00
{0xA2, 0x00}, {0x90, 0xF8}, {0x91, 0x03}, {0x92, 0x48}, {0x93, 0x00}, {0x94, 0x90}, {0x95, 0x00},
{0x96, 0x20}, {0x97, 0x03}, {0x98, 0x92}, {0x99, 0x02}, {0x9A, 0x13}, {0x9B, 0x00}, {0x9C, 0x26},
{0x9D, 0x00}, {0x9E, 0x58}, {0x9F, 0x02}, {0xD0, 0x0B}, {0xD1, 0x0C}, {0xD2, 0x09}, {0xD3, 0x4C},
{0xD4, 0x01}, {0x29, 0x00}, {0x81, 0x3C}, {0x80, 0x00}
},
// 9 mode7228_8048
{{0x00, 0xD0}, {0x01, 0x02}, {0x02, 0x20}, {0x03, 0x01}, {0x10, 0x1C}, {0x11, 0x0F}, {0x12, 0xBB},
{0x13, 0x00}, {0x14, 0x00}, {0x15, 0x00}, {0x16, 0x00}, {0x17, 0x00}, {0x19, 0x02}, {0x20, 0x96},
{0x21, 0x09}, {0x22, 0xFF}, {0x23, 0x0F}, {0x20, 0x65}, {0x21, 0x0E}, {0x22, 0xFF}, {0x23, 0x1F},
{0x24, 0x00}, {0x25, 0x00}, {0x24, 0x00}, {0x25, 0x04}, {0x27, 0x01}, {0xA0, 0x44}, {0xA1, 0x1B},
{0xA2, 0x00}, {0x90, 0x25}, {0x91, 0x04}, {0x92, 0x35}, {0x93, 0x00}, {0x94, 0x70}, {0x95, 0x00},
{0x96, 0x20}, {0x97, 0x03}, {0x98, 0x0D}, {0x99, 0x02}, {0x9A, 0x03}, {0x9B, 0x00}, {0x9C, 0x1F},
{0x9D, 0x00}, {0x9E, 0xE0}, {0x9F, 0x01}, {0xD0, 0x0D}, {0xD1, 0x0E}, {0xD2, 0x07}, {0xD3, 0x02},
{0xD4, 0x01}, {0x29, 0x00}, {0x81, 0x02}, {0x80, 0x00}
}
};
for(i = 0; i < 53; i++)
I2CWriteByte(HX8824_ADDR, V_Scaling[S][i][0], V_Scaling[S][i][1]);
}
/* -------------------------------------------------------------------
Name : Video_Detect
Purpose :
Passed :
Returns :
Notes :
------------------------------------------------------------------- */
void Video_Detect(void)
{
Byte i, temp1;
// Byte temp2;
Old_Status = New_Status;
for(i = 0;i < 100;i++)
{
/*
if(i==4)
i=5;
I2CWriteByte(SAA7114_ADDR, 0x0e, I2CReadByte(SAA7114_ADDR, 0x0e&0x8f)|(i*16));
I2CWriteByte(SAA7114_ADDR, 0x0e, I2CReadByte(SAA7114_ADDR, 0x0e)&0x7f);
I2CWriteByte(SAA7114_ADDR, 0x0e, I2CReadByte(SAA7114_ADDR, 0x0e)|0x80);
DelayX1ms(5);
*/
//do
//{
// do
// {
temp1= I2CReadByte(SAA7114_ADDR, 0x1F);
// DelayX10ms(2);
// temp2= I2CReadByte(SAA7114_ADDR, 0x1F);
// }while(temp1!=temp2);
//}while((temp1 & 0x01) != 0x01);
}
if((temp1 & 0x40) == 0x00) // video locked
{
bVideo_Status = 1;
if((temp1 & 0x20) == 0x00)
{
b60hz = 0; // PAL
//Puts_UART("PAL!\r\n");
}
else if((temp1 & 0x20) == 0x20)
{
b60hz = 1; // NTSC
//Puts_UART("NTSC!\r\n");
}
New_Status = b60hz;
}
else
{
New_Status = 0x03; // no signal
bVideo_Status = 0; // Video unlocked
}
if(New_Status == Old_Status)
{
Status_Change = 0;
//Puts_UART("Status No Change!\r\n");
}
else
{
Status_Change = 1;
Puts_UART("Video Status Change!\r\n");
}
}
/* -------------------------------------------------------------------
Name : VGA_Detect
Purpose :
Passed :
Returns :
Notes :
------------------------------------------------------------------- */
void VGA_Detect()
{
pre_status = now_status;
now_status = 0x01 & SCDT;
Puts_UART("VGA now Status = ");HexTobyStr(now_status);Puts_UART(byStr);Puts_UART("\r\n");
//Puts_UART("VGA pre Status = ");HexTobyStr(pre_status);Puts_UART(byStr);Puts_UART("\r\n");
if(pre_status == now_status)
{
Status_Change = 0;
//Puts_UART("VGA Status No Change!\r\n");
if(SCDT)
bVGA_Status = 1;
else
bVGA_Status = 0;
}
else
{
Status_Change = 1;
Puts_UART("VGA Status Change!\r\n");
if(SCDT)
bVGA_Status = 1;
else
bVGA_Status = 0;
}
pre_status = 0x01 & SCDT;
Puts_UART("VGA pre Status = ");HexTobyStr(pre_status);Puts_UART(byStr);Puts_UART("\r\n");
}
/* -------------------------------------------------------------------
Name : Stand_alone_mode
Purpose :
Passed :
Returns :
Notes :
------------------------------------------------------------------- */
void Stand_alone_mode()
{
Byte i;
for(i = 0; i < 53; i++)
{
I2CWriteByte(HX8824_ADDR, ModeTbl[5][i][0], ModeTbl[5][i][1]);
}
I2CWriteByte(HX8824_ADDR, 0xA0, 0xFF);
I2CWriteByte(HX8824_ADDR, 0xA1, 0xFF);
I2CWriteByte(HX8824_ADDR, 0xA2, 0xFF);
}
/* -------------------------------------------------------------------
Name : Display
Purpose :
Passed :
Returns :
Notes :
------------------------------------------------------------------- */
void Display()
{
Byte i;
for(i = 0; i < 53; i++)
{
I2CWriteByte(HX8824_ADDR, ModeTbl[Mode][i][0], ModeTbl[Mode][i][1]);
}
Puts_UART("Mode = ");HexTobyStr(Mode);Puts_UART(byStr);Puts_UART("\r\n");
bNo_Signal = 0;
}
/* -------------------------------------------------------------------
Name : Switch_Input
Purpose :
Passed :
Returns :
Notes :
------------------------------------------------------------------- */
void Switch_Input(unsigned char Inp_Source)
{
// Byte temp;
#if EEPROM
I2CWriteByte(EEPROM_MCU | ((EE_SOURCE/256)*2), (EE_SOURCE%256), bSource);
#endif
switch(Inp_Source)
{
case 0: // CVBS
bVideo = 1;
bVGA = 0;
bPanel_Change = 1;
S1 = 0; // switch to CCIR
S2 = 1;
I2CWriteByte(SAA7114_ADDR, 0x02, 0xC4);
I2CWriteByte(SAA7114_ADDR, 0x09, 0x41);
I2CWriteByte(SAA7114_ADDR, 0x0a, 0x80);//72
I2CWriteByte(SAA7114_ADDR, 0x0b, 0x50);//44
I2CWriteByte(SAA7114_ADDR, 0x14, I2CReadByte(SAA7114_ADDR, 0x14)&0xfc|0x02);
ParaAddress = EE_AV1_PARA;
Puts_UART("bVideoAV\r\n");
break;
case 1: // S Video
bVideo = 1;
bVGA = 0;
bPanel_Change = 1;
S1 = 0; // switch to CCIR
S2 = 1;
I2CWriteByte(SAA7114_ADDR, 0x02, 0xC8);
I2CWriteByte(SAA7114_ADDR, 0x09, 0xCC);
I2CWriteByte(SAA7114_ADDR, 0x0a, 0x72);
I2CWriteByte(SAA7114_ADDR, 0x0b, 0x44);
I2CWriteByte(SAA7114_ADDR, 0x14, I2CReadByte(SAA7114_ADDR, 0x14)&0xfc|0x01);
ParaAddress = EE_AV2_PARA;
Puts_UART("bVideoS\r\n");
break;
case 2: // VGA
bVideo = 0;
bVGA = 1;
bPanel_Change = 1;
S1 = 1; // switch to VGA
S2 = 0;
ParaAddress = EE_AV3_PARA;
Puts_UART("bVGA\r\n");
break;
case 3: // Tuner AI24
bVideo = 1;
bVGA = 0;
bPanel_Change = 1;
S1 = 0; // switch to CCIR
S2 = 1;
I2CWriteByte(SAA7114_ADDR, 0x02, 0xC5);
I2CWriteByte(SAA7114_ADDR, 0x09, 0x41);
I2CWriteByte(SAA7114_ADDR, 0x0a, 0x80);//72
I2CWriteByte(SAA7114_ADDR, 0x0b, 0x50);//44
I2CWriteByte(SAA7114_ADDR, 0x14, I2CReadByte(SAA7114_ADDR, 0x14)&0xfc|0x02);
ParaAddress = EE_TV_PARA;
Puts_UART("bTuner\r\n");
break;
default:
break;
}
Signal_Detect();
}
/* -------------------------------------------------------------------
Name : Reset_hx8824
Purpose :
Passed :
Returns :
Notes :
------------------------------------------------------------------- */
void Reset_hx8824()
{
Byte i;
code unsigned reset_hx8824_table[11][2] = {{0x41,0x10},{0x42,0xF0},{0x43,0x00},{0x44,0xF0},
{0x45,0x0C},{0x46,0x80},{0x47,0x80},{0x48,0x00},
{0x49,0x00},{0x4A,0x80},{0x4B,0x00}};
for(i = 0; i < 11; i++)
I2CWriteByte(HX8824_ADDR, reset_hx8824_table[i][0], reset_hx8824_table[i][1]);
#if EEPROM
I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_BRIGHTNESS)/256)*2), ParaAddress + EE_BRIGHTNESS, I2CReadByte(HX8824_ADDR, HX8824_BRIGHTNESS));
I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_CONTRAST)/256)*2), ParaAddress + EE_CONTRAST, I2CReadByte(HX8824_ADDR, HX8824_CONTRAST)); I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_SHARPNESS)/256)*2), ParaAddress + EE_SHARPNESS, I2CReadByte(HX8824_ADDR, HX8824_SHARPNESS)); I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_SAT_SIN_HUE)/256)*2), ParaAddress + EE_SAT_SIN_HUE, I2CReadByte(HX8824_ADDR, HX8824_SATSINHUE)); I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_SAT_SIN_HUE)/256)*2), ParaAddress + EE_SAT_SIN_HUE + 1, I2CReadByte(HX8824_ADDR, HX8824_SATSINHUE + 1)); I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_SAT_COS_HUE)/256)*2), ParaAddress + EE_SAT_COS_HUE, I2CReadByte(HX8824_ADDR, HX8824_SATCOSHUE)); I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_SAT_COS_HUE)/256)*2), ParaAddress + EE_SAT_COS_HUE + 1, I2CReadByte(HX8824_ADDR, HX8824_SATCOSHUE + 1));
#endif
}
/* -------------------------------------------------------------------
Name : test
Purpose :
Passed :
Returns :
Notes :
------------------------------------------------------------------- */
void test()
{
unsigned char* string;
//Init_OSD();
//Print_String(2, 2, 0x00, 0x07, "ABCDEFGH");
//SetFonts(1);
//Print_Icon(0x41, 0x00, 0x00, 0x07, 0x00);
//I2CWriteByte(HX8824_ADDR, 0x60, 0x20);
//I2CWriteByte(SAA7111_ADDR, 0x02, 0xC8);
string = IntTobyStr(55);
//Puts_UART(string);
}
/* ================================================================
Name : IntTobyStr
Purpose : Change Integer Number to String
Passed : integer
Notes : string
================================================================ */
unsigned char* IntTobyStr(Byte c)
{
BYTE MAXHOLD = 5;
BYTE Hundred = 1, Array = 0, Size = 0;
Bool Finished = 0;
unsigned char* string;
while(Finished == 0)
{
if(c < 10)
{
Finished = 1;
Size = 1;
break;
}
Hundred *= 10;
if(c - Hundred >= 0 && c - 10 * Hundred < 0)
{
Finished = 1;
}
Size ++;
}
if(Size >= MAXHOLD)
{
return 0;
}
while(Array <= Size)
{
if(Hundred == 0)
{
string[Array] = 0;
}
else
{
string[Array] = c / Hundred + 48;
c -= c / Hundred * Hundred;
Hundred /= 10;
}
++Array;
}
string[Array] = 0;
return string;
}
/* ================================================================
Name : Check_EEPROM
Purpose : Check EEPROM DATA
Passed :
Notes :
================================================================ */
void Check_EEPROM(void)
{
//Burning_EEPROM();
//---Check wrong eeprom for MCU---//
if((I2CReadByte(EEPROM_MCU | (EE_BURN1/256)*2, EE_BURN1%256) != EEPDATA[63][13])||
(I2CReadByte(EEPROM_MCU | (EE_BURN2/256)*2, EE_BURN2%256) != EEPDATA[63][14])||
(I2CReadByte(EEPROM_MCU | (EE_BURN3/256)*2, EE_BURN3%256) != EEPDATA[63][15]))
{
//Puts_UART("Burning EEPROM Start!\r\n");
Burning_EEPROM();
//Puts_UART("Burning EEPROM End!\r\n");
}
else if ((I2CReadByte(EEPROM_MCU | (EE_BURN1/256)*2, EE_BURN1%256) == EEPDATA[63][13])&&
(I2CReadByte(EEPROM_MCU | (EE_BURN2/256)*2, EE_BURN2%256) == EEPDATA[63][14])&&
(I2CReadByte(EEPROM_MCU | (EE_BURN3/256)*2, EE_BURN3%256) == EEPDATA[63][15]))
{
//Puts_UART("EEPROM matched!\r\n");
}
}
/*==============================================================================
==============================================================================*/
void Burning_EEPROM(void)
{
Word address;
LEDG = 0;
LEDR = 0;
for(address = 0; address < 0x400; address++) // 1024 byte
{
if((address % 256) == 0x00)
LEDR = LEDG = 0;
if((address % 256) == 0x80)
LEDR = LEDG = 1;
I2CWriteByte(EEPROM_MCU | (address/256)*2, address%256 , EEPDATA[address/16][address%16]);
}
LEDG = 1;
LEDR = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -