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

📄 44blib.c

📁 ARM744B0的无操作系统下的蜂鸣器播放音乐程序
💻 C
📖 第 1 页 / 共 2 页
字号:
        rTCMPB2 = tout>>1;

        /* Set the manual update bit of the corresponding timer. */
        ctrlMsk = ~(0xf<<12);
        ctrl = rTCON & ctrlMsk;
        ctrl |= 0x2<<12;    /* auto reload off,
                             * inverter off,
                             * manual update,
                             * timer stop.
                             */
        rTCON = ctrl;

        /* Set the start bit of the corresponding timer to start the timer,
           At the same time, clear the manual update bit.*/
        ctrl &= ~(0xf<<12);
        if (periodly != 0)
        {
            ctrl |= (0xd<<12);   /* auto-reload on(Interval mode)
                                  * Timer output inverter on
                                  * No operation (for manual update off)
                                  * Timer start
                                  */

        }
        else
        {
            ctrl |= (0x5<<12);   /* auto-reload off (one shot mode)
                                  * Timer output inverter on
                                  * No operation (for manual update off)
                                  * Timer start
                                  */
        }
        rTCON = ctrl;
        break;
    case PWM_TIMER3:
        /* Write the initial value into TCNTB3 and TCMPB3 */
        rTCNTB3 = tout;
        rTCMPB3 = tout>>1;

        /* Set the manual update bit of the corresponding timer. */
        ctrlMsk = ~(0xf<<16);
        ctrl = rTCON & ctrlMsk;
        ctrl |= 0x2<<16;    /* auto reload off,
                             * inverter off,
                             * manual update,
                             * timer stop.
                             */
        rTCON = ctrl;

        /* Set the start bit of the corresponding timer to start the timer,
           At the same time, clear the manual update bit.*/
        ctrl &= ~(0xf<<16);
        if (periodly != 0)
        {
            ctrl |= (0xd<<16);   /* auto-reload on(Interval mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */

        }
        else
        {
            ctrl |= (0x5<<16);   /* auto-reload off (one shot mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */
        }
        rTCON = ctrl;
        break;
    case PWM_TIMER4:
        /* Write the initial value into TCNTB4 and TCMPB4 */
        rTCNTB4 = tout;
        rTCMPB4 = tout>>1;

        /* Set the manual update bit of the corresponding timer. */
        ctrlMsk = ~(0xf<<20);
        ctrl = rTCON & ctrlMsk;
        ctrl |= 0x2<<20;    /* auto reload off,
                             * inverter off,
                             * manual update,
                             * timer stop.
                             */
        rTCON = ctrl;

        /* Set the start bit of the corresponding timer to start the timer,
           At the same time, clear the manual update bit.*/
        ctrl &= ~(0xf<<20);
        if (periodly != 0)
        {
            ctrl |= (0xd<<20);   /* auto-reload on(Interval mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */

        }
        else
        {
            ctrl |= (0x5<<20);   /* auto-reload off (one shot mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */
        }
        rTCON = ctrl;
        break;

    case PWM_TIMER5:
        /* Write the initial value into TCNTB5 */
        rTCNTB5 = tout;

        /* Set the manual update bit of the corresponding timer. */
        ctrlMsk = ~(0x7<<24);
        ctrl = rTCON & ctrlMsk;
        ctrl |= 0x2<<24;    /* auto reload off,
                             * manual update,
                             * timer stop.
                             */
        rTCON = ctrl;

        /* Set the start bit of the corresponding timer to start the timer,
           At the same time, clear the manual update bit.*/
        ctrl &= ~(0x7<<24);
        if (periodly != 0)
        {
            ctrl |= (0x5<<24);   /* auto-reload on(Interval mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */

        }
        else
        {
            ctrl |= (0x1<<24);   /* auto-reload off (one shot mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */
        }
        rTCON = ctrl;
        break;

    default:
        break;
    }
}

/******************************************************************************
Function    : void pwm_stop(int which)
Params      : which - the PWM Timer channel(0~5)
            : 
            : 
            : 
Return      : N/A
Description : stop the special PWM timer channel.
            : 
******************************************************************************/
void pwm_stop(int which)
{
    unsigned ctrl;

    /* for detail information about rTCON, pls reference pwm_start(). */
    ctrl = rTCON;

    switch(which)
    {
    case PWM_TIMER0:
        ctrl &= ~(1<<0);    /* clear Bit0. */
        break;
    case PWM_TIMER1:
        ctrl &= ~(1<<8);    /* clear Bit8. */
        break;
    case PWM_TIMER2:
        ctrl &= ~(1<<12);    /* clear Bit12. */
        break;
    case PWM_TIMER3:
        ctrl &= ~(1<<16);    /* clear Bit16. */
        break;
    case PWM_TIMER4:
        ctrl &= ~(1<<20);    /* clear Bit20. */
        break;
    case PWM_TIMER5:
        ctrl &= ~(1<<24);    /* clear Bit24. */
        break;

    default:
        break;
    }

    rTCON = ctrl;
}

