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

📄 bsp.c

📁 lpc2378 iar开发环境 嵌入系统程序
💻 C
📖 第 1 页 / 共 3 页
字号:

        case 1:
             Fin        =  MAIN_OSC_FRQ;
             break;

        case 2:
             Fin        =  RTC_OSC_FRQ;
             break;

        default:
             Fin        =  IRC_OSC_FRQ;
             break;
    }

    if ((PLLSTAT & (1 << 25)) > 0) {                                    /* If the PLL is currently enabled and connected            */
        msel            = (CPU_INT32U)(PLLSTAT & 0x3FFF) + 1;           /* Obtain the PLL multiplier                                */
        nsel            = (CPU_INT32U)((PLLSTAT >>   16) & 0x0F) + 1;   /* Obtain the PLL divider                                   */
        pllClkFrq       = (2 * msel * Fin / nsel);                      /* Compute the PLL output frequency                         */
    } else {
        pllClkFrq       = (Fin);                                        /* The PLL is bypassed                                      */
    }

    cClkDiv             = (CPU_INT08U)(CCLKCFG & 0x0F) + 1;             /* Obtain the CPU core clock divider                        */
    cClkFrq             = (CPU_INT32U)(pllClkFrq / cClkDiv);            /* Compute the ARM Core clock frequency                     */

    return (cClkFrq);
}

/*
*********************************************************************************************************
*                                          INITIALIZE I/Os
*
* Description : This function initializes the GPIO pins.  All the I/O pins are initialized in this function
*               so you don't have to look at multiple places for I/O initialization.
*
* Arguments   : none
*
* Note(s)     : 1) Refer to the LPC2378 User Manaul, Chapter 9 for a detailed Pin Assignment
*               2) The UARTS are connected as follows
*                  PO.2      UART0   Tx
*                  PO.3      UART0   Rx
*                  PO.15     UART1   Tx
*                  PO.16     UART1   Rx
*
*               3) The 2x16 LCD is connected as follows
*
*                  P1.24     D4       LCD Data 4     \
*                  P1.25     D5       LCD Data 5      |
*                  P1.26     D6       LCD Data 6      | 4-bit interface mode
*                  P1.27     D7       LCD Data 7     /

*                  P1.28     RS       Register Select
*                  P1.29     R/W      Read (H) / Write (L)
*                  P1.30     E        Enable
*
*               3) The onboard LEDs are connected as follows
*                  P2[7:0]   GPIO Port 2 Pins 7:0
*
*               4) The push button is connected as follows
*                  P2.10     GPIO Port 2.10
*********************************************************************************************************
*/

