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

📄 bsp.c

📁 在IAR EWARM开发环境下的ucos_2操作系统在LPC2200上的应用
💻 C
📖 第 1 页 / 共 3 页
字号:
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
void  DispDataWr (CPU_INT08U data)
{
    CPU_INT08U  value;


    BSP_DispRW_Low();                                           /* Set R/W write LOW to write to the LCD module             */

    BSP_DispE_High();                                           /* Write the UPPER nibble to the LCD module                 */
    value  =  (data & 0xF0);                                    
    value |=  (BSP_74HC595_Data & 0x0F);                        /* Only modified the data line (see Note #1)                */

    BSP_74HC595_WrByte(value);
   
    DispDly_uS(100);
    BSP_DispE_Low();

    DispDly_uS(100);                                            /* Write the LOWER nibble to the LCD module                 */
    BSP_DispE_High();
    value  =  (data & 0x0F) << 4;
    value |=  (BSP_74HC595_Data & 0x0F);
    BSP_74HC595_WrByte(value);
 
    DispDly_uS(100);
    BSP_DispE_Low();
}

#if DISP_BUS_WIDTH == 4
void DispDataWrOneNibble(CPU_INT08U data)
{
    CPU_INT08U  value;


    BSP_DispRW_Low();                                          /* Set R/W write LOW to write to the LCD module             */

    BSP_DispE_High();                                          /* Write the UPPER nibble to the LCD module                 */
    value  =  data & 0xF0;
    value |=  (BSP_74HC595_Data & 0x0F);
    BSP_74HC595_WrByte(value);
 
    DispDly_uS(100);
    BSP_DispE_Low();
}
#endif

#endif


/*
*********************************************************************************************************
*                                               DispDly_uS()
*
* Description : Delay for the specified number of microseconds.
*
* Argument(s) : us      Number of microseconds
*
* Return(s)   : none.
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
void  DispDly_uS (CPU_INT32U us)
{
    CPU_INT16U  ms_dly;
    CPU_INT32U  pclk_freq;
    CPU_INT32U  tmr_dly;

   
    if (us < 1000) {
        pclk_freq = BSP_CPU_PclkFreq();
        tmr_dly   = (pclk_freq / 1000000L) *  us ;
        T2TCR     = 0;                                          /* Disable timer 0.                                         */
        T2PC      = 0;                                          /* Prescaler is set to no division.                         */
        T2CCR     = 0;                                          /* Capture is disabled.                                     */
        T2EMR     = 0;                                          /* No external match output.                                */
        T2TCR     = 1;                                          /* Enable timer 0                                           */

        while ((CPU_INT32U)T2TC < tmr_dly) {
            ;
        }
    } else {
        ms_dly = us / 1000;
        OSTimeDlyHMSM(0, 0, 0, ms_dly);
    }
    
   
}
#endif


/*
*********************************************************************************************************
*                                            DispSel()
*
* Description : Change the Register Select control line to the LCD controller to select either
*               command or data register.
*
* Argument(s) : sel         Indicates whether command or data register should be selected:
*                           DISP_SEL_CMD_REG    select command register
*                           DISP_SEL_DATA_REG   select data    register
*
* Return(s)   : none.
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
void  DispSel (CPU_INT08U sel)
{
    if (sel == DISP_SEL_CMD_REG) {
        BSP_74HC595_ClrBit(BSP_74HC595_LCD_RS_PIN_NBR);        /* Select the command register (RS low)                     */
    } else {
        BSP_74HC595_SetBit(BSP_74HC595_LCD_RS_PIN_NBR);        /* Select the data    register (RS high)                    */
    }
}
#endif


/*
*********************************************************************************************************
*                                      DISPLAY CONTROL LINE FUNCTIONS
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
static  void  BSP_DispE_High (void)
{
    BSP_74HC595_SetBit(BSP_74HC595_LCD_E_PIN_NBR);
}


static  void  BSP_DispE_Low (void)
{
    BSP_74HC595_ClrBit(BSP_74HC595_LCD_E_PIN_NBR);
}

static  void  BSP_DispRW_Low (void)
{
    BSP_74HC595_ClrBit(BSP_74HC595_LCD_RW_PIN_NBR);
}
#endif

/*
*********************************************************************************************************
*                                              74HC595 FUNCTIONS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                            BSP_74HC595_Init()
*
* Description : Initializes the I/O of the IC 74HC5990
*           
* Argument(s) : none.
*                                                      
* Return(s)   : none.
*
* Caller(s)   : DispInitPort()
*
* Note(s)     : (1)    The LPC2103 is connected to the 74HC595 (8 bit serial to parallel converter) with the following
*                      connection:
*
*                      +------------+                              +---------+
*                      |            |  P0.24        Serial Data    |         | 1 - 3   LCD Ctrl Lines
*                      |            |----------------------------->|         |-------->
*                      |            |  P0.25        Shift Reg clk  | 74HC595 | 4 - 7   LCD Data Line
*                      | LPC 2103   |----------------------------->|         |-------->
*                      |            |  P0.26        Out   Reg clk  |         | 0       LCD Light 
*                      |            |----------------------------->|         |-------->
*                      +------------+                              +---------+
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
static  void  BSP_74HC595_Init(void)
{
    IODIR |= BSP_GPIOO_74HC595_GRP;

    BSP_74HC595_ST_CP_LOW();                                    /* Initialize the 74HC595 inputs see (Note  #1)              */
    BSP_74HC595_DS_LOW();
    BSP_74HC595_SH_CP_LOW();

    BSP_74HC595_WrByte(0x00);                                   /* Initialize the parallel output to 0x00 (Note  #1)         */
}
#endif

