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

📄 uart.h

📁 cc1110,cc2510透传代码,IAR环境的
💻 H
字号:
/******************************************************************************
 * uart.h
 * Copyright 1994-2006 Infortech Technology Co.,Ltd.
 * DESCRIPTION:
 * Author : Shutingzhong 2008-09-13
 ******************************************************************************/

#ifndef _UART_H
#define _UART_H

#define BR_1200 0
#define BR_2400 1
#define BR_4800 2
#define BR_9600 3
#define BR_19200 4

/******************************************************************************
*******************  USART-UART specific functions/macros   *******************
******************************************************************************/
#define BAUD_E(baud, clkDivPow)( \
   (baud ==   1200) ?   5 +clkDivPow : \
   (baud ==   2400) ?   6 +clkDivPow : \
   (baud ==   4800) ?   7 +clkDivPow : \
   (baud ==   9600) ?   8 +clkDivPow : \
   (baud ==  14400) ?   9 +clkDivPow : \
   (baud ==  19200) ?   9 +clkDivPow : \
   (baud ==  28800) ?  10 +clkDivPow : \
   (baud ==  38400) ?  10 +clkDivPow : \
   (baud ==  57600) ?  11 +clkDivPow : \
   (baud ==  76800) ?  11 +clkDivPow : \
   (baud == 115200) ?  12 +clkDivPow : \
   (baud == 230400) ?  13 +clkDivPow : \
   0)
#define BAUD_M(baud) ( \
   (baud ==   1200) ?  131 : \
   (baud ==   2400) ?  131 : \
   (baud ==   4800) ?  131 : \
   (baud ==   9600) ?  131 : \
   (baud ==  14400) ?   34 : \
   (baud ==  19200) ?  131 : \
   (baud ==  28800) ?   34 : \
   (baud ==  38400) ?  131 : \
   (baud ==  57600) ?   34 : \
   (baud ==  76800) ?  131 : \
   (baud == 115200) ?   34 : \
   (baud == 230400) ?  164 : \
   0)
#define UART_SETUP(uart, baudRate, options)      \
   do {                                          \
      if((uart) == 0){                           \
         if(PERCFG & 0x01){                      \
            P1SEL |= 0x30;                       \
         } else {                                \
            P0SEL |= 0x0C;                       \
         }                                       \
      }                                          \
      else {                                     \
         if(PERCFG & 0x02){                      \
            P1SEL |= 0xC0;                       \
         } else {                                \
            P0SEL |= 0x30;                       \
         }                                       \
      }                                          \
                                                 \
      U##uart##GCR = BAUD_E((baudRate),CLKSPD);  \
      U##uart##BAUD = BAUD_M(baudRate);          \
                                                 \
      U##uart##CSR |= 0x80;                      \
                                                 \
                                                 \
      U##uart##UCR |= ((options) | 0x80);        \
                                                 \
      if((options) & TRANSFER_MSB_FIRST){        \
         U##uart##GCR |= 0x20;                   \
      }                                          \
   } while(0)

// Options for UART_SETUP macro
#define FLOW_CONTROL_ENABLE         0x40
#define FLOW_CONTROL_DISABLE        0x00
#define EVEN_PARITY                 0x20
#define ODD_PARITY                  0x00
#define NINE_BIT_TRANSFER           0x10
#define EIGHT_BIT_TRANSFER          0x00
#define PARITY_ENABLE               0x08
#define PARITY_DISABLE              0x00
#define TWO_STOP_BITS               0x04
#define ONE_STOP_BITS               0x00
#define HIGH_STOP                   0x02
#define LOW_STOP                    0x00
#define HIGH_START                  0x01
#define TRANSFER_MSB_FIRST          0x80
#define TRANSFER_MSB_LAST           0x00
#define UART_ENABLE_RECEIVE         0x40

extern void OpenUart(unsigned char BaudRateMode,unsigned char options);
#endif  /* _UART_H */

⌨️ 快捷键说明

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