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

📄 uart_1.c

📁 基于cc1010的设计实例
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                    CHIPCON CC1010 EXAMPLE PROGRAM            *
 *      ***   + +   ***                         UART                         *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 * Demonstrates the use of UART0.                                            *
 * - UART0_SETUP, interrupt-driven                                           *
 * - UART0_SEND and UART0_RECEIVE                                            *
 *                                                                           *
 * A cable must be connected between UART0 on the evaluation board and a COM *
 * port on the PC. Set up HyperTerminal to use 57600 bps.                    *
 *                                                                           *
 * The program will echo the text written in the HyperTerminal text window   *
 * back to the PC. The terminal window must be set up to not echo typed      *
 * characters, all text that appears should be sent from the eval. board.    *
 *                                                                           *
 * The program is not suitable for use with the debugger.                    *
 *****************************************************************************
 * Author:              ARR                                                  *
 *****************************************************************************
 * Revision history:                                                         *
 * 1.0  2002/08/29      First public release                                 *
 *                                                                           *
 * $Log: uart_1.c,v $
 * Revision 1.4  2003/08/18 12:26:43  tos
 * Synchronisation with library update (reentry issue).
 *
 * Revision 1.3  2003/02/18 10:45:13  tos
 * Corrected macro typo (TX interrupt check) in UART0 interrupt service routine.
 *
 * Revision 1.2  2002/11/19 15:47:40  kht
 * Added startup macros
 *
 * Revision 1.1  2002/10/14 11:27:07  tos
 * Initial version in CVS.
 *
 *                                                                           *
 ****************************************************************************/

#include <chipcon/hal.h>
#include <chipcon/cc1010eb.h>

int main() {

    // Disable watchdog timer
    WDT_ENABLE(FALSE);

    // Set optimum settings for speed and low power consumption
    MEM_NO_WAIT_STATES();
    FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS);

    // All I/Os are inputs after reset. Make I/Os connected to LEDs outputs
    RLED=YLED=GLED=BLED=LED_OFF;
    RLED_OE(TRUE); YLED_OE(TRUE); GLED_OE(TRUE); BLED_OE(TRUE);

    // Setup UART0 with interrupt
    UART0_SETUP(57600, CC1010EB_CLKFREQ, UART_NO_PARITY | UART_RX_TX | UART_ISR);
    INT_ENABLE(INUM_UART0, INT_ON);
    INT_PRIORITY(INUM_UART0, INT_HIGH);

    // Turn on interrupts
    INT_GLOBAL_ENABLE(INT_ON);

    // Infinite loop
    while(1);
}

// ISR (interrupt service routine) for uart0
void isr_uart0() interrupt INUM_UART0 {
    byte received_byte;

    if (INT_GETFLAG(INUM_UART0_RX) == INT_SET) {
        received_byte = UART0_RECEIVE(); //read receive buffer
        INT_SETFLAG(INUM_UART0_RX, INT_CLR); // clear int
        UART0_SEND(received_byte);  // echo received character
        GLED = ~GLED;  // toggle LED
    } else if (INT_GETFLAG(INUM_UART0_TX) == INT_SET) {
        INT_SETFLAG(INUM_UART0_TX, INT_CLR); // clear int
    }

} //end isr_uart0()

⌨️ 快捷键说明

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