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

📄 adc.c

📁 infineon的HT166的AD转换程序
💻 C
📖 第 1 页 / 共 2 页
字号:
  ///  - the data reduction filter is disabled
  ///  - the event interrupt is disabled
  ///  - the wait-for-read mode is disabled
  ///  - the VF unchaned by read access to RESRxH/RESRAxH

  ADC_RCR1      =  0x00;         // load result control register 1

  ///  Configuration of Result Control Register 2
  ///  - the data reduction filter is disabled
  ///  - the event interrupt is disabled
  ///  - the wait-for-read mode is disabled
  ///  - the VF unchaned by read access to RESRxH/RESRAxH

  ADC_RCR2      =  0x00;         // load result control register 2

  ///  Configuration of Result Control Register 3
  ///  - the data reduction filter is disabled
  ///  - the event interrupt is disabled
  ///  - the wait-for-read mode is disabled
  ///  - the VF unchaned by read access to RESRxH/RESRAxH

  ADC_RCR3      =  0x00;         // load result control register 3

  SFR_PAGE(_ad5, noSST);         // switch to page 5

  ///  -----------------------------------------------------------------------
  ///  Configuration of Channel Interrupt Node Pointer Register:
  ///  -----------------------------------------------------------------------
  ///  - the SR 0 line become activated if channel 0 interrupt is generated
  ///  - the SR 0 line become activated if channel 1 interrupt is generated
  ///  - the SR 0 line become activated if channel 2 interrupt is generated
  ///  - the SR 0 line become activated if channel 3 interrupt is generated
  ///  - the SR 0 line become activated if channel 4 interrupt is generated
  ///  - the SR 0 line become activated if channel 5 interrupt is generated
  ///  - the SR 0 line become activated if channel 6 interrupt is generated
  ///  - the SR 0 line become activated if channel 7 interrupt is generated

  ADC_CHINPR    =  0x00;         // load channel interrupt node pointer 
                                 // register 

  ///  -----------------------------------------------------------------------
  ///  Configuration of Event Interrupt Node Pointer Registers:
  ///  -----------------------------------------------------------------------
  ///  - the SR 0 line become activated if the event 0 interrupt is generated
  ///  - the SR 0 line become activated if the event 1 interrupt is generated
  ///  - the SR 0 line become activated if the event 4 interrupt is generated
  ///  - the SR 0 line become activated if the event 5 interrupt is generated
  ///  - the SR 0 line become activated if the event 6 interrupt is generated
  ///  - the SR 0 line become activated if the event 7 interrupt is generated

  ADC_EVINPR    =  0x00;         // load event interrupt set flag register 

  SFR_PAGE(_ad0, noSST);         // switch to page 0

  ///  -----------------------------------------------------------------------
  ///  Configuration of Limit Check Boundary:
  ///  -----------------------------------------------------------------------

  ADC_LCBR      =  0xB7;         // load limit check boundary register

  ///  -----------------------------------------------------------------------
  ///  Configuration of External Trigger Control:
  ///  -----------------------------------------------------------------------
  ///  - the trigger input ETR00 is selected for Source 0
  ///  - the trigger input ETR10 is selected for Source 1
  ///  - the synchronizing stage is not in external trigger input REQTR0 path
  ///  - the synchronizing stage is not in external trigger input REQTR1 path

  ADC_ETRCR     =  0x00;         // load external trigger control register

  SFR_PAGE(_ad6, noSST);         // switch to page 6

  ///  -----------------------------------------------------------------------
  ///  Configuration of Conversion Queue Mode Register:
  ///  -----------------------------------------------------------------------
  ///  - the gating line is permanently 1
  ///  - the external trigger is disabled
  ///  - the trigger mode 0 is selected

  ADC_QMR0      =  0x01;         // load queue mode register

  ///  -----------------------------------------------------------------------
  ///  Configuration of Conversion Request Mode Registers:
  ///  -----------------------------------------------------------------------
  ///  - the gating line is permanently 0
  ///  - the external trigger is disabled
  ///  - the source interrupt is disabled
  ///  - the autoscan functionality is disabled

  ADC_CRMR1     =  0x00;         // load conversion request mode register 1

  SFR_PAGE(_ad0, noSST);         // switch to page 0

  ADC_GLOBCTR  |=  0x80;         // turn on Analog part

  ///  - ADC-Interrupt (EADC) remains disabled


  // USER CODE BEGIN (ADC_Init,3)

  // USER CODE END

} //  End of function ADC_vInit