static  void  BSP_IO_Init (void)
{
    CPU_INT32U  value;


#if (OS_VIEW_MODULE > 0) && (OS_VIEW_COMM_SEL == OS_VIEW_UART_0)
    PINSEL0   &= ~(0x0F <<  4);                                         /* Clear the UART0 Function bits                            */
    PINSEL0   |=  (0x01 <<  4);                                         /* Configure P0.2 for use with UART0 TxD                    */
    PINSEL0   |=  (0x01 <<  6);                                         /* Configure P0.3 for use with UART0 RxD                    */
#endif

#if (OS_VIEW_MODULE > 0) && (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
    PINSEL0   &= ~(0x03 << 30);                                         /* Clear the UART1 Tx function bits                         */
    PINSEL1   &= ~(0x03 <<  0);                                         /* Clear the UART1 Rx function bits                         */
    PINSEL0   |=  (0x01 << 30);                                         /* Configure P0.30 for use with UART1 TxD                   */
    PINSEL1   |=  (0x01 <<  0);                                         /* Configure P1.0 for use with UART1 RxD                    */
#endif

#ifdef DISP_MODULE_PRESENT
    value      =  (3 << 24) | (3 << 26) | (3 << 28);                    /* Create a mask for the LCD Control function bits          */
    PINSEL3   &=  ~value;                                               /* Clear and configure the associated function bits as GPIO */

    value      =  (3 << 16) | (3 << 18) | (3 << 20) | (3 << 22);        /* Create a mask for the LCD Data function bits             */
    PINSEL3   &=  ~value;                                               /* Clear and configure the associated function bits as GPIO */

    value      =   LCD_BIT_DATA3 | LCD_BIT_DATA2 | LCD_BIT_DATA1 | LCD_BIT_DATA0 | LCD_BIT_E | LCD_BIT_RS | LCD_BIT_RW;
    IO1DIR    |=   value;                                               /* Configure all of the LCD pins as outputs                 */

    DispRW_High();                                                      /* Initialize the state of the LCD RW bit to High           */
#endif

    PINSEL2   &= ~(0xFF <<  0);                                         /* Clear P2[7:0] function bits enabling GPIO for the LEDs   */
    FIO20DIR  |=  (0xFF <<  0);                                         /* Configure P2[7:0] as output bits                         */

    PINSEL2   &= ~(0x03 << 30);                                         /* Clear P2.10 function bits, enabling GPIO function        */
    FIO20DIR  &= ~(0x01 << 10);                                         /* Configure P2.10 as an input bit                          */

    PINSEL10   =   0;                                                   /* Release ETM control of PORT 2 I/O pins                   */

    PINSEL1    = ~(0x03 << 20);                                         /* Select Port 0, pin 26 as GPIO (speaker pin)              */
    IO0CLR     =  (0x01 << 26);                                         /* Clear pin 26, prevent speaker usage humming              */
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                      WRITE DATA TO DISPLAY DEVICE
*
* Description : This function sends a single BYTE to the display device.
* Arguments   : 'data'  is the BYTE to send to the display device
* Returns     : none
* Notes       : 1) The Keil LPC2378 evaluation board uses a 4 bit interface.
*                  If an 8 bit interface is used. BSP_IO_Init() and DispDataWr() will need
*                  to be modified to reflect the new databus. In 8 bit mode, DispDataWrOneNibble()
*                  is not necessary.
*********************************************************************************************************
*/

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


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

    DispE_High();                                                       /* Write the UPPER nibble to the LCD module                 */
    value  =  ((data >> 4) & 0x0F) << 24;
    IO1SET = value;
    value  = (~(data >> 4) & 0x0F) << 24;
    IO1CLR = value;

    DispDly_uS(100);
    DispE_Low();

    DispDly_uS(100);                                                    /* Write the LOWER nibble to the LCD module                 */
    DispE_High();

    value  =  (data & 0x0F) << 24;
    IO1SET = value;
    value  = (~data & 0x0F) << 24;
    IO1CLR = value;

    DispDly_uS(100);
    DispE_Low();
}

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


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

    DispE_High();                                                       /* Write the UPPER nibble to the LCD module                 */
    value  =  ((data >> 4) & 0x0F) << 24;
    IO1SET = value;
    value  = (~(data >> 4) & 0x0F) << 24;
    IO1CLR = value;

    DispDly_uS(100);
    DispE_Low();
}
#endif
#endif                                                                  /* End #ifdef DISP_MODULE_PRESENT                           */

/*
*********************************************************************************************************
*                                               DELAY
*
* Description : This function is called to delay for the specified number of microseconds.
*
* Arguments   : us      Number of microseconds
*
* Returns     : none
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
void  DispDly_uS (CPU_INT32U us)
{
    CPU_INT32U  us_per_tick;
    CPU_INT32U  ticks;


    us_per_tick = 1000000L / OS_TICKS_PER_SEC;
    ticks       = us / us_per_tick + 1;
    OSTimeDly(ticks);
}
#endif

/*
*********************************************************************************************************
*                                  INITIALIZE DISPLAY DRIVER I/O PORTS
*
* Description : This initializes the I/O ports used by the display driver.
*
* Arguments   : none
*
* Returns     : none
*
* Note(s)     : 1) The I/Os for the LCD module are initialized in BSP_IO_Init().
*********************************************************************************************************
*/

#ifdef DISP_MODULE_PRESENT
void  DispInitPort (void)
{
}
#endif

/*
*********************************************************************************************************
*                                   SELECT COMMAND OR DATA REGISTER
*
* Description : This changes the Register Select control line to the LCD controller.
* Arguments   : none
*********************************************************************************************************
*/

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

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

#ifdef DISP_MODULE_PRESENT
static  void  DispE_High (void)
{
    IO1SET = LCD_BIT_E;                                                 /* Raise the LCD Enable pin high                            */
}


static  void  DispE_Low (void)
{
    IO1CLR = LCD_BIT_E;                                                 /* Lower the LCD Enable pin                                 */
}


static  void  DispRW_High (void)
{
    IO1SET = LCD_BIT_RW;                                                /* Raise the LCD R/W pin                                    */
}


static  void  DispRW_Low (void)
{
    IO1CLR = LCD_BIT_RW;                                                /* Lower the LCD R/W pin                                    */

⌨️ 快捷键说明

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