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

📄 f06x_uarts_stdio_polled_2uarts.lst

📁 // This program demonstrates how to configure the C8051F060 to write to and read // from the UART i
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.08   F06X_UARTS_STDIO_POLLED_2UARTS                                        02/14/2008 09:52:44 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE F06X_UARTS_STDIO_POLLED_2UARTS
OBJECT MODULE PLACED IN F06x_UARTs_STDIO_Polled_2UARTs.OBJ
COMPILER INVOKED BY: C:\SiLabs\MCU\IDEfiles\C51\BIN\C51.exe F06x_UARTs_STDIO_Polled_2UARTs.c DB OE

line level    source

   1          //-----------------------------------------------------------------------------
   2          // F06x_UARTs_STDIO_Polled_2UARTs.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2005 Silicon Laboratories, Inc.
   5          // http://www.silabs.com
   6          //
   7          // Program Description:
   8          //
   9          // This program demonstrates configuration of UART0 and UART1 and includes
  10          // an example of how to overload the STDIO library functions to enable
  11          // selection of either UART0 or UART1 in code, via the "Uart" global variable.
  12          //
  13          //
  14          // How To Test:
  15          //
  16          // 1) Download code to a 'F06x device that is connected to a UART transceiver
  17          // 2) Connect serial cable from the transceiver to a PC
  18          // 3) On the PC, open HyperTerminal (or any other terminal program) and connect
  19          //    to the COM port at <BAUDRATE> and 8-N-1
  20          // 4) HyperTerminal will print a message if everything is working properly
  21          //
  22          //
  23          // FID:            06X000031
  24          // Target:         C8051F06x
  25          // Tool chain:     KEIL C51 7.50 / KEIL EVAL C51
  26          // Command Line:   None
  27          //
  28          // Release 1.0
  29          //    -Initial Revision (BW / TP)
  30          //    -07 DEC 2006
  31          //
  32          
  33          //-----------------------------------------------------------------------------
  34          // Includes
  35          //-----------------------------------------------------------------------------
  36          
  37          #include <C8051F060.h>                 // SFR declarations
  38          #include <stdio.h>
  39          
  40          //-----------------------------------------------------------------------------
  41          // 16-bit SFR Definitions for 'F06x
  42          //-----------------------------------------------------------------------------
  43          
  44          sfr16 RCAP2    = 0xCA;                 // Timer2 capture/reload
  45          sfr16 TMR2     = 0xCC;                 // Timer2
  46          
  47          //-----------------------------------------------------------------------------
  48          // Global Constants
  49          //-----------------------------------------------------------------------------
  50          
  51          #define BAUDRATE     115200            // Baud rate of UART in bps
  52          
  53          // SYSCLK = System clock frequency in Hz
  54          #define SYSCLK       22118400L
  55          
C51 COMPILER V8.08   F06X_UARTS_STDIO_POLLED_2UARTS                                        02/14/2008 09:52:44 PAGE 2   

  56          //-----------------------------------------------------------------------------
  57          // Function Prototypes
  58          //-----------------------------------------------------------------------------
  59          
  60          void OSCILLATOR_Init (void);
  61          void PORT_Init_UART0 (void);
  62          void PORT_Init_UART1 (void);
  63          void UART0_Init (void);
  64          void UART1_Init (void);
  65          
  66          //-----------------------------------------------------------------------------
  67          // Global Variables
  68          //-----------------------------------------------------------------------------
  69          
  70          unsigned char Uart;                    // Global variable -- when '0', UART0
  71                                                 // is used for stdio; when '1', UART1
  72                                                 // is used for stdio
  73          
  74          //-----------------------------------------------------------------------------
  75          // main() Routine
  76          //-----------------------------------------------------------------------------
  77          
  78          void main (void)
  79          {
  80   1         SFRPAGE = CONFIG_PAGE;
  81   1      
  82   1         WDTCN = 0xDE;                       // Disable watchdog timer
  83   1         WDTCN = 0xAD;
  84   1      
  85   1         OSCILLATOR_Init ();                 // Initialize oscillator
  86   1         PORT_Init_UART0 ();                 // Initialize crossbar and GPIO
  87   1      
  88   1         UART0_Init ();                      // Initialize UART0
  89   1         UART1_Init ();                      // Initialize UART1
  90   1      
  91   1      
  92   1         while (1)
  93   1         {
  94   2            // print something to UART0
  95   2            PORT_Init_UART0 ();              // Configure Crossbar to pinout
  96   2                                             // UART0 TX and RX to P0.0 and P0.1
  97   2            Uart = 0;
  98   2            printf ("UART 0\n\n");
  99   2      
 100   2            // now print something to UART1
 101   2            PORT_Init_UART1 ();              // Configure Crossbar to pinout
 102   2                                             // UART1 TX and RX to P0.0 and P0.1
 103   2            Uart = 1;
 104   2            printf ("UART 1\n\n");
 105   2         }
 106   1      }
 107          
 108          //-----------------------------------------------------------------------------
 109          // Initialization Subroutines
 110          //-----------------------------------------------------------------------------
 111          
 112          //-----------------------------------------------------------------------------
 113          // OSCILLATOR_Init
 114          //-----------------------------------------------------------------------------
 115          //
 116          // Return Value : None
 117          // Parameters   : None
