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

📄 adc.c

📁 keil C51 LCD 驱动源码,其中还有I2C驱动,ADC驱动,键盘操作等,是一个完整的keil源代码,供大家参考
💻 C
📖 第 1 页 / 共 3 页
字号:
       AdcWriteByte(0x0C,Data9884[Item][2]);  // Reg0C VCOrange, Charge pump current
       AdcWriteByte(0x0D,0x00);               // Reg0D
    }
    else if( ModeInputport[Item] == 1 )       // double_sampling,single port
    {
 #if   ZURAC_HWMD
       if( Z2_OUTPUTHPOL )  bval = 0xF0;
       else                 bval = 0xD0;
 #else
       if( CurrentHPol )    bval = 0xF0; 
       else                 bval = 0xD0;
 #endif                    
       AdcWriteByte(0x0A,bval);               // Reg0A
       
       bval = (PhaseValue & 0x0F)*2 + 1;
       AdcWriteByte(0x0B,bval<<3);            // Reg0B phase
       
       AdcWriteByte(0x0C,Data9884[Item][3]);  // Reg0C VCOrange, Charge pump current
       
       if( PhaseValue<16 )  bval = 0x10;      
       else                 bval = 0x00;      
       AdcWriteByte(0x0D,bval);               // Reg0D       
    }
    else /* ModeInputport[Item] == 2 */       // normal sampling,dual port
    {
 #if   ZURAC_HWMD
       if( Z2_OUTPUTHPOL )  bval = 0xF0;
       else                 bval = 0xD0;
 #else
       if( CurrentHPol )    bval = 0xF0;
       else                 bval = 0xD0;
 #endif
       AdcWriteByte(0x0A,bval);               // Reg0A
       AdcWriteByte(0x0B,PhaseValue<<3);      // Reg0B phase
       AdcWriteByte(0x0C,Data9884[Item][2]);  // Reg0C VCOrange, Charge pump current 
       AdcWriteByte(0x0D,0x00);               // Reg0D
    }
    
#elif (ADC_CHIP==ADI_9883)
    Word wval;
    Byte bval;
        
    wval = (ClockValue - 1) << 4;

    bval = SyncSource & 0x03;    
    if( bval==0 )       bval = 0x5B;   // Reg0E Sync control, SOG      
    else if( bval==1 )  bval = 0x53;   // Reg0E Sync control, Composite
    else /* bval==3 */  bval = 0x40;   // Reg0E Sync control, Seperate 

    AdcWriteWord(0x01, wval);                        // Reg01,02 clockvalue
    AdcWriteByte(0x03, Data9883[Item][0]);           // Reg03 VCO && Charge Pump Current
    AdcWriteByte(0x04, PhaseValue<<3);               // Reg04 phase                   
    AdcWriteByte(0x05, Data9883[Item][1]);           // Reg05 Clamp placement         
    AdcWriteByte(0x06, Data9883[Item][2]);           // Reg06 Clamp duration          
    AdcWriteByte(0x07, Data9883[Item][3]);           // Reg07 Hsync output pulse width
    AdcWriteByte(0x08, GainModify(U1RgainValue));    // Reg08 R Gain                  
    AdcWriteByte(0x09, GainModify(U1GgainValue));    // Reg09 G Gain                  
    AdcWriteByte(0x0A, GainModify(U1BgainValue));    // Reg0A B Gain                  
    AdcWriteByte(0x0B, ColorModify(M_BrightnessR,U1RgainValue)); // Reg0B R OFFSET    
    AdcWriteByte(0x0C, ColorModify(M_BrightnessG,U1GgainValue)); // Reg0C G OFFSET    
    AdcWriteByte(0x0D, ColorModify(M_BrightnessB,U1BgainValue)); // Reg0D B OFFSET    
    AdcWriteByte(0x0E, bval);                        // Reg0E Sync control
    AdcWriteByte(0x0F, 0x5E);                        // Reg0F MISC control
    AdcWriteByte(0x10, 0xB8);                        // Reg10 Sync-on-Green  Threshold 
    AdcWriteByte(0x11, 0x20);                        // Reg11 Sync Separator Threshold 
    AdcWriteByte(0x12, 0x00);                        // Reg12 Pre-coast                
    AdcWriteByte(0x13, 0x00);                        // Reg13 Post-coast               

