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

📄 mcu.c

📁 LCD OSD 程序用於8051 開發lcd
💻 C
字号:
#include "board.h"
#include "types.h"
#include "misc.h"
#include "debug.h"

void Init_ExternalInterrupt(void);
void Init_Timer(void);
void Init_SerialPort(void);
void Init_IOPorts(void);

void Init_MCU(void)
{
	EA = 0;
	Init_ExternalInterrupt();
	Init_Timer();
	Init_SerialPort();
	Init_IOPorts();
	EA = 1;
}


// Initialize I/O setting
void Init_IOPorts(void)
{
#if Quanta
	hw_ClrBlacklit();
	hw_ClrPanel();
	hw_SetMute();
	hw_SetStandby();
	hw_ClrAmberLed();
	hw_ClrGreenLed();

	PADMOD0 = 0x01; // P6 setting, P6.0 as AD0 for keypad others is general I/O
	PADMOD4 = 0x1D; // P6.1/5 input,

	PADMOD1 = 0x7F; // P5 setting General I/O
	PADMOD3 = 0x18; //P5.3, P5.4 output for LED

	INTEN = 0x40;
	SLVBADDR = 0xA6;
	OPTION = 0x20;
	PADMOD2 = 0x87; //BIT7[0/1]:[RS232/DDC2Bi] P4 is General I/O
	PADMOD5=0x00; //P1 is GPIO

	P1 = 0x0E;
	P3 = 0x0F;
#elif  0//QuantaGateway		// Jason

/*
	hw_ClrBlacklit();
	hw_ClrPanel();
	hw_SetMute();
	hw_SetStandby();
	hw_ClrAmberLed();
	hw_ClrGreenLed();
	hw_ClrPC5V();
*/

	PADMOD0 = 0x01;		// P6 setting, P6.0 as AD0 for power source select, others is general I/O
	PADMOD1 = 0x7F;		// P5 setting General I/O
//	PADMOD2 = 0x87;		// BIT7[0/1]:[RS232/DDC2Bi] P4 is General I/O
	PADMOD2 = 0x07;		// BIT7[0/1]:[RS232/DDC2Bi] P4 is General I/O
	PADMOD3 = 0x3D;		//
	// Port 5 configure
	// Pin #		7			6			5			4			3			2			1			0
	// Function    None            VGA Con            STBY              LED G             LED R              PC 5V              None          Panel VCC 12V
	// I/O		I			I			O			O			O			O			I			O
	// Setting		0			0			1			1			1			1			0			1

	PADMOD4 = 0x43; 	//
	// Port 6 configuration
	// Pin #		7			6			5			4			3			2			1			0
	// Function    None       Panel VDD Ctrl          None        HP MCU ( DVI )    Key Right          Key Left        MST Reset          Pwr_Sel
	// I/O		I			O			I			I			I			I			O			O
	// Setting		0			1			0			0			0			0			1			1
	PADMOD5=0x00;		// P1 is 8051 standard I/O ( GPIO ).

	INTEN = 0x40;
	SLVBADDR = 0xA6;
	OPTION = 0x20;		// CPU clock Double speed

	hw_ClrBlacklit();
	hw_ClrPanel();
	hw_SetMute();
	hw_SetStandby();
	hw_ClrAmberLed();
	hw_ClrGreenLed();
	hw_ClrPC5V();

	P1 = 0xFF;
	P3 = 0x3F;

#elif QuantaGateway
{
/*
  hw_ClrBlacklit();
  //hw_ClrPanel();//barry0922 for QDI PowerSquence
  hwPanel_Pin=0;  
  Delay1ms(3); 
  hwPanel1_Pin=0 ;  
  
  
  hw_SetMute();
  hw_SetStandby();
*/
  //ASW new
  PADMOD0=0x01; // P6 setting, P6.0~P6.3 is general I/O    //Auswin for AD0 scankey
  //PADMOD0=0x00; // P6 setting, P6.0~P6.3 is general I/O

  //PADMOD4=0x1B;//0x1F; // P6.2, P6.3 output for Panel, P6.4/5/0/1 input
  //PADMOD4=0x43; // P6.2, P6.3 input for L/R key                              //output/input
                // P6.1       output for MST reset                           //  1   /  0
                // P6.0       output for PV5V off
                // P6.4, P6.5 input for cable connect                      
                // P6.6       output for Panel power control
  //PADMOD4=0x63; // P6.5       input to output  try edid eat connect
  PADMOD4=0x62;
  PADMOD1=0x7F; // P5 setting General I/O
  
  //ASW new
  //PADMOD3=0x19;            //P5.3, P5.4 output for LED                       //output/input
    PADMOD3=0x3d;            //P5.0 output       for Panel power control
                             //P5.2 0utput       for PC5v   //  1   /  0

  
  //hw_ClrPV5VOff();
  WDT=0x00;



  INTEN=0x40;
  SLVBADDR=0xA6;
 #if 1 // 0 for RS232, 1 for DDC2bi
  PADMOD2=0x87;
  OPTION=0x24;//OPTION=0x20;
 #else
  PADMOD2=0x07; // P4 is General I/O
  OPTION=0x20; // double speed
 #endif
  P3_0=1;
  P3_1=1;
  P3_4=1;
  P3_5=1;
  
//**********************************//barry0923 AC plug flash
  hw_ClrBlacklit();
  //hw_ClrPanel();//barry0922 for QDI PowerSquence
  hwPanel_Pin=0;  
  Delay1ms(3); 
  //hwPanel1_Pin=0 ; 

  hw_SetMute();
  hw_SetStandby();


  hw_ClrAmberLed();
  hw_ClrGreenLed();
//************************************

  }

#elif Lego2
{
/*
  hw_ClrBlacklit();
  //hw_ClrPanel();//barry0922 for QDI PowerSquence
  hwPanel_Pin=0;  
  Delay1ms(3); 
  hwPanel1_Pin=0 ;  
  
  
  hw_SetMute();
  hw_SetStandby();
*/
  //ASW new
  PADMOD0=0x01; // P6 setting, P6.0~P6.3 is general I/O    //Auswin for AD0 scankey
  //PADMOD0=0x00; // P6 setting, P6.0~P6.3 is general I/O

  //PADMOD4=0x1B;//0x1F; // P6.2, P6.3 output for Panel, P6.4/5/0/1 input
  //PADMOD4=0x43; // P6.2, P6.3 input for L/R key                              //output/input
                // P6.1       output for MST reset                           //  1   /  0
                // P6.0       output for PV5V off
                // P6.4, P6.5 input for cable connect                      
                // P6.6       output for Panel power control
  //PADMOD4=0x63; // P6.5       input to output  try edid eat connect
  PADMOD4=0x62;
  PADMOD1=0x7F; // P5 setting General I/O
  
  //ASW new
  //PADMOD3=0x19;            //P5.3, P5.4 output for LED                       //output/input
    PADMOD3=0x7d;     //old value is 0x3D.dragon 0513       //P5.0 output       for Panel power control
                             //P5.2 0utput       for PC5v   //  1   /  0

  
  hw_ClrPV5VOff();
  WDT=0x00;



  INTEN=0x40;
  SLVBADDR=0xA6;
 #if 1 // 0 for RS232, 1 for DDC2bi
  PADMOD2=0x87;
  OPTION=0x24;//OPTION=0x20;
 #else
  PADMOD2=0x07; // P4 is General I/O
  OPTION=0x20; // double speed
 #endif
  P3_0=1;
  P3_1=1;
  P3_4=1;
  P3_5=1;
  
//**********************************//barry0923 AC plug flash
  hw_ClrAmberLed();
  hw_ClrGreenLed();
  hw_SetMute();
  
  hw_ClrBlacklit();
  //hw_ClrPanel();//barry0922 for QDI PowerSquence
  hwPanel_Pin=0;  
//  Delay1ms(3); 
  //hwPanel1_Pin=0 ; 
  //Delay1ms(100);//jon change 10m
  hw_SetStandby();

//************************************
  }


#elif QuantaL7T
	hw_ClrBlacklit();
  	hw_ClrPanel();
  	hw_SetMute();
  	hw_SetStandby();
  	hw_ClrAmberLed();
  	hw_ClrGreenLed();

  	PADMOD0=0x00; // P6 setting, P6.0 as AD0 for keypad others is general I/O
  	// 0 is GPIO, 1 is DAC
  	PADMOD4=0x1C; // P6[0/1/5] input,
  	// 1 is Output, 0 is Input
	PADMOD1=0x7F; // P5 setting General I/O
	// 1 is GPIO, 0 is DAC
	PADMOD3=0x18; //P5[0] Input, P5[3/4] output for LED
	// 1 is Output, 0 is Input
	INTEN=0x40;
	SLVBADDR=0xA6;
	OPTION=0x20; // Double speed

	PADMOD2=0x87; //BIT7[0/1]:[RS232/DDC2Bi] P4 is General I/O
	PADMOD5=0x00; //P1 is GPIO
	P1=0xFF;
	P3=0x3F;
#else
	P0=0xFF;
	P1=0x03;
	P2=0xFA;
	P3=0x0F;
#endif
}