C51 COMPILER V8.08   F06X_UARTS_STDIO_POLLED_2UARTS                                        02/14/2008 09:52:44 PAGE 3   

 118          //
 119          // This function initializes the system clock to use an external 22.1184MHz
 120          // crystal.
 121          //
 122          //-----------------------------------------------------------------------------
 123          void OSCILLATOR_Init (void)
 124          {
 125   1         int i;                              // Software timer
 126   1      
 127   1         char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page
 128   1      
 129   1         SFRPAGE = CONFIG_PAGE;              // Set SFR page
 130   1      
 131   1         OSCICN = 0x80;                      // Set internal oscillator to run
 132   1                                             // at its slowest frequency
 133   1      
 134   1         CLKSEL = 0x00;                      // Select the internal osc. as
 135   1                                             // the SYSCLK source
 136   1      
 137   1         // Initialize external crystal oscillator to use 22.1184 MHz crystal
 138   1      
 139   1         OSCXCN = 0x67;                      // Enable external crystal osc.
 140   1         for (i=0; i < 256; i++);            // Wait at least 1ms
 141   1      
 142   1         while (!(OSCXCN & 0x80));           // Wait for crystal osc to settle
 143   1      
 144   1         CLKSEL = 0x01;                      // Select external crystal as SYSCLK
 145   1                                             // source
 146   1      
 147   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFRPAGE
 148   1      }
 149          
 150          //-----------------------------------------------------------------------------
 151          // PORT_Init_UART0
 152          //-----------------------------------------------------------------------------
 153          //
 154          // Return Value : None
 155          // Parameters   : None
 156          //
 157          // This function configures the crossbar and GPIO ports.
 158          //
 159          // Pinout:
 160          //
 161          // P0.0   digital   push-pull     UART TX
 162          // P0.1   digital   open-drain    UART RX
 163          // P1.6   digital   push-pull     LED
 164          //-----------------------------------------------------------------------------
 165          void PORT_Init_UART0 (void)
 166          {
 167   1         char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page
 168   1      
 169   1         SFRPAGE = CONFIG_PAGE;              // Set SFR page
 170   1      
 171   1         XBR0     = 0x04;                    // Enable UART0
 172   1         XBR1     = 0x00;
 173   1         XBR2     = 0x40;                    // Enable crossbar and weak pull-up
 174   1      
 175   1      
 176   1         P0MDOUT |= 0x01;                    // Set TX pin to push-pull
 177   1         P1MDOUT |= 0x40;                    // Set P1.6(LED) to push-pull
 178   1      
 179   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFR page
C51 COMPILER V8.08   F06X_UARTS_STDIO_POLLED_2UARTS                                        02/14/2008 09:52:44 PAGE 4   

 180   1      }
 181          
 182          //-----------------------------------------------------------------------------
 183          // PORT_Init_UART1
 184          //-----------------------------------------------------------------------------
 185          //
 186          // Return Value : None
 187          // Parameters   : None
 188          //
 189          // This function configures the crossbar and GPIO ports.
 190          //
 191          // Pinout:
 192          //
 193          // P0.0   digital   push-pull     UART TX
 194          // P0.1   digital   open-drain    UART RX
 195          // P1.6   digital   push-pull     LED
 196          //-----------------------------------------------------------------------------
 197          void PORT_Init_UART1 (void)

⌨️ 快捷键说明

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