/*
*********************************************************************************************************
*                                            BSP_74HC5940_SetBit()
*
* Description : Set a output bit using the serial to parallel IC 74HC5990
*           
*
* Argument(s) : bit      bit position to be set.         
*                                                      
* Return(s)   : none.
*
* Caller(s)   : BSP_DispE_High()
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
static  void  BSP_74HC595_SetBit  (CPU_INT08U  bit) 
{
    CPU_INT08U  reg_val;    
    
    
    reg_val = BSP_74HC595_Data | DEF_BIT(bit);
 
    BSP_74HC595_WrByte(reg_val);    
}
#endif

/*
*********************************************************************************************************
*                                            BSP_74HC5940_ClrBit()
*
* Description : Reset a output bit using the serial to parallel IC 74HC5990
*           
*
* Argument(s) : bit      bit position to be cleared.         
*                                                      
* Return(s)   : none.
*
* Caller(s)   : BSP_DispE_Low()
*               BSP_DispRW_Low()
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
static  void  BSP_74HC595_ClrBit  (CPU_INT08U  bit) 
{
    CPU_INT08U  reg_val;
    
    
    reg_val = BSP_74HC595_Data & (~DEF_BIT(bit));
 
    BSP_74HC595_WrByte(reg_val);    

}
#endif

/*
*********************************************************************************************************
*                                            BSP_74HC595_WrByte()
*
* Description : Writes a byte to the 74HC595 device
*           
* Argument(s) : data.  byte to be write
*                                                      
* Return(s)   : none.
*
* Caller(s)   : BSP_74HC595_Init()
*               BSP_74HC595_SetBit()
*               BSP_74HC595_ClrBit
*               DispDataWr()
*               DispDataWrOneNibble()
*
* Note(s)     : The LPC2103 is connected to the 74HC595 (8 bit serial to parallel converter) with the following
*               connection:
*
*              +------------+                              +---------+
*              |            |  P0.24        Serial Data    |         | 1 - 3   LCD Ctrl Lines
*              |            |----------------------------->|         |-------->
*              |            |  P0.25        Shift Reg clk  | 74HC595 | 4 - 7   LCD Data Line
*              | LPC 2103   |----------------------------->|         |-------->
*              |            |  P0.26        Out   Reg clk  |         | 0       LCD Light 
*              |            |----------------------------->|         |-------->
*              +------------+                              +---------+
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
static  void  BSP_74HC595_WrByte  (CPU_INT08U  data) 
{
    CPU_INT08U  i;
      
    for (i = BSP_74HC595_NBR_OUT; i > 0; i--) {
        if ((data & DEF_BIT(i - 1)) == 0) {
            BSP_74HC595_DS_LOW();
        } else {
            BSP_74HC595_DS_HIGH();                
        }                    
        BSP_74HC595_SH_CP_HIGH();
        BSP_74HC595_SH_CP_LOW();        
    }

    BSP_74HC595_ST_CP_HIGH();
    BSP_74HC595_ST_CP_LOW();
    
    BSP_74HC595_Data = data;
}
#endif

/*
*********************************************************************************************************
*********************************************************************************************************
**                                       PB, LED, AND ADC FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                             LED_Init()
*
* Description : Setup the I/O for the LEDs.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : BSP_Init()
*********************************************************************************************************
*/

void  BSP_LED_Init (void)
{
    IODIR |= BSP_GPI00_LED_GRP;                                 /* Set the P0.0-P0.15 as a output                      */    
}

/*
*********************************************************************************************************
*                                             BSP_LED_On()
*
* Description : Turn ON any or all the LEDs on the board.
*
* Argument(s) : led     The ID of the LED to control:
*
*                       0    turns ON all  LEDs  on the board
*                       1    turns ON user LED1  on the board
*                       2    turns ON user LED2  on the board
*                       . 
*                       . 
*                       16   turns ON user LED16 on the board
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*
*********************************************************************************************************
*/

void  BSP_LED_On (CPU_INT08U led)
{
    if (led > 0) { 
        IOSET = DEF_BIT(led - 1);
    } else {
        IOSET = BSP_GPI00_LED_GRP;
    }
}

/*
*********************************************************************************************************
*                                             BSP_LED_Off()
*
* Description : Turn OFF any or all the LEDs on the board.
*
*
* Argument(s) : led     The ID of the LED to control:
*
*                       0    turns OFF all  LEDs  on the board
*                       1    turns OFF user LED1  on the board
*                       2    turns OFF user LED2  on the board
*                       . 
*                       . 
*                       16   turns OFF user LED16 on the board
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*********************************************************************************************************
*/

void  BSP_LED_Off (CPU_INT08U led)
{
   if (led > 0) { 
        IOCLR = DEF_BIT(led - 1);
    } else {
        IOCLR =BSP_GPI00_LED_GRP;
    }
}

/*
*********************************************************************************************************
*                                             BSP_LED_Toggle()
*
* Description : TOGGLE any or all the LEDs on the board.
*

⌨️ 快捷键说明

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