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

📄 bsp.c

📁 基于PIC24 UCOS-II 2.83源程序下载
💻 C
📖 第 1 页 / 共 2 页
字号:
        PORTA  |=  (1 << led);                                          /* Turn on the chosen LED                                   */
    } 
}

/*
*********************************************************************************************************
*                                             LED OFF
*
* Description : This function is used to control any or all the LEDs on the board.
*
* Arguments   : led    is the number of the LED to turn OFF
*                      0    indicates that you want ALL the LEDs to be OFF
*                      1    turns OFF LED1
*                      2    turns OFF LED2
*                      .
*                      8    turns OFF LED8
*
* Notes       : 1) Jumper JP2 on the Explorer 16 board must be connected to enable the onboard LEDs
*********************************************************************************************************
*/

void  LED_Off (INT8U led)
{
    if (led == 0) {
        PORTA  &=  ~0xFF;                                               /* Turn on all of the LEDs if a 0 is passed in              */
		return;
    }

    if ((led >= 1) && (led <= 8)) {
		led--;                                                          /* Convert the LED number to a pin number by subtracting 1	*/
        PORTA  &= ~(1 << led);                                          /* Turn on the chosen LED                                   */
    } 
}

/*
*********************************************************************************************************
*                                             LED TOGGLE
*
* Description : This function is used to toggle any or all the LEDs on the board.
*
* Arguments   : led    is the number of the LED to control
*                      0    indicates that you want to toggle ALL the LEDs
*                      1    toggles LED1
*                      2    toggles LED2
*                      .
*                      8    toggles LED8
*
* Notes       : 1) Jumper JP2 on the Explorer 16 board must be connected to enable the onboard LEDs
*********************************************************************************************************
*/

void  LED_Toggle (INT8U led)
{
    if (led == 0) {
        PORTA  ^=  0xFF;                                                /* Turn on all of the LEDs if a 0 is passed in              */                  
		return;
    }

    if ((led >= 1) && (led <= 8)) {
		led--;                                                          /* Convert the LED number to a pin number by subtracting 1	*/
        PORTA  ^=  (1 << led);                                          /* Turn on the chosen LED                                   */
    } 
}

/*
*********************************************************************************************************
*                                     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)
{
#if OS_VIEW_TMR_SEL == 3
    T3CON     =   0;                                                    /* Use Internal Osc (Fosc / 4), 16 bit mode, prescaler = 1  */
    TMR3      =   0;                                                    /* Start counting from 0 and clear the prescaler count      */                                   
    PR3       =   0xFFFF;                                               /* Set the period register to its maximum value             */
    T3CON    |=   TON;                                                  /* Start the timer                                          */      
#endif   

#if OS_VIEW_TMR_SEL == 5
    T5CON     =   0;                                                    /* Use Internal Osc (Fosc / 4), 16 bit mode, prescaler = 1  */
    TMR5      =   0;                                                    /* Start counting from 0 and clear the prescaler count      */                                   
    PR5       =   0xFFFF;                                               /* Set the period register to its maximum value             */
    T5CON    |=   TON;                                                  /* Start the timer                                          */      
#endif    
}
#endif

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

#if OS_VIEW_MODULE > 0
INT32U  OSView_TmrRd (void)
{
#if OS_VIEW_TMR_SEL == 3
    return (TMR3);                                                      /* Return the value of timer 3 if selected                  */
#endif   

#if OS_VIEW_TMR_SEL == 5
    return (TMR5);                                                      /* Return the value of timer 5 if selected                  */
#endif       
}
#endif

/*
*********************************************************************************************************
*                                       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
*
* Note(s)     : 1) The timer operates at a frequency of Fosc / 4
*               2) The timer resets to 0 after period register match interrupt is generated
*********************************************************************************************************
*/

static  void  Tmr_TickInit (void)
{
    INT32U  tmr_frq;
    INT16U  cnts;


    tmr_frq   =   BSP_CPU_ClkFrq();                                     /* Get the CPU Clock Frequency (Hz) (Fcy)                    */
    cnts      =   (tmr_frq / OS_TICKS_PER_SEC) - 1;                     /* Calaculate the number of timer ticks between interrupts  */

#if BSP_OS_TMR_SEL == 2
    T2CON     =   0;                                                    /* Use Internal Osc (Fcy), 16 bit mode, prescaler = 1  		*/
    TMR2      =   0;                                                    /* Start counting from 0 and clear the prescaler count      */                                   
    PR2       =   cnts;                                                 /* Set the period register                                  */
    IPC1     &=  ~T2IP_MASK;                                            /* Clear all timer 2 interrupt priority bits                */
    IPC1     |=  (TIMER_INT_PRIO << 12);                                /* Set timer 2 to operate with an interrupt priority of 4   */
    IFS0     &=  ~T2IF;                                                 /* Clear the interrupt for timer 2                          */
    IEC0     |=   T2IE;                                                 /* Enable interrupts for timer 2                            */
    T2CON    |=   TON;                                                  /* Start the timer                                          */      
#endif   

#if BSP_OS_TMR_SEL == 4
    T4CON     =   0;                                                    /* Use Internal Osc (Fcy), 16 bit mode, prescaler = 1  		*/
    TMR4      =   0;                                                    /* Start counting from 0 and clear the prescaler count      */                                   
    PR4       =   cnts;                                                 /* Set the period register                                  */
    IPC6     &=  ~T4IP_MASK;                                            /* Clear all timer 4 interrupt priority bits                */
    IPC6     |=  (TIMER_INT_PRIO << 12);                                /* Set timer 4 to operate with an interrupt priority of 4   */
    IFS1     &=  ~T4IF;                                                 /* Clear the interrupt for timer 4                          */
    IEC1     |=   T4IE;                                                 /* Enable interrupts for timer 4                            */
    T4CON    |=   TON;                                                  /* Start the timer                                          */      
#endif  
}

/*
*********************************************************************************************************
*                                     OS TICK INTERRUPT SERVICE ROUTINE
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*********************************************************************************************************
*/

void OS_Tick_ISR_Handler (void) 
{
    OSTimeTick();
}


⌨️ 快捷键说明

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