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

📄 bsp.c

📁 lpc2478开发板基于IAR编译器移植ucos实验例程
💻 C
📖 第 1 页 / 共 5 页
字号:
             break;

        case 2:
             if ((data & 0x0C) == 0) {
                 data  &= ~0x0C;
                 data  |=  0x04;
             } else {
                 data  &= ~0x0C;
             }
             break;

        case 3:
             if ((data & 0x30) == 0) {
                 data  &= ~0x30;
                 data  |=  0x10;
             } else {
                 data  &= ~0x30;
             }
             break;

        case 4:
             if ((data & 0xC0) == 0) {
                 data  &= ~0xC0;
                 data  |=  0x40;
             } else {
                 data  &= ~0xC0;
             }
             break;

        default:
             return;
    }

    buf[0]          = 0x08;
    buf[1]          = data;

    I2C_Write(buf, 2);
}

/*
*********************************************************************************************************
*                                         ADC INITIALIZATION
*
* Description : This function initializes the board's ADC
*
* Arguments   : none
*
* Returns     : none
*********************************************************************************************************
*/

static  void  ADC_Init (void)
{
    CPU_INT08U  div;
    CPU_INT32U  pinsel;


    PCONP      |=  DEF_BIT_12;

    div         = (BSP_CPU_PclkFreq(PCLK_ADC) / 4500000) + 1;
                                                                /* Configure ADC ...                                        */
    AD0CR       = (0x03 <<  0)                                  /*  ... Sample/convert pin AD0.0 and AD0.1 ...              */
                | (div  <<  8)                                  /*  ... Set divider so sample freq. < 4.5 MHz ...           */
                |  DEF_BIT_16                                   /*  ... Use burst mode for continuous conversion ...        */
                | (0x00 << 17)                                  /*  ... Use 11 clocks per conversion for 10-bit accuracy ...*/
                |  DEF_BIT_21;                                  /*  ... Power up the ADC.                                   */

                                                                /* Select AD0.0, AD0.1 function for P0.23, P0.24            */
    pinsel      = PINSEL1;
    pinsel     &= 0xFFFC3FFF;
    pinsel     |= 0x00014000;
    PINSEL1     = pinsel;
}


/*
*********************************************************************************************************
*                                           ADC STATUS
*
* Description : This function initializes the board's ADC
*
* Arguments   : adc     is the number of the ADC to probe.
*                       0  probes AD0.0, the right-hand potentiometer
*                       1  probes AD0.1, the left-hand  potentiometer
*
* Returns     : The numerator of the binary fraction representing the result of the latest ADC conversion.
*               This value will be a 10-bit value between 0x0000 and 0x03FF, inclusive.
*********************************************************************************************************
*/

CPU_INT16U  ADC_GetStatus (CPU_INT08U  adc)
{
    if (adc == 0) {
        return ((ADDR0 >> 6) & 0x03FF);
    } else if (adc == 1) {
        return ((ADDR1 >> 6) & 0x03FF);
    } else {
        return (0);
    }
}

/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                            LCD Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                          LCD BACKLIGHT ON
*
* Description : This function turns on the LCD backlight.
*
* Arguments   : None
*
* Returns     : None
*********************************************************************************************************
*/

void  LCD_LightOn (void)
{
    FIO3SET     = GPIO3_LCD_LIGHT;
}

/*
*********************************************************************************************************
*                                          LCD BACKLIGHT OFF
*
* Description : This function turns off the LCD backlight.
*
* Arguments   : None
*
* Returns     : None
*********************************************************************************************************
*/

void  LCD_LightOff (void)
{
    FIO3CLR     = GPIO3_LCD_LIGHT;
}

/*
*********************************************************************************************************
*                                          LCD BACKLIGHT TOGGLE
*
* Description : This function toggles the LCD backlight.
*
* Arguments   : None
*
* Returns     : None
*********************************************************************************************************
*/

void  LCD_LightToggle (void)
{
    CPU_INT32U  pin;


    pin         = FIO3PIN & GPIO3_LCD_LIGHT;

    if (pin == GPIO3_LCD_LIGHT) {

        FIO3CLR = GPIO3_LCD_LIGHT;

    } else {

        FIO3SET = GPIO3_LCD_LIGHT;
    }
}

