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

📄 cfg.c

📁 常用外围接口的程序设计
💻 C
📖 第 1 页 / 共 2 页
字号:
/*$PAGE*/
/*
*********************************************************************************************************
*                                        CLOCK/CALENDAR MODULE
*********************************************************************************************************
*/

#if MODULE_CLK
#endif

/*
*********************************************************************************************************
*                                             TIMER MANAGER
*********************************************************************************************************
*/

#if MODULE_TMR
#endif

/*$PAGE*/
/*
*********************************************************************************************************
*                                          DISCRETE I/O MODULE
*                                        INITIALIZE PHYSICAL I/Os
*
* Description : This function is by DIOInit() to initialze the physical I/O used by the DIO driver.
* Arguments   : None.
* Returns     : None.
* Notes       : The physical I/O is assumed to be an 82C55A chip initialized as follows:
*                   Port A = OUT  (Discrete outputs)   (Address 0x0300)
*                   Port B = IN   (Discrete inputs)    (Address 0x0301)
*                   Port C = OUT  (not used)           (Address 0x0302)
*                   Control Word                       (Address 0x0303)
*               Refer to the Intel 82C55A data sheet.
*********************************************************************************************************
*/

#if  MODULE_DIO
void  DIOInitIO (void)
{
    outp(0x0303, 0x82);                          /* Port A = OUT, Port B = IN, Port C = OUT            */
}

/*
*********************************************************************************************************
*                                           DISCRETE I/O MODULE
*                                           READ PHYSICAL INPUTS
*
* Description : This function is called to read and map all of the physical inputs used for discrete
*               inputs and map these inputs to their appropriate discrete input data structure.
* Arguments   : None.
* Returns     : None.
*********************************************************************************************************
*/

void  DIRd (void)
{
    DIO_DI *pdi;
    INT8U   i;
    INT8U   in;
    INT8U   msk;


    pdi = &DITbl[0];                                       /* Point at beginning of discrete inputs    */
    msk = 0x01;                                            /* Set mask to extract bit 0                */
    in  = inp(0x0301);                                     /* Read the physical port (8 bits)          */
    for (i = 0; i < 8; i++) {                              /* Map all 8 bits to first 8 DI channels    */
        pdi->DIIn   = (BOOLEAN)(in & msk) ? 1 : 0;
        msk       <<= 1;
        pdi++;
    }
}

/*
*********************************************************************************************************
*                                           DISCRETE I/O MODULE
*                                         UPDATE PHYSICAL OUTPUTS
*
* Description : This function is called to map all of the discrete output channels to their appropriate
*               physical destinations.
* Arguments   : None.
* Returns     : None.
*********************************************************************************************************
*/

void  DOWr (void)
{
    DIO_DO *pdo;
    INT8U   i;
    INT8U   out;
    INT8U   msk;


    pdo = &DOTbl[0];                        /* Point at first discrete output channel                  */
    msk = 0x01;                             /* First DO will be mapped to bit 0                        */
    out = 0x00;                             /* Local 8 bit port image                                  */
    for (i = 0; i < 8; i++) {               /* Map first 8 DOs to 8 bit port image                     */
        if (pdo->DOOut == TRUE) {
            out |= msk;
        }
        msk <<= 1;
        pdo++;
    }
    outp(0x0300, out);                      /* Output port image to physical port                      */
}
#endif

/*$PAGE*/
/*
*********************************************************************************************************
*                                          ANALOG I/O MODULE
*                                       INITIALIZE PHYSICAL I/Os
*
* Description : This function is called by AIOInit() to initialize the physical I/O used by the AIO
*               driver.
* Arguments   : None.
* Returns     : None.
*********************************************************************************************************
*/

#if  MODULE_AIO
void  AIOInitIO (void)
{
    /* This is where you will need to put you initialization code for the ADCs and DACs                */
    /* You should also consider initializing the contents of your DAC(s) to a known value.             */
    
    AITestCnts = 0;
}

/*
*********************************************************************************************************
*                                           ANALOG I/O MODULE
*                                          READ PHYSICAL INPUTS
*
* Description : This function is called to read a physical ADC channel.  The function is assumed to
*               also control a multiplexer if more than one analog input is connected to the ADC.
* Arguments   : ch     is the ADC logical channel number (0..AIO_MAX_AI-1).
* Returns     : The raw ADC counts from the physical device.
*********************************************************************************************************
*/

INT16S  AIRd (INT8U ch)
{
    /* This is where you will need to provide the code to read your ADC(s).                            */
    /* AIRd() is passed a 'LOGICAL' channel number.  You will have to convert this logical channel     */
    /* number into actual physical port locations (or addresses) where your MUX. and ADCs are located. */
    /* AIRd() is responsible for:                                                                      */
    /*     1) Selecting the proper MUX. channel,                                                       */
    /*     2) Waiting for the MUX. to stabilize,                                                       */
    /*     3) Starting the ADC,                                                                        */
    /*     4) Waiting for the ADC to complete its conversion,                                          */
    /*     5) Reading the counts from the ADC and,                                                     */
    /*     6) Returning the counts to the calling function.                                            */

                                       /* Simulate a RAMPING voltage                                   */
    AITestCnts += 10;                  /* Always assume ADC returns a signed 16-bit count              */
    if (AITestCnts > 28670) {          /* Max. counts for LM34A at 300 F, with gain of 2.5             */
        AITestCnts = 0;
    }
    return (AITestCnts);
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                           ANALOG I/O MODULE
*                                        UPDATE PHYSICAL OUTPUTS
*
* Description : This function is called to write the 'raw' counts to the proper analog output device
*               (i.e. DAC).  It is up to this function to direct the DAC counts to the proper DAC if more
*               than one DAC is used.
* Arguments   : ch     is  the DAC logical channel number (0..AIO_MAX_AO-1).
*               cnts   are the DAC counts to write to the DAC
* Returns     : None.
*********************************************************************************************************
*/

void  AOWr (INT8U ch, INT16S cnts)
{
    ch   = ch;
    cnts = cnts;

    /* This is where you will need to provide the code to update your DAC(s).                          */
    /* AOWr() is passed a 'LOGICAL' channel number.  You will have to convert this logical channel     */
    /* number into actual physical port locations (or addresses) where your DACs are located.          */
    /* AOWr() is responsible for writing the counts to the selected DAC based on a logical number.     */
}
#endif

⌨️ 快捷键说明

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