📄 top18
字号:
#define paln_on 0xc8 //1100_1000
#define palm_on 0xc4 //1100_0100
#define n443_on 0xd0 //1101_0000
#define sec_on 0xe0 //1110_0000
#define all_on 0xc0 //1100_0000
#define pan36 0x2f
#define pan25 0x2b
uchar com_buf;
uchar reg_no;
/*******************************************************************/
sbit P_SCK = P1^0; //I2C总线时钟线
sbit P_SDA = P1^1; //I2C总线数据线
sbit RESETB = P3^4;
sbit PDN = P3^5;
sbit SCEN = P0^1;
sbit SDA = P1^1;
sbit SCL = P1^0;
code uchar tab[]={
AP1x, //00
0x15,
0x00,
0x6d,
0xfc,
0x00,
0x10,
0x60,
0x00,
0x80,
0x80,
0x00,
0x80,
0x40,
0x00,
0x08 //0f
};/************************************************/
void Delay_10us(void)
{
nop ;
nop ;
nop ;
nop ;
nop ;
nop ;
nop ;
nop ;
nop ;
nop ;
nop ;
}
/*************************************************/
void Wait_64us(void)
{
uchar i;
uchar j;
for(i=0;i<100;i++)
{
for(j=0;j<30;j++)
{
Delay_10us();
}
}
}
/*************************************************/
void Start_I2C(void)
{
// 启动条件是P_SCK为高电平,P_SDA下降触发
P_SCK = False ;
Delay_10us() ;
P_SDA = True ;
Delay_10us() ;
P_SCK = True ;
Delay_10us() ;
P_SDA = False ; // 下降触发
Delay_10us() ;
P_SCK = False ;
}
/***********************************************/
void Stop_I2C(void)
{
// 停止条件是P_SCK为高电平,P_SDA上升触发
P_SCK = False ;
Delay_10us() ;
P_SDA = False ;
Delay_10us() ;
P_SCK = True ;
Delay_10us() ;
P_SDA = True ; // 上升触发
Delay_10us() ;
P_SCK = False ;
}
/***********************************************/
void WByte_I2C(uchar value)
{
uchar i ;
for (i=0;i!=8;i++)
{
if ( value&0x80 )
{
P_SDA = True ;
}
else
{
P_SDA = False ;
}
value <<=1 ;
Delay_10us() ;
P_SCK = True ;
Delay_10us() ;
P_SCK = False ;
Delay_10us() ;
}
P_SDA = True ; // 读数据之前,预置P_SDA
P_SCK = True ;
do
{
i++ ;
} while(P_SDA&&i!=255) ;
P_SCK = False ;
}
//-----------------------------------------
BYTE I2C_RByte(bit Byte_F)
{
BYTE i ;
BYTE value=0 ;
P_SDA = 1 ; // 读数据之前,预置P_SDA
for (i=0;i!=8;i++)
{
P_SCK = 1 ;
Delay_10us() ;
value <<=1 ;
if (P_SDA)
{
value ++ ;
}
P_SCK = 0 ;
Delay_10us() ;
}
P_SDA = Byte_F ;
Delay_10us() ;
P_SCK = 1 ;
Delay_10us() ;
P_SCK = 0 ;
return value ;
}
/**********************************************
***********************************************/
void Read_24C02_Byte(uchar reg_addr)
{
Start_I2C() ;
WByte_I2C(0xba) ; // IC_ADDR & write command
WByte_I2C(reg_addr) ;
Start_I2C() ;
WByte_I2C(0xbb) ; // IC_ADDR & read command
com_buf=I2C_RByte(1) ; // read command over
Stop_I2C() ;
}
/*********************************************************************************************************************
TVP5150驱动程序
*********************************************************************************************************************/
void W5150_reg(uchar R_addr ,uchar R_data)
{
Start_I2C();
WByte_I2C(S_addr);
WByte_I2C(R_addr);
WByte_I2C(R_data);
Wait_64us();
Stop_I2C();
}
/******************************************************************************
Input connector: AP1A
Video format: NTSC-M, 443, PAL (B, G, H, I, M, N) and SECAM (B, D,G, K, K,I, L)
Output format: 8-bit 4:2:2 YCbCr with discrete sync outputs
******************************************************************************/
void Init_5150(void)
{ //对5150进行初始化
uchar i;
reg_no=0x00;
for(i=0;i<16;i++)
{
W5150_reg(reg_no,tab[i]);
reg_no++;
}
W5150_reg(0x16,0x7b);
}
/*********************************************/
void set_5150(void)
{ //对5150进行相应参数调节
W5150_reg(0x0a,128);
W5150_reg(0x09,128);
W5150_reg(0x0c,128);
W5150_reg(0x04,all_on);
}
/*******************************************************************************************************************
Tpg051驱动程序
*******************************************************************************************************************/
/*******************************************************************
写TPG051寄存器子函数
函数原型: void WriteTPG051(uchar SAdd,uchar SData)
功能: 向TPG051中的指定寄存器写入相应的数据
说明: SAdd:寄存器地址; SData:要写入的数据
********************************************************************/
void WriteTPG051(uchar SAdd,uchar SData)
{
uint SBuffer,SBit;
uchar i,j;
SBuffer=SAdd;
SBuffer=( SBuffer << 10 ) | ( 1 << 8 ) | SData; //将地址、数据组合成16b
SCEN=0; //CS=0
for(i=0;i<=15;i++) //16位数据的传送
{
SCL=0;
SBit=SBuffer >> (15 - i);
SBit = SBit & 0x0001;
if ( SBit !=0 )
{
SDA=1; //"1"
}
else
{
SDA=0; //"0"
}
SCL=1;
for(j=0;j++;j<100) ; //Delay
} // Delay1ms(100);
SCL=0; //空闲状态的值
SDA=0;
SCEN=1;
Delay_10us();
}
/*********************************************************************/
void Initial_TPG051(void)
{
SCL=0; //空闲状态的值
SDA=0;
SCEN=1;
WriteTPG051( 0x02, 0x6d);
WriteTPG051( 0x03, 0x02);
WriteTPG051( 0x05, 0x10); //for 2.5inch TPG051 COG: 0x05 should set to 0x2B; for 3.6, set to 0x2F
WriteTPG051( 0x04, 0x0f);
WriteTPG051( 0x14, 0x40); //Panel Gamma setting
WriteTPG051( 0x15, 0x55);
WriteTPG051( 0x16, 0x55);
WriteTPG051( 0x17, 0x35);
WriteTPG051( 0x18, 0x88);
}
/***************************************************************************
***************************************************************************/
void main(void)
{
PDN=1;
RESETB=1;
Init_5150();
Initial_TPG051();
SDA=0;
SCL=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -