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

C/C++

  1. //***********************************************************************
  2. //                                      Myson Addition DDCRAM 
  3. //***********************************************************************
  4. typedef unsigned char Byte;
  5. #define _DDC_
  6. #include "HeaderDDC.h"
  7. #include "HeaderMTV512.H"
  8. #include "Headeraccess.h"
  9. #include "HeaderTimer.h"
  10. #include "reg52.h"
  11. #if(USE_MCU_DDC)
  12. Byte xdata EDID_Cmd_Buffer;
  13. void EnableDDC(void);
  14. //void EnableDDCWriter();
  15. void EDID_Process();
  16. //void MovEEPROM(Byte *array);
  17. //void MovEEPROM_2(Byte *array);
  18. Byte code EDID_DATA1[128] = 
  19. {
  20.   0x00,0xff,0xff,0xff,0xFF,0xFF,0xFF,0x00,0x5A,0x63,0x02,0x08,0x01,0x01,0x01,0x01,
  21.   0x29,0x0A,0x01,0x02,0x1D,0x1F,0x17,0xB9,0xEB,0x00,0xB8,0xA0,0x57,0x49,0x9B,0x26,
  22.   0x10,0x48,0x4C,0xFF,0xFE,0x80,0x31,0x59,0x45,0x59,0x71,0x4F,0x81,0x40,0x81,0x80,
  23.   0x01,0x01,0x01,0x01,0x01,0x01,0xC3,0x1E,0x00,0x20,0x41,0x00,0x20,0x30,0x10,0x60,
  24.   0x13,0x00,0x2C,0xE1,0x10,0x00,0x00,0x1E,0x00,0x00,0x00,0xFF,0x00,0x32,0x30,0x48,
  25.   0x30,0x30,0x34,0x31,0x30,0x30,0x32,0x36,0x30,0x0A,0x00,0x00,0x00,0xFD,0x00,0x32,
  26.   0xB4,0x1E,0x46,0x0A,0x01,0x0A,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0xFC,
  27.   0x00,0x52,0x45,0x41,0x4C,0x54,0x45,0x4B,0x0A,0x20,0x20,0x20,0x20,0x20,0x00,0x01
  28.   //     R   E     A    L    T   E     K
  29.   
  30. };
  31. void EDID_Process()
  32.   Byte i,checksum=0;
  33.   
  34.   if(EDID_Cmd_Buffer==0xaa)
  35.   {
  36.      for(i=0;i<128;i++)
  37.         checksum=checksum+byMTV512_DDCRAMA[i];
  38.      if(checksum==0) // checksum correct
  39.      {
  40.         if((byMTV512_DDCRAMA[20]&0x80)==0x80)
  41.             MovEEPROM(&byMTV512_DDCRAMA,1); //DVI SAVE TO LAST 128 BYTE
  42.         else
  43.             MovEEPROM(&byMTV512_DDCRAMA,0); //SUB SAVE TO LAST 128 BYTE
  44.             EDID_Cmd_Buffer=0xff;    //Initial Command Buffer          
  45.      }       
  46.   }    
  47. }
  48. void EnableDDC(void)
  49. {
  50.    EDID_Cmd_Buffer = 0xff;     //Initial Command Buffer
  51.    M512_IIC_CTR = 0xc0;       //Enable IIC Interface and define ddc2 active at HSDA/HSCL
  52.    M512_IIC_INTEN = 0x04;    //Detect WslvA1 IIC Stop Condition
  53.    M512_INTFLG = 0x00;        //Clear IIC Interrupt register
  54.    byM512_CTRSLVB = 0x00;     //Define IIC Protocal Slave Address Bit
  55.    M512_PadMode2=0xa0;      //OPEN DDCRAM1 and DDCRAM2 Chanell(HSDA1/HSDA2  HSCL1/HSCL2) 
  56.    byM512_DDCCTRA1=0xd0;    //Enable DDC1 and DDCRAM 128 Access
  57.    byM512_SLVA1ADR=0x80|(0xa0>>1);  //DDC Slave A1 address
  58.    byM512_DDCCTRA2=0xd0;    //Enable DDC1 and DDCRAM 128 Access
  59.    byM512_SLVA2ADR=0x80|(0xa0>>1);  //DDC Slave A2 address
  60.    
  61. }
  62. //*******************************************************************************************
  63. void ReceiveEDIDINT1(void) interrupt 2
  64. {
  65.    Byte tempflag;  
  66.    tempflag = M512_INTFLG;
  67.    EX1 = 0; 
  68.    
  69.    if((tempflag & WslvA1I) != 0)  //DDCRAMA IIC Stop Interrupt detect
  70.    {
  71.        M512_INTFLG = tempflag & (~WslvA1I);  //Clear DDCRAMA IIC Stop Interrupt detect 
  72.        EDID_Cmd_Buffer = 0xaa;   //Set the Writer EEPROM Command
  73.    }  
  74.  
  75.    EX1 =1;
  76. }
  77. //*******************************************************************************************
  78. void MovEEPROM(Byte *array,unsigned char index)   //128 byte
  79. {
  80.     Byte a,b;
  81.     for (a=0;a<8;a++)
  82. {
  83.   if(index == 0)
  84.         I2CSendAddr(ADDR_EDID1, a*16, 0);     
  85.   else
  86.         I2CSendAddr(ADDR_EDID1, (0x80)+(a*16), 0);     
  87.   for (b=0;b<16;b++)
  88.    I2CSendByte(array[(a*16)+b]);  //DDCRAM Write to EEPROM
  89.       I2CSendStop(); 
  90.   Delay_Xms(30);
  91. }
  92. }
  93. //*******************************************************************************************
  94. /*
  95. void MovEEPROM_2(Byte *array)   //128 byte
  96. {
  97.     Byte a,b;
  98.     for (a=0;a<8;a++)
  99. {
  100.       I2CSendAddr(ADDR_EDID1, (0x80)+(a*16), 0);     
  101.   for (b=0;b<16;b++)
  102.    I2CSendByte(array[(a*16)+b]);  //DDCRAM Write to EEPROM
  103.       I2CSendStop(); 
  104.   Delay_Xms(30);
  105. }
  106. }
  107. */
  108. #endif//#if(USE_MCU_DDC)