/* initialize 8051 CPU timer & interrupt routine */
/* TCON.7(   TF1): Timer 1 overflow flag */
/* TCON.6(   TR1): Timer 1 stop/start bit */
/* TCON.5(   TF0): Timer 0 overflow flag */
/* TCON.4(   TR0): Timer 0 stop/start bit */
/* TCON.3(   IE1): Timer 1 INT1 interrupt flag */
/* TCON.2(   IT1): Timer 1 INT1 interrupt style setup*/
/* TCON.1(   IE0): Timer 0 /INT0 interrupt flag */
/* TCON.0(   IT0): Timer 0 /INT0 interrupt style setup */
void Init_ExternalInterrupt(void)
{
#if UseINT
  IT0=1;//1;
  IE0=0;
  EX0=1;  // disable external interrupt 0
#else
  IT0=0;//1;
  IE0=0;
  EX0=0;  // disable external interrupt 0
#endif
  IT1=1;//1; // set external interrupt 0 & 1 as falling edge trigger
  IE1=0;  // interrupt flag
  EX1=1;  // enable external interrupt 1

  PX0=1;  //
}

void Init_Timer(void)
{ WORD clock_period=ClockPeriod;
  /* -------------initialize Timer 0 -----------------------------*/
  ET0=1;  // enable timer 0 interrupt
  TH0=clock_period>>8;
  TL0=clock_period&0xFF; // timer 0 counter
  TF0=0; // timer 1 flag

 /* -------------initialize Timer 0 -----------------------------*/
#if Quanta || QuantaL7T||QuantaGateway ||Lego2
 TMOD=0x21;
#else
  ET1=0;  // disable timer 1 interrupt
  TH1=0;
  TL1=0; // timer 1 counter
  TF1=0; // timer 1 flag

  // setup Timer mode
  TMOD=0x11;  // set timer 1 as timer(1) , timer 0 as counter(5)
  TR1=0;  // disable timer 1
#endif

  // enable/disable timer
  TR0=1;  // disable timer 0
}