#elif ( ADC_CHIP==ADI_9887 )
    Word wval;
    Byte bval;    
    
    if( ModeInputport[Item]==1 )  /* 1:Single,Double-Sampling */
        wval = (ClockValue*2 - 1) << 4;
    else /* 0:Single,Normal-sampling, 2,Dual-Port-Sampling*/
        wval = (ClockValue - 1) << 4;
    
    AdcWriteWord(0x01, wval);                        // Reg01,02 clockvalue
    AdcWriteByte(0x03, Data9887[Item][0]);           // Reg03 VCO && Charge Pump Current
    AdcWriteByte(0x04, PhaseValue<<3);               // Reg04 phase                     
    AdcWriteByte(0x05, Data9887[Item][1]);           // Reg05 Clamp placement           
    AdcWriteByte(0x06, Data9887[Item][2]);           // Reg06 Clamp duration            
    AdcWriteByte(0x07, Data9887[Item][3]);           // Reg07 Hsync output pulse width  
    AdcWriteByte(0x08, GainModify(U1RgainValue));    // Reg08 R Gain                    
    AdcWriteByte(0x09, GainModify(U1GgainValue));    // Reg09 G Gain                    
    AdcWriteByte(0x0A, GainModify(U1BgainValue));    // Reg0A B Gain                    
    AdcWriteByte(0x0B, ColorModify(M_BrightnessR,U1RgainValue)); // Reg0B R OFFSET      
    AdcWriteByte(0x0C, ColorModify(M_BrightnessG,U1GgainValue)); // Reg0C G OFFSET      
    AdcWriteByte(0x0D, ColorModify(M_BrightnessB,U1BgainValue)); // Reg0D B OFFSET      
    AdcWriteByte(0x0E, Data9887[Item][4]);           // Reg0E Mode Control 1            
    AdcWriteByte(0x0F, 0xD0);                        // Reg0F PLL and Clamp Control     
    AdcWriteByte(0x10, 0x74);                        // Reg10 Mode Control 2            
    
    if( InputSource==INPUT_DIGITAL )
    {
        bval = 0xE9;
    }
    else /* INPUT_ANALOG */
    { 
        bval = SyncSource & 0x03;        
        if( bval==0 )       bval = 0xBD;     // SOG       
        else if( bval==1 )  bval = 0xAD;     // Composite
        else /* bval==3 */  bval = 0xA9;     // Seperate
    }
    AdcWriteByte(0x12, bval);                // Reg12 Active Interface
    
    AdcWriteByte(0x13, 0x20);                // Reg13 Sync Seperator threshold
    AdcWriteByte(0x14, 0x12);                // Reg14 Control Bit             
    AdcWriteByte(0x16, 0xB8);                // Reg16 Control Bit 2 
    AdcWriteByte(0x17, 0x00);                // Reg17 Pre-Coast     
    AdcWriteByte(0x18, 0x00);                // Reg18 Post-Coast    
    AdcWriteByte(0x19, 0x00);                // Reg19 Test Register 
    AdcWriteByte(0x1A, 0xFF);                // Reg1A Test Register 
    AdcWriteByte(0x1B, 0x80);                // Reg1B Test Register 