//****************************************************************************
// @Function      void ADC_vStartSeqReqChNum(ubyte ubExtTrg, ubyte ubEnIntr, 
//                ubyte ubRFill, ubyte ubChannelNum) 
//
//----------------------------------------------------------------------------
// @Description   This function request software controlled conversion for 
//                new channel.
//                
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    ubExtTrg: 
//                External Trigger : defines external trigger
// @Parameters    ubEnIntr: 
//                Enable Source Interrupt : defines source interrupt
// @Parameters    ubRFill: 
//                Refill : defines the refill
// @Parameters    ubChannelNum: 
//                Name of the Request Channel Number (0 - 7)
//
//----------------------------------------------------------------------------
// @Date          2008-4-15
//
//****************************************************************************

void ADC_vStartSeqReqChNum(ubyte ubExtTrg, ubyte ubEnIntr, ubyte ubRFill, ubyte ubChannelNum)
{

  ubyte ubVal = 0;
  if (ubExtTrg == 1){ ubVal = 0x80;}
  if (ubEnIntr == 1){ ubVal = ubVal + 0x40;}
  if (ubRFill == 1){ ubVal = ubVal + 0x20;}
  ubVal = ubVal + (ubChannelNum & 0x07);

  SFR_PAGE(_ad6, SST1);          // switch to page 6

  ADC_QINR0 = ubVal; // requested channel 

  SFR_PAGE(_ad0, RST1);          // restore the old ADC page

} //  End of function ADC_vStartSeqReqChNum


//****************************************************************************
// @Function      ubyte ADC_ubBusy(void) 
//
//----------------------------------------------------------------------------
// @Description   This function checks the conversion state of the current 
//                ADC-channel by examination of the busy flag (BUSY). It 
//                returns '1' while a conversion is running.
//
//----------------------------------------------------------------------------
// @Returnvalue   1 if conversion is currently active, else 0
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          2008-4-15
//
//****************************************************************************

ubyte ADC_ubBusy(void)
{
  ubyte ubResult = 0;

  SFR_PAGE(_ad0, SST1);          // switch to page 0

  ubResult = ADC_GLOBSTR & 0x01;

  SFR_PAGE(_ad0, RST1);          // restore the old ADC page

  return(ubResult);
} //  End of function ADC_ubBusy


//****************************************************************************
// @Function      uword ADC_uwGetResultData0(void) 
//
//----------------------------------------------------------------------------
// @Description   This function reads the 8- or 10-bit conversion results 
//                from result register 0
//
//----------------------------------------------------------------------------
// @Returnvalue   Conversion Result
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          2008-4-15
//
//****************************************************************************

uword ADC_uwGetResultData0(void)
{
  uword uwResult = 0;

  SFR_PAGE(_ad2, SST1);          // switch to page 2

    if ( ADC_RESR0L & 0x10 )       //  if Result Register0 contains valid data
    {
    uwResult = (uword)((ADC_RESR0H << 2) + ((ADC_RESR0L >> 6)& 0x03));   // for 10-bit resolution (without accumulation)
    }

  SFR_PAGE(_ad0, RST1);          // restore the old ADC page

  return(uwResult);
} //  End of function ADC_uwGetResultData0




// USER CODE BEGIN (ADC_General,10)

// USER CODE END

⌨️ 快捷键说明

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