/*----------Timer 2 -------------------*/
/* T2CON.7(   TF2): overflow flag */
/* T2CON.6(  EXF2): extern enable flag */
/* T2CON.5(  RCLK): receive clock */
/* T2CON.4(  TCLK): transfer clock */
/* T2CON.3( EXEN2): extern enable flag */
/* T2CON.2(   TR2): stop/start timer 2 */
/* T2CON.1(  C_T2): intern clock(0)/extern counter(1) switch */
/* T2CON.0(CP_RL2): capture flag */
void Init_SerialPort(void)
{
#if Quanta || QuantaL7T||QuantaGateway
  WORD br_cnt=T1BaudRatePeriod;

  PCON=0x80;
  SCON=0x52;
  TH1=255;//0xFA;			//br_cnt;

  TR1=1;

#elif Lego2
  WORD br_cnt=T1BaudRatePeriod;

  PCON=0x80; //00
  SCON=0x52;
  TH1=255;//br_cnt;  //jon change 225 to 255 modify white balance no adjust //255;//0xFA;			//

  TR1=1;


#else
  WORD br_cnt=BaudRatePeriod;
  T2CON=0x00;
//  RCAP2H= 0xFF;//BaudRatePeriod>>8;
//  RCAP2L= 0xDC;//BaudRatePeriod&0xff;
  RCAP2H= br_cnt>>8;
  RCAP2L= br_cnt&0xff;
  SCON=0x50;
  T2CON=0x34;
#endif
  RI=0;
  TI=0;
  ES=1;
}

#if 0
void EnableISP(void)
{ TR0=0;
  CHPENR=0x87;
  CHPENR=0x59;
  CHPCON=0x03;
  IP=0x00;
  IP=0x82;
  TL0=0xFE;
  TH0=0xFF;
  TR0=1;//
  PCON |= 0x01;
  while (1);
}
#endif

#if Quanta || QuantaL7T || QuantaGateway||Lego2
void EnableDDC(void)
{
	INTEN = 0x40;
	PADMOD2 = 0x87;
	ES = 0;
}
void DisableDDC(void)
{
	INTEN = 0x00;
	PADMOD2 = 0x07;
	ES = 1;
}
#endif

⌨️ 快捷键说明

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