#endif
    return;        
}
/***************************************************************************/
/***************************************************************************/
void AdcSource(Byte sel)
{
#if (ADC_CHIP==ADI_9883)
    sel=0;                                   // Don't care this command
    AdcWriteByte(0x0E, 0x40);                // Reg0E Active Interface
#endif
#if (ADC_CHIP==ADI_9887)
    Byte  bval;
        
    if( sel==INPUT_DIGITAL )   bval = 0xE9;
    else /* INPUT_ANALOG */    bval = 0xA9;
    AdcWriteByte(0x12, bval);                // Reg12 Active Interface   
#endif
    return;
}
/***************************************************************************/
/***************************************************************************/
void AdcSync(Byte sel)
{
#if (ADC_CHIP==ADI_9883)        
    Byte  bval;
        
    if( sel==0 )       bval = 0x40;          // Seperate
    else if( sel==1)   bval = 0x53;          // Composite
    else /* sel==2 */  bval = 0x5B;          // SOG
    AdcWriteByte(0x0E, bval);                // Reg0E Active Interface
#elif (ADC_CHIP==ADI_9887)
    Byte  bval;
        
    if( InputSource==INPUT_DIGITAL )
    {
       bval = 0xE9;                          // Seperate
    }
    else
    {
       if( sel==0 )       bval = 0xA9;       // Seperate
       else if( sel==1)   bval = 0xAD;       // Composite
       else /* sel==2 */  bval = 0xBD;       // SOG
    }
    AdcWriteByte(0x12, bval);                // Reg12 Active Interface
#endif
    return;
}
/***************************************************************************/
/***************************************************************************/
Byte  GainModify ( Byte gain )
{
    int  ival;

    if( ContrastValue < 10 ) ival = 10;
    else if( ContrastValue > 245 ) ival = 245;
    else ival = ContrastValue;
    ival = (int)ival - 127 + (int)gain;  /* assume mean value is 127 */
    if( ival < 0 )          ival = 0;
    else if( ival > 0xFF )  ival = 0xFF;
    return  ((Byte)(0xFF - ival));
}
/***************************************************************************/
/* Equation for color modify                                               */
/***************************************************************************/
Byte  ColorModify ( Byte offset, Byte gain )
{    
#if (ADC_CHIP==ADI_9887 || ADC_CHIP==ADI_9883)
    // NewOffset = OldOffset - ((OldOffset-64)*(1-(OldGain+255)/(NewGain+255)));
    //           = (OldOffset-64)*(OldGain+255)/NewGain+255) + 64;
    long   f1,f2,f3;
    Byte   bval;

    if( ContrastValue < 10 ) f2 = 10;
    else if( ContrastValue > 245 ) f2 = 245;
    else f2 = ContrastValue;
    gain = 0xFF - gain;
    offset = 0x7F - offset;
    /* BILL20000720,modify the Contrast T function for ADC9887 */
    f3 = (long) gain + 255;         /* old gain, at ContrastValue 128 */
    f2 = (long) gain + f2 - 128 + 255;    /* new gain */
    if( f2 < 255 )   f2 = 255;     /* limit the smallest value */
    if( f2 > 510 )   f2 = 510;     /* limit the largest  value */

    f1 = (long) offset - 64;        /* old offset */
    f1 = (((f1 * f3) / f2) + 64);

    if( f1 < 0 )         f1 = 0;
    else if( f1 > 127 )  f1 = 127;
    bval = ((Byte) f1) << 1;
    return bval;
#else                                                                        
    // NewOffset = OldOffset - ((OldOffset-32)*(1-(OldGain+255)/(NewGain+255)));        
    //           = (OldOffset-32)*(OldGain+255)/NewGain+255) + 32;          
    long   f1,f2,f3;
    Byte   bval;

    if( ContrastValue < 10 ) f2 = 10;
    else if( ContrastValue > 245 ) f2 = 245;
    else f2 = ContrastValue;
    gain = 0xFF - gain;
    offset = 0x3F - offset;
    /* BILL19990820,modify the Contrast T function for ADC9884 */
    f3 = (long) gain + 255;         /* old gain, at ContrastValue 127 */
    f2 = (long) gain + f2 - 127 + 255;    /* new gain */
    if( f2 < 255 )   f2 = 255;     /* limit the smallest value */
    if( f2 > 510 )   f2 = 510;     /* limit the largest  value */
    f1 = (long) offset - 32;        /* old offset */
    f1 = (((f1 * f3) / f2) + 32);
    if( f1 < 0 )        f1 = 0;
    else if( f1 > 63 )  f1 = 63;
    bval = ((Byte) f1) << 2;
    return bval;
#endif    
}
/***************************************************************************/
/* void AdcWritebyte(Byte reg,Byte val)                                    */
/*      Write one byte data to ADC register                                */
/***************************************************************************/
void AdcWriteWord(Byte reg,Word val)
{
    SlvAdr    = AD9884_ADDR;
    ByteCnt   = 3;
    TrmBuf[0] = reg;
    TrmBuf[1] = HIBYTE(val);
    TrmBuf[2] = LOBYTE(val);
    SendData();
    return;
} 
void AdcWriteByte(Byte reg,Byte val)
{
    SlvAdr    = AD9884_ADDR;
    ByteCnt   = 2;
    TrmBuf[0] = reg;
    TrmBuf[1] = val;
    SendData();
    return;
} 

⌨️ 快捷键说明

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