/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                          OS-View Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                     INITIALIZE TIMER FOR uC/OS-View
*
* Description : This function is called to by uC/OS-View to initialize the free running timer that is
*               used to make time measurements.
*
* Arguments   : none
*
* Returns     ; none
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
void  OSView_TmrInit (void)
{
    T1PR  = 0;
    T1TCR = 0x00000001;                                         /* Enable the timer                                         */

}
#endif

/*
*********************************************************************************************************
*                                     READ TIMER FOR uC/OS-View
*
* Description : This function is called to read the current counts of a 32 bit free running timer.
*
* Arguments   : none
*
* Returns     ; The 32 bit counts of the timer assuming the timer (MUST be an UP counter).
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
CPU_INT32U  OSView_TmrRd (void)
{
    if (OSRunning == DEF_TRUE) {
        return ((CPU_INT32U)T1TC);
    } else {
        return (0);
    }
}
#endif


/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                         uC/OS-II Timer Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                       TICKER INITIALIZATION
*
* Description : This function is called to initialize uC/OS-II's tick source (typically a timer generating
*               interrupts every 1 to 100 mS).
*
* Arguments   : none
*
* Returns     ; none
*********************************************************************************************************
*/

static  void  Tmr_TickInit (void)
{
    CPU_INT32U  pclk_freq;
    CPU_INT32U  rld_cnts;

                                                                /* VIC timer #0 Initialization                              */
    VICIntSelect       &= ~(1 << VIC_TIMER0);                   /* Configure the timer interrupt as an IRQ source           */
    VICVectAddr4        =  (CPU_INT32U)Tmr_TickISR_Handler;     /* Set the vector address                                   */
    VICIntEnable        =  (1 << VIC_TIMER0);                   /* Enable the timer interrupt source                        */

    pclk_freq           =   BSP_CPU_PclkFreq(PCLK_TIMER0);      /* Get the peripheral clock frequency                       */

    rld_cnts            =   pclk_freq / OS_TICKS_PER_SEC;       /* Calculate the # of counts necessary for the OS ticker    */

    T0TCR               =  (1 << 1);                            /* Disable and reset counter 0 and the prescale counter 0   */
    T0TCR               =   0;                                  /* Clear the reset bit                                      */
    T0PC                =   0;                                  /* Prescaler is set to no division                          */

    T0MR0               =   rld_cnts;
    T0MCR               =   3;                                  /* Interrupt on MR0 (reset TC), stop TC                     */

    T0CCR               =   0;                                  /* Capture is disabled.                                     */
    T0EMR               =   0;                                  /* No external match output.                                */
    T0TCR               =   1;                                  /* Enable timer 0                                           */
}


/*
*********************************************************************************************************
*                                         TIMER #0 IRQ HANDLER
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments   : none
*
* Returns     ; none
*********************************************************************************************************
*/

void  Tmr_TickISR_Handler (void)
{
    T0IR        = 0xFF;                                         /* Clear timer #0 interrupt                                 */

    OSTimeTick();                                               /* Call uC/OS-II's OSTimeTick()                             */
}
/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                       Serial Port Communications
******************************************************************************************************************************
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                                   Ser_Init
*
* Description :   This function prepares UART0.
*
* Arguments   :   None.
*
* Returns     :   None.
*********************************************************************************************************
*/

void  Ser_Init (void)
{
    CPU_INT16U  div;                                            /* Baud rate divisor                                        */
    CPU_INT08U  divlo;
    CPU_INT08U  divhi;
    CPU_INT08U  lcr;										    /* Line Control Register                                    */
    CPU_INT32U  pclk_freq;
    CPU_INT32U  pinsel;


#if SER_COMM_SEL == SER_UART_0
                                                                /* Compute divisor for desired baud rate                    */
    pclk_freq   =  BSP_CPU_PclkFreq(PCLK_UART0);                /* Get the CPU clock frequency                              */

    div         = (CPU_INT16U)(((2 * pclk_freq / 16 / 115200) + 1) / 2);

⌨️ 快捷键说明

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