Initial.~c
上传用户:xmyjxjd
上传日期:2013-05-04
资源大小:1517k
文件大小:14k
开发平台:

C/C++

  1. #define __INITIAL__
  2. #include "HeaderLcd_main.h"
  3. #include "reg52.h"
  4. #include "HeaderAccess.h"
  5. #include "Headerconfig.h"
  6. #include "intrins.h"
  7. #include "HeaderLcd_func.h"
  8. #include "HeaderInitial.h"
  9. #include "HeaderOSD.h"
  10. #include "HeaderSrc_Ctrl.h"
  11. #include "HeaderFrame_Sync.h"
  12. //#include "Power_Ctrl.h"
  13. void MCU_Init(void)
  14. {
  15. #if(MCU_TYPE == MCU_WINBOND)
  16.     IE      = 0x00;                 // Disable all interrupts
  17.     TMOD    = 0x11;                 // Program Timer0 & Timer1 to Mode#1
  18.     TR0     = 0;                    // Stop Timer0
  19.     TF0     = 0;                    // Clear Timer0 Overflow Bit
  20.     TL0     = TIME0_COUNTER_LBYTE;  // Load Timer0 low-byte   (for 20ms)
  21.     TH0     = TIME0_COUNTER_HBYTE;  // Load Timer0 high-byte  (for 20ms)
  22.     TR1     = 0;                    // Stop Timer1
  23.     TF1     = 0;                    // Clear Timer1 Overflow Bit
  24.     TL1     = TIME1_COUNTER_LBYTE;  // Load Timer1 low-byte   (for 1ms)
  25.     TH1     = TIME1_COUNTER_HBYTE;  // Load Timer1 hifh-byte  (for 1ms)
  26.     IE      = 0x8a;                 // Enable interrupts of Timer0 and Timer1
  27. #else
  28.     IE      = 0x00;                 // Disable all interrupts
  29.     TMOD    = 0x11;             // Program Timer0 & Timer1 to Mode#1
  30.     TR0     = 0;                    // Stop Timer0
  31.     TF0     = 0;                    // Clear Timer0 Overflow Bit
  32.     TL0     = TIME0_COUNTER_LBYTE;  // Load Timer0 low-byte   (for 20ms)
  33.     TH0     = TIME0_COUNTER_HBYTE;  // Load Timer0 high-byte  (for 20ms)
  34.     TR1     = 0;                    // Stop Timer1
  35.     TF1     = 0;                    // Clear Timer1 Overflow Bit
  36.     TL1     = TIME1_COUNTER_LBYTE;  // Load Timer1 low-byte   (for 1ms)
  37.     TH1     = TIME1_COUNTER_HBYTE;  // Load Timer1 hifh-byte  (for 1ms)
  38.     
  39.     IE      = 0x86;                 // Enable interrupts of Timer0 and Timer1
  40. //    IE      = 0x8a;                 // Enable interrupts of Timer0 and Timer1
  41. //    TR1 = 1;
  42.     TR0            = 1;
  43.     
  44. M512_PadMode1=0xff;
  45. M512_PadMode2=0x80;
  46. // M512_PadMode3=0x20;
  47. M512_PadMode3=0x83;
  48. M512_PadMode6=0x00;
  49. M512_PadMode7=0x40;
  50. // MCU_WriteVideoPower(0);
  51. M512_Port55=0;
  52. #endif
  53. }
  54. void Firmware_Init(void)
  55. {
  56. #if(MCU_TYPE == MCU_WINBOND)
  57.     bLIGHT_PWR  = LIGHT_OFF;
  58.     bPANEL_PWR  = PANEL_OFF;
  59.     bPanel_Status = _OFF;
  60. #else
  61.     MCU_WriteBacklightPower(LIGHT_OFF);
  62.     MCU_WritePanelPower(PANEL_OFF);
  63.     bPanel_Status = _OFF;//DWL 0120
  64. #endif
  65.      MCU_Init();
  66.      RTDSetBit(HOSTCTRL_02,0xfb,0x00);    // RTD turn on
  67. #if(MCU_TYPE == MCU_WINBOND)
  68. #if(RESET_TYPE == RESET_IN)
  69.     bRTD_RST    = 0;
  70.     Delay_Xms(10);
  71.     do
  72.     {
  73.         // Wait for reset complete
  74.         bRTD_RST    = 1;
  75.         Delay_Xms(2);
  76.     }
  77.     while (!bRTD_RST);
  78. #endif
  79. #else
  80. #if(RESET_TYPE == RESET_IN)
  81.     MCU_WriteRtdReset(LOW);
  82.     Delay_Xms(10);
  83.     do
  84.     {
  85.         // Wait for reset complete
  86.         MCU_WriteRtdReset(HIGH);
  87.         Delay_Xms(10);
  88.     }
  89.     while (MCU_ReadRtdReset()!=HIGH);
  90. #endif
  91. #endif
  92.     RTDRead(ID_REG_00,1,N_INC);
  93. ucID_Code = Data[0];
  94.     RTDCodeW(RTD_PWUP_INI);
  95. #if(HDCP_ENABLE)
  96.     RTDCodeW(BKSV);
  97.     KEYCodeW(HDCP_KEY_A_Port);
  98. #endif
  99.     RTDSetByte(HOSTCTRL_02, 0x40);          // Wake RTD up
  100.     RTDSetByte(DPLL_CTRL_D0, 0x11);         // Enable DPLL
  101.     RTDSetByte(VDIS_SIGINV_21, 0x00 | DISP_EO_SWAP | DISP_RB_SWAP | DISP_ML_SWAP);       // DHS, DVS, DEN, DCLK MUST NOT be inverted.
  102.     RTDSetBit(VDIS_CTRL_20, 0xfd, 0x21);    // DHS, DVS, DEN, DCLK and data are clamped to 0
  103.     RTDSetBit(DIS_TIMING0_3A, 0xff, 0x20);  // Force display timing enable
  104.     RTDSetBit(DIS_TIMING0_3A, 0xdf, 0x00);  // Stop forcing
  105.     _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
  106.     RTDSetBit(VDIS_CTRL_20, 0xfe, 0x00);    // Stop display timing
  107.     RTDSetByte(HOSTCTRL_02, 0x42);          // Put RTD2020 back into power-saving mode
  108.     RTDSetByte(DPLL_CTRL_D0, 0x10);         // Disable DPLL
  109.     RTDCodeW(RTD_DDC_TABLE);
  110.     RTDCodeW(RTD_IO_INI);
  111. #if(!SOURCE_AUTO_SCAN)
  112.     PowerDown_VDC();
  113.     //Device_Power(VDC_POWER,OFF);
  114. #endif
  115. PowerDown_TMDS();
  116.     PowerDown_LVDS();
  117.     //Device_Power(TMDS_POWER,OFF);
  118.     //Device_Power(LVDS_POWER,OFF);
  119.     Delay_Xms(10);
  120.     // Check and initial EEPROM if necessary
  121.     Delay_Xms(10);
  122.     Check_EEPROM();
  123.     Delay_Xms(10);
  124.     // Turn timer0 on. Let's go ~~~
  125.     TR0     = 1;
  126. }
  127. void Power_Up_Init(void)    // Do once when power up
  128. {
  129.    
  130.      RTDSetBit(HOSTCTRL_02,0xfb,0x00);    // RTD turn on
  131.     Reset_RTD();            // Initial RTD3000 & OSD
  132. #if(ADC_DEFFERENTIAL)
  133.     RTDSetBit(ADC_DIFF_MODE_EC,0xff,0x40); //Differential mode
  134. #else
  135.     RTDSetBit(ADC_DIFF_MODE_EC,0xbf,0x00); //Single endded mode
  136. #endif
  137. #if(MCU_TYPE == MCU_WINBOND)
  138.     bLIGHT_PWR  = LIGHT_OFF;
  139.     bPANEL_PWR  = PANEL_OFF;
  140. bPanel_Status = _OFF;
  141. #else
  142.     MCU_WriteBacklightPower(LIGHT_OFF);
  143.     MCU_WritePanelPower(PANEL_OFF);
  144.     bPanel_Status = _OFF;
  145. #endif
  146. #if(TUNE_APLL)
  147. ucPE_Max = 0;
  148. RTDSetByte(DV_TOTAL_STATUS_3D,0x40); //clear PE Max value
  149. #endif
  150. #if(!SOURCE_AUTO_SCAN)
  151.     PowerDown_VDC();
  152. //Device_Power(VDC_POWER,OFF);
  153. #endif
  154.     PowerDown_LVDS();
  155. //Device_Power(LVDS_POWER,OFF);
  156. #if(TMDS_ENABLE)
  157. RTDSetByte(ANG_PERFORMANCE2_A3, 0x26); //Go about the TMDS impedence match
  158. RTDSetByte(ANG_PERFORMANCE2_A3, 0x36);
  159. #endif
  160.     //RTDSetBit(OVL_CTRL_6D, 0x3f, (stGUD1.FUNCTION & 0x10) ? 0x80 : 0x00);
  161.     RTDSetBit(OVL_CTRL_6D, 0xc7, (stGUD1.INPUT_SOURCE & 0xe0) >> 2);
  162. #if (SPREAD_SPECTRUM)
  163. //    RTDSetBit(SPREAD_SPECTRUM_99,0x03,0x00);
  164.     RTDSetBit(DPLL_N_D2,0xff,0x20); //DPLL spread spectrum Enable
  165. #endif
  166.     Init_Input_Source();    // Initial Mode & OSD
  167. }
  168. void Reset_RTD(void)
  169. {
  170. #if(MCU_TYPE == MCU_WINBOND)
  171. #if(RESET_TYPE == RESET_IN)
  172.     bRTD_RST    = 0;
  173. Delay_Xms(10);
  174.     do
  175.     {
  176.         // Wait for reset complete
  177.         bRTD_RST    = 1;
  178.         Delay_Xms(6);
  179.     }
  180.     while (!bRTD_RST);
  181. #endif
  182. #else
  183. #if(RESET_TYPE == RESET_IN)
  184.     MCU_WriteRtdReset(LOW);
  185.  Delay_Xms(10);
  186.     do
  187.     {
  188.         // Wait for reset complete
  189.         MCU_WriteRtdReset(HIGH);
  190.         Delay_Xms(6);
  191.     }
  192.     while (MCU_ReadRtdReset()!=HIGH);
  193. #endif
  194. #endif
  195.     
  196.     // Initial RTD3000 & free background display
  197.     RTDCodeW(RTD_PWUP_INI);
  198. #if(HDCP_ENABLE)
  199.     RTDCodeW(BKSV);
  200.     KEYCodeW(HDCP_KEY_A_Port);
  201. #endif
  202.     RTDCodeW(RTD_DDC_TABLE);
  203.     RTDCodeW(RTD_IO_INI);
  204.     RTDSetByte(HOSTCTRL_02, 0x40);          // Wake RTD up
  205.     RTDCodeW(FreeV);
  206.     RTDSetByte(VDIS_SIGINV_21, 0x00 | DISP_EO_SWAP | DISP_RB_SWAP | DISP_ML_SWAP);       // DHS, DVS, DEN, DCLK MUST NOT be inverted.
  207.     RTDSetBit(VDIS_CTRL_20, 0xfd, 0x01);    // DHS, DVS, DEN, DCLK and data are clamped to 0
  208.     // Initial RTD3000-OSD
  209.     RTDCodeW(OSD_PWUP_INI);
  210.     RTDOSDW(OSD_Reset);
  211.     // Initial OSD palette
  212.     RTDCodeW(Palette_Open);
  213.     RTDCodeW(Palette_7);
  214.     RTDCodeW(Palette_Close);
  215.     // Check and initial EEPROM if necessary
  216. //    Delay_Xms(10);
  217. //    Check_EEPROM();
  218. //    Delay_Xms(10);
  219.     Set_Gamma();
  220.     Set_Dithering();
  221.     Set_Bright_Contrast();
  222. }
  223. void Init_Input_Source(void)
  224. {       
  225.     ucMode_Found    = MODE_NOSUPPORT;
  226.     ucMode_Curr     = MODE_NOSIGNAL;
  227.     ucMode_Times    = 0;
  228.     ucAV_Mode       = 0;
  229.     bVpole_Curr     = 1;                // The initial set of polarity is positive
  230.     bHpole_Curr     = 1;                // The initial set of polarity is positive
  231.     // Unknown signal source
  232.     if (SOURCE_MAX < (stGUD1.INPUT_SOURCE & 0x07))
  233.         stGUD1.INPUT_SOURCE = (stGUD1.INPUT_SOURCE & 0xf8) | SOURCE_VGA;
  234. #if (TMDS_ENABLE == _FALSE)
  235.     if (SOURCE_DVI == (stGUD1.INPUT_SOURCE & 0x07))
  236.         stGUD1.INPUT_SOURCE = (stGUD1.INPUT_SOURCE & 0xf8) | SOURCE_VGA;
  237. #endif
  238. #if (VIDEO_CHIP == VDC_NONE)
  239.     if (SOURCE_AV == (stGUD1.INPUT_SOURCE & 0x07) || SOURCE_SV == (stGUD1.INPUT_SOURCE & 0x07))
  240.         stGUD1.INPUT_SOURCE = (stGUD1.INPUT_SOURCE & 0xf8) | SOURCE_VGA;
  241. #endif
  242. #if (VIDEO_CHIP != VDC_SAA7118)
  243.     if (SOURCE_YUV == (stGUD1.INPUT_SOURCE & 0x07))
  244.         stGUD1.INPUT_SOURCE = (stGUD1.INPUT_SOURCE & 0xf8) | SOURCE_VGA;
  245. #endif
  246. #if (TV_CHIP == TV_NONE)
  247.     if (SOURCE_TV == (stGUD1.INPUT_SOURCE & 0x07))
  248.         stGUD1.INPUT_SOURCE = (stGUD1.INPUT_SOURCE & 0xf8) | SOURCE_VGA;
  249. #endif
  250.     // Because internal ADC power state will not affect VGA mode detection,
  251.     // we always turn off ADC when source changed, and turn it on again only 
  252.     // when a valid VGA mode is going to display.
  253.     PowerDown_ADC();
  254.     //Device_Power(ADC_POWER,OFF);
  255. #if(SOURCE_AUTO_SCAN)
  256. PowerUp_VDC();
  257. Delay_Xms(10);
  258. #if (VIDEO_CHIP == VDC_SAA7114 || VIDEO_CHIP == VDC_SAA7115 || VIDEO_CHIP == VDC_SAA7118)
  259.         I2CWrite(V_ENABLE);         // VIDEO ENABLE
  260.         I2CWrite(VIDEO_ALL);
  261. #endif
  262.     bSourceScanEnable = _TRUE;
  263. #endif
  264.     switch (stGUD1.INPUT_SOURCE & 0x07)
  265.     {
  266.     case SOURCE_VGA:
  267. #if (VIDEO_CHIP == VDC_SAA7114 || VIDEO_CHIP == VDC_SAA7115 || VIDEO_CHIP == VDC_SAA7118)
  268.         I2CWrite(V_DISABLE);        // VIDEO DISABLE
  269. #endif
  270.         I2CWrite(V_NOWORK);         // VIDEO No Work
  271. #if(!SOURCE_AUTO_SCAN)
  272.     PowerDown_VDC();
  273. PowerDown_TMDS();
  274. //Device_Power(VDC_POWER,OFF);
  275. //Device_Power(TMDS_POWER,OFF);
  276. #else
  277.     PowerUp_VDC();
  278. PowerUp_TMDS();
  279. //Device_Power(VDC_POWER,ON);
  280. //Device_Power(TMDS_POWER,ON);
  281. #endif
  282. #if(TMDS_ENABLE)
  283.         RTDSetBit(TMDS_CORRECTION_FF,0xfc,0x00);
  284. #endif
  285.         // Set user's ADC gain and offset settings
  286.         SetADC_GainOffset();
  287.         ucInputSrc  = SOURCE_VGA;        
  288.         ucSync_Type = SYNC_SS;
  289.         RTDCodeW(VGA_INI_SS);
  290.         break;
  291.   case SOURCE_DVI:
  292. #if (VIDEO_CHIP == VDC_SAA7114 || VIDEO_CHIP == VDC_SAA7115 || VIDEO_CHIP == VDC_SAA7118)
  293.         I2CWrite(V_DISABLE);        // VIDEO DISABLE
  294. #endif
  295.         I2CWrite(V_NOWORK);         // VIDEO No Work
  296. #if(!SOURCE_AUTO_SCAN)
  297.     PowerDown_VDC();
  298. //Device_Power(VDC_POWER,OFF);
  299. #else
  300.     PowerUp_VDC();
  301. //Device_Power(VDC_POWER,ON);
  302. #endif
  303. #if(TMDS_ENABLE)
  304.         RTDSetBit(TMDS_CORRECTION_FF,0xfc,0x00);
  305. #endif
  306.         PowerUp_TMDS();
  307.         //Device_Power(TMDS_POWER,ON);
  308.         ucInputSrc  = SOURCE_DVI;        
  309.         RTDCodeW(DVI_INI);
  310.         break;      
  311.     case SOURCE_AV:
  312.     case SOURCE_TV:
  313. #if(SOURCE_AUTO_SCAN)
  314.         if((SOURCE_AV != MASTER_SOURCE) && (SOURCE_AV != SLAVE_SOURCE) && (SOURCE_AV != THIRD_SOURCE))
  315.    bSourceScanEnable = _FALSE;
  316. #endif  
  317.         PowerUp_VDC();
  318. #if(TMDS_ENABLE)
  319.         RTDSetBit(TMDS_CORRECTION_FF,0xfc,0x00);
  320. #endif
  321.         //Device_Power(VDC_POWER,ON);
  322.         // PCB rev.C
  323.         // For PCB rev.C, turning down TMDS will turning on video decoder.
  324.         // However, video decoder needs times to wake up.
  325.         Delay_Xms(10);
  326. #if (VIDEO_CHIP == VDC_SAA7114 || VIDEO_CHIP == VDC_SAA7115 || VIDEO_CHIP == VDC_SAA7118)
  327.         I2CWrite(V_ENABLE);         // VIDEO ENABLE
  328.         I2CWrite(VIDEO_ALL);
  329. #endif
  330.         I2CWrite(AV_DETECT);        // VIDEO Detect(AV)
  331.         if (SOURCE_AV == (stGUD1.INPUT_SOURCE & 0x07))
  332.         {
  333.             ucInputSrc  = SOURCE_AV;
  334.         }
  335.         else
  336.         {
  337.             ucInputSrc  = SOURCE_TV;
  338. #if (TV_CHIP != TV_NONE)
  339.             // Set TV channel
  340.             Set_TV_Channel();
  341. #endif
  342.             // Select TV signal input pin and disable AGC of video decoder
  343.             I2CWrite(TV_SOURCE_SEL);
  344.             I2CWrite(TV_SCAN_GAIN);
  345.         }
  346.         RTDCodeW(VIDEO_INI);
  347.         I2CRead(ADDR_VIDEO, 0x1f, 0x01);
  348.         break;
  349.         
  350.     case SOURCE_SV:
  351. #if(SOURCE_AUTO_SCAN)
  352.         if((SOURCE_SV != MASTER_SOURCE) && (SOURCE_SV != SLAVE_SOURCE) && (SOURCE_SV != THIRD_SOURCE))
  353.    bSourceScanEnable = _FALSE;
  354. #endif  
  355.  PowerUp_VDC();
  356.  //Device_Power(VDC_POWER,ON);
  357.        Delay_Xms(10);
  358. #if (VIDEO_CHIP == VDC_SAA7114 || VIDEO_CHIP == VDC_SAA7115 || VIDEO_CHIP == VDC_SAA7118)
  359.         I2CWrite(V_ENABLE);         // VIDEO ENABLE
  360.         I2CWrite(VIDEO_ALL);
  361. #endif
  362.         I2CWrite(SV_DETECT);        // VIDEO Detect(SV)
  363.         ucInputSrc  = SOURCE_SV;
  364.         RTDCodeW(VIDEO_INI);
  365.         I2CRead(ADDR_VIDEO, 0x1f, 0x01);
  366.         break;
  367.     case SOURCE_YUV:
  368. #if(SOURCE_AUTO_SCAN)
  369.         if((SOURCE_YUV != MASTER_SOURCE) && (SOURCE_YUV != SLAVE_SOURCE) && (SOURCE_YUV != THIRD_SOURCE))
  370.    bSourceScanEnable = _FALSE;
  371. #endif  
  372.     PowerUp_VDC();
  373. //Device_Power(VDC_POWER,ON);
  374.         
  375.         Delay_Xms(10);
  376.         I2CWrite(V_ENABLE);         // VIDEO ENABLE
  377.         I2CWrite(VIDEO_ALL);
  378.         I2CWrite(VIDEO_YUV);
  379.         I2CWrite(YUV_DETECT);       // VIDEO Detect(YUV)
  380.         ucInputSrc  = SOURCE_YUV;
  381.         RTDCodeW(VIDEO_INI);
  382.         I2CRead(ADDR_VIDEO, 0x1f, 0x01);
  383.         break;
  384.     }
  385. #if (AUDIO_TYPE != AUDIO_NONE)
  386.     SetVolume();
  387. #endif
  388. }
  389. void Power_Status_Init(void)
  390. {
  391. #if (POWER_KEY_TYPE == TYPE_ONE_TOUCH)
  392. #if (KEY_DISABLED == POWER_KEY_MASK)
  393.     // Force system to power up when no power-key
  394.     bPower_Status   = 1;
  395.     Power_Up_Init();
  396.     bStable     = 0;                    // Assume input signal is not stable when power up
  397.     bReload     = 1;                    // Always reload font when power up
  398.     bFrameSync  = 0;                    // Not sync yet
  399.     ucModeCnt   = MODE_DETECT_FREQ;     // Reset Input Mode Detector
  400.     
  401.     Measure_Mode();                     // Measure mode-timing
  402.     Set_Task(STATE_POWERUP);            // Notify Task State Machine
  403. #else
  404.     // Restore previous power status
  405.     if (0 == (stGUD1.FUNCTION & 0x08))
  406.     {
  407.         bPower_Status   = 1;
  408.         Power_Up_Init();
  409.         
  410.         bStable     = 0;                    // Assume input signal is not stable when power up
  411.         bReload     = 1;                    // Always reload font when power up
  412.         bFrameSync  = 0;                    // Not sync yet
  413.         ucModeCnt   = MODE_DETECT_FREQ;     // Reset Input Mode Detector
  414.     
  415.         Measure_Mode();                     // Measure mode-timing
  416.         Set_Task(STATE_POWERUP);            // Notify Task State Machine
  417.     }
  418.     else
  419.     {
  420.         bPower_Status   = 0;
  421.     }
  422. #endif
  423. #else
  424.     // Do nothing when power-key is two-state type.
  425.     bPower_Status   = 0;
  426. #endif
  427. }