/******************************************************************************
Function    : void init_uart(void)
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : This function config all of UART registers as app default:
            : No parity, 1 stop bit, 8 data bits, 57600bps baud.
******************************************************************************/
void init_uart()
{
    /* Bit6    : infra-Red mode or not, 1 for infra-Red mode.
     * bit5..3 : parity mode, 0xx for no parity.
     * Bit2    : number of stop bit, 0 one stop bit, 1 two stop bit per frame.
     * Bit1..0 : data bits per frame, 11 for 8 bits.
     */
    rULCON0 = 0x3;     /*No parity, 1 stop bit, 8 data bits*/
    rULCON1 = 0x3;

    /* Bit7..6 : Tx FIFO Trigger Level
     * Bit5..4 : Rx FIFO Trigger Level
     * Bit3    : Reserved and not used.
     * Bit2    : Tx FIFO Reset
     * Bit1    : Rx FIFO Reset
     * Bit0    : FIFO enable or not, 0 for disable, 1 for enable.
     */
    rUFCON0 = 0x0;     /* FIFO disabled. */
    rUFCON1 = 0x0;

    /* Bit4    : Auto Flow Control(AFC) enable or not, 1 for enable, 0 for disable.
     * Bit3..1 : Reserved and must be 0.
     * Bit0    : nRTS, only used when AFC is disabled.
     */
    rUMCON0 = 0x0;     /* AFC disabled. */
    rUMCON1 = 0x0;

    /* Bit9    : Tx interrupt type, 0 for pulse, 1 for level
     * Bit8    : Rx interrupt type, 0 for pulse, 1 for level
     * Bit7    : Rx timeout enable, 0 for disable, 1 for enable
     * Bit6    : Rx error status interrupt enable, 0 for disable, 1 for enable
     * Bit5    : Loop-back mode, 0 for normal option, 1 for Loop-back mode
     * Bit4    : Send Break Signal, 0 for normal transmit, 1 for send break signal
     * Bit3..2 : Transmit Mode, 00 for disable, 01 for interrupt request or polling mode
     * Bit1..0 : Receive Mode, 00 for disable, 01 for interrupt request or polling mode
     */
    rUCON0 = 0x45;     /* Tx is using polling mode.
                        * Rx is using pulse interrupt type.
                        * Rx timeout is disabled.
                        * Don't send break signal.
                        */
    rUCON1 = 0x45;

    /* default baud rate is 57600bps. */
    rUBRDIV0 = (MCLK + 8 * BAUD_DEFAULT)/(16 * BAUD_DEFAULT) - 1;
    rUBRDIV1 = (MCLK + 8 * BAUD_DEFAULT)/(16 * BAUD_DEFAULT) - 1;
}

/******************************************************************************
Function    : void UART_sendChar(int which, char ch)
Params      : which - UART0 or UART1
            : ch    - send this char to UART [which].
            : 
            : 
Return      : N/A
Description : output char to a special UART channel. This feature can be used
            : for output print information or send answer frame to host.
******************************************************************************/
void UART_sendChar(int which, char ch)
{
    if ((which != UART_CH0)&&(which != UART_CH1))
    {
        return;
    }
    switch (which)
    {
    case UART_CH0:
        if(ch=='\n')
        {
            while(!(rUTRSTAT0 & 0x2));
            WrUTXH0('\r');
        }
        while(!(rUTRSTAT0 & 0x2)); /* Wait until THR is empty. */
        WrUTXH0(ch);
        break;
    case UART_CH1:
        if(ch=='\n')
        {
            while(!(rUTRSTAT1 & 0x2));
            WrUTXH1('\r');
        }
        while(!(rUTRSTAT1 & 0x2)); /* Wait until THR is empty. */
        WrUTXH1(ch);
        break;
    default:
        break;
    }
}

/******************************************************************************
Function    : void UART_sendString(int which, const char * pszstring)
Params      : which     - UART0 or UART1
            : pszstring - send this string to UART [which](end by '\0').
            : 
            : 
Return      : N/A
Description : send a string to UART0 or UART1.
            :
******************************************************************************/
void UART_sendString(int which, const char * pszstring)
{
    int i;

    for (i = 0; i < strlen(pszstring); i++)
    {
        UART_sendChar(which, pszstring[i]);
    }
}

/******************************************************************************
Function    : void flash_led()
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : Flash the running LED.
            : 
******************************************************************************/
void flash_led()
{
    static int ledState=LED_OFF;

    if (ledState == LED_OFF)
    {
        ledState = LED_ON;
    }
    else
    {
        ledState = LED_OFF;
    }

    //light_led(LED1, ledState);
}

/******************************************************************************
Function    : void delay(unsigned n)
Params      : n - delay time, it is not an accurate time.
            : 
Return      : N/A
Description : This function is used to config the RTC registers and should be
            : called only once, when the system is power on.
******************************************************************************/
void delay(unsigned n)
{
    while(n--!=0);
}

⌨️ 快捷键说明

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