亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? f02x_uarts_stdio_polled_2uarts.c

?? 基于單片機(jī)c8051F020的串行口通信的源程序代碼。
?? C
字號:
//-----------------------------------------------------------------------------
// F02x_UARTs_STDIO_Polled_2UARTs.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program demonstrates configuration of UART0 and UART1 and includes
// an example of how to overload the STDIO library functions to enable
// selection of either UART0 or UART1 in code, via the "UART" global variable.
// This way both UARTs can use the same pins and present messages.
//
// Pinout
//
//    P0.0   digital   push-pull     UART TX
//    P0.1   digital   open-drain    UART RX
//    P1.6   digital   push-pull     LED
//
// How To Test:
//
// 1) Download code to a 'F02x device that is connected to a UART transceiver
// 2) Connect serial cable from the transceiver to a PC
// 3) On the PC, open HyperTerminal (or any other terminal program) and connect
//    to the COM port at <BAUDRATE> and 8-N-1
// 4) HyperTerminal will print a message if everything is working properly
//
// Obs: The designer must check that the required baud rate is reached and
//    that the error is within range for the application.
//
//
// FID:            02X000005
// Target:         C8051F02x
// Tool chain:     KEIL C51 7.50 / KEIL EVAL C51
// Command Line:   None
//
// Release 1.0
//    -Initial Revision (CG)
//    -24 JUL 2006
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include <c8051f020.h>                 // SFR declarations
#include <stdio.h>

//-----------------------------------------------------------------------------
// 16-bit SFR Definitions for 'F02x
//-----------------------------------------------------------------------------

sfr16 RCAP2    = 0xca;                 // Timer2 capture/reload
sfr16 TMR2     = 0xcc;                 // Timer2

//-----------------------------------------------------------------------------
// Global Constants
//-----------------------------------------------------------------------------

#define BAUDRATE     1200              // Baud rate of UART in bps

// SYSCLK = System clock frequency in Hz

#define SYSCLK       (22118400L)

//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------

void OSCILLATOR_Init (void);
void PORT_Init_UART0 (void);
void PORT_Init_UART1 (void);
void UART0_Init (void);
void UART1_Init (void);

//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------

unsigned char UART;                    // Global variable -- when '0', UART0
                                       // is used for stdio; when '1', UART1
                                       // is used for stdio

//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------

void main (void)
{
   WDTCN = 0xde;                       // Disable watchdog timer
   WDTCN = 0xad;

   OSCILLATOR_Init ();                 // Initialize oscillator
   PORT_Init_UART0 ();                 // Initialize crossbar and GPIO

   UART0_Init ();                      // Initialize UART0
   UART1_Init ();                      // Initialize UART1


   while (1)
   {
      // print something to UART0
      PORT_Init_UART0 ();              // Configure Crossbar to pinout
                                       // UART0 TX and RX to P0.0 and P0.1
      UART = 0;
      printf ("UART 0\n\n");

      // now print something to UART1
      PORT_Init_UART1 ();              // Configure Crossbar to pinout
                                       // UART1 TX and RX to P0.0 and P0.1
      UART = 1;
      printf ("UART 1\n\n");
   }
}

//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// OSCILLATOR_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function initializes the system clock to use the  external 22.1184MHz
// crystal.
//
//-----------------------------------------------------------------------------
void OSCILLATOR_Init (void)
{
   int i;                              // Software timer

   OSCICN |= 0x80;                     // Enable the missing clock detector

   // Initialize external crystal oscillator to use 22.1184 MHz crystal

   OSCXCN = 0x67;                      // Enable external crystal osc.
   for (i=0; i < 256; i++);            // Wait at least 1ms
   while (!(OSCXCN & 0x80));           // Wait for crystal osc to settle
   OSCICN |= 0x08;                  // Select external clock source
   OSCICN &= ~0x04;                 // Disable the internal osc.
}

//-----------------------------------------------------------------------------
// PORT_Init_UART0
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function configures the crossbar and GPIO ports.
//
// P0.0   digital   push-pull     UART TX
// P0.1   digital   open-drain    UART RX
//-----------------------------------------------------------------------------
void PORT_Init_UART0 (void)
{
   XBR0     = 0x04;                    // Enable UART0
   XBR1     = 0x00;
   XBR2     = 0x40;                    // Enable crossbar and weak pull-up

   P0MDOUT |= 0x01;                    // Set TX pin to push-pull
}

//-----------------------------------------------------------------------------
// PORT_Init_UART1
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function configures the crossbar and GPIO ports.
//
// P0.0   digital   push-pull     UART TX
// P0.1   digital   open-drain    UART RX
//-----------------------------------------------------------------------------
void PORT_Init_UART1 (void)
{
   XBR0     = 0x00;
   XBR1     = 0x00;
   XBR2     = 0x44;                    // Enable crossbar and weak pull-up
                                       // Enable UART1

   P0MDOUT |= 0x01;                    // Set TX pin to push-pull
}

//-----------------------------------------------------------------------------
// UART0_Init   Variable baud rate, Timer 2, 8-N-1
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Configure UART0 for operation at <baudrate> 8-N-1 using Timer2 as
// baud rate source.
//
//-----------------------------------------------------------------------------
void UART0_Init (void)
{
   CKCON = 0x20;                       // Timer2 uses the system clock
   T2CON = 0x34;                       // Timer2 used for TX and RX, enabled
   RCAP2 = - ((long) (SYSCLK/BAUDRATE)/32);
   TMR2 = RCAP2;
   TR2= 1;                             // Start Timer2

   SCON0 = 0x50;                       // 8-bit variable baud rate;
                                       // 9th bit ignored; RX enabled
                                       // clear all flags
   TI0     = 1;                        // Indicate TX0 ready
}


//-----------------------------------------------------------------------------
// UART1_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Configure the UART1 using Timer1, for <baudrate> and 8-N-1.
// This routine configures the UART1 based on the following equation:
//
// Baud = (2^SMOD1/32)*(SYSCLK*12^(T1M-1))/(256-TH1)
//
// This equation can be found in the datasheet, Mode1 baud rate using timer1.
// The function select the proper values of the SMOD1 and T1M bits to allow
// for the proper baud rate to be reached.
//-----------------------------------------------------------------------------
void UART1_Init (void)
{
   SCON1   = 0x50;                     // SCON1: mode 1, 8-bit UART, enable RX

   TMOD   &= ~0xF0;
   TMOD   |=  0x20;                    // TMOD: timer 1, mode 2, 8-bit reload


   if ( (((SYSCLK/BAUDRATE)/256)/16) < 1 )
   {
      PCON |= 0x10;                    // SMOD1 (PCON.4) = 1 --> UART1 baudrate
                                       // divide-by-two disabled
      CKCON |= 0x10;                   // Timer1 uses the SYSCLK
      TH1 = - ((SYSCLK/BAUDRATE)/16);
   }
   else if ( (((SYSCLK/BAUDRATE)/256)/32) < 1 )
   {
      PCON &= ~0x10;                   // SMOD1 (PCON.4) = 0 --> UART1 baudrate
                                       // divide-by-two enabled
      CKCON |= 0x10;                   // Timer1 uses the SYSCLK
      TH1 = - ((SYSCLK/BAUDRATE)/32);
   }
   else if ( ((((SYSCLK/BAUDRATE)/256)/16)/12) < 1 )
   {
      PCON |= 0x10;                    // SMOD1 (PCON.4) = 1 --> UART1 baudrate
                                       // divide-by-two disabled
      CKCON &= ~0x10;                  // Timer1 uses the SYSCLK/12
      TH1 = - (((SYSCLK/BAUDRATE)/16)/12);
   }
   else if ( ((((SYSCLK/BAUDRATE)/256)/32)/12) < 1 )
   {
      PCON &= ~0x10;                   // SMOD1 (PCON.4) = 0 --> UART1 baudrate
                                       // divide-by-two enabled
      CKCON &= ~0x10;                  // Timer1 uses the SYSCLK/12
      TH1 = - (((SYSCLK/BAUDRATE)/32)/12);
   }
   TL1 = TH1;                          // Initialize Timer1
   TR1 = 1;                            // Start Timer1
   SCON1 |= 0x02;                      // Indicate TX1 ready (TI1=1)
}

//-----------------------------------------------------------------------------
// Support Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// putchar
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Configure the UART1 using Timer1, for <baudrate> and 8-N-1.
// This routine overloads the standard putchar() library function to support
// either UART0 or UART1, depending on the state of the global variable
// <UART>.
//
//-----------------------------------------------------------------------------
char putchar (char c)
{
   if (UART == 0)
   {
      if (c == '\n')                      // If carriage return
      {
         while (!TI0);
         TI0 = 0;
         SBUF0 = 0x0d;                    // Output CR
      }
      while (!TI0);                       // Wait for transmit complete
      TI0 = 0;
      SBUF0 = c;                          // Send character
   }
   else if (UART == 1)
   {
      if (c == '\n')                      // If carriage return
      {
         while ((SCON1 & 0x02) == 0);     // Wait for the transmit to complete
         SCON1 &= ~0x02;                  // Clear TI1
         SBUF1 = 0x0d;                    // Output CR
      }
      while ((SCON1 & 0x02) == 0);        // Wait for the transmit to complete
      SCON1 &= ~0x02;                     // Clear TI1
      SBUF1 = c;                          // Send character
   }
   return c;
}

//-----------------------------------------------------------------------------
// _getkey
//-----------------------------------------------------------------------------
//
// Return Value : Char received throught serial port (UART0 or UART1)
// Parameters   : None
//
// This routine overloads the standard _getkey() library function to support
// either UART0 or UART1, depending on the state of the global variable
// <UART>.
//-----------------------------------------------------------------------------
char _getkey ()
{
   char c;

   if (UART == 0)
   {
      while (!RI0);                       // Wait for byte to be received
      c = SBUF0;                          // Read the byte
   }
   else if (UART == 1)
   {
      while ((SCON1 & 0x01) == 0);        // Wait for the reception to complete
      c = SBUF1;                          // Read the byte
   }
   return (c);
}

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人av在线一区二区| 亚洲日本在线a| 韩国女主播一区| 精品国产百合女同互慰| 国产一区二区三区在线观看精品| www一区二区| 国产成人午夜精品5599| 亚洲国产精品高清| 色婷婷亚洲一区二区三区| 亚洲人成伊人成综合网小说| 欧美做爰猛烈大尺度电影无法无天| 亚洲乱码日产精品bd| 在线亚洲免费视频| 奇米四色…亚洲| 中文av字幕一区| 在线观看视频一区二区 | 99久久精品国产一区| 亚洲欧洲韩国日本视频| 欧美日韩精品一二三区| 精品影视av免费| 日韩一区在线播放| 欧美精品粉嫩高潮一区二区| 国产精品正在播放| 亚洲精品乱码久久久久久日本蜜臀| 欧美日本视频在线| 国产成人免费视频网站| 亚洲大尺度视频在线观看| 欧美大片在线观看| 91免费版在线| 久久69国产一区二区蜜臀| 国产精品麻豆视频| 91精品国产手机| 成人高清免费观看| 日韩国产在线一| 国产精品久久久久久久久免费桃花 | 色一情一乱一乱一91av| 美女国产一区二区三区| 亚洲欧美日韩精品久久久久| 日韩一级大片在线| 99re这里只有精品6| 精品写真视频在线观看| 一区二区三区在线观看国产| 久久亚区不卡日本| 欧美日韩国产综合一区二区| 成人国产电影网| 韩国av一区二区三区四区| 一区二区三区欧美亚洲| 中文av一区二区| 欧美大肚乱孕交hd孕妇| 欧美性感一区二区三区| caoporn国产精品| 久草这里只有精品视频| 亚洲国产综合色| 亚洲日穴在线视频| 国产嫩草影院久久久久| 欧美一级日韩一级| 欧美日韩的一区二区| 色综合视频一区二区三区高清| 国产福利一区在线| 久久黄色级2电影| 日韩av成人高清| 亚洲国产裸拍裸体视频在线观看乱了 | 国产超碰在线一区| 久久国产精品99精品国产| 日韩激情一二三区| 日韩国产欧美在线视频| 午夜电影网亚洲视频| 亚洲国产美女搞黄色| 亚洲激情男女视频| 亚洲精品精品亚洲| 亚洲美女视频一区| 亚洲精品国产视频| 亚洲美女区一区| 亚洲乱码国产乱码精品精的特点| 久久精品亚洲精品国产欧美 | 日韩午夜在线播放| 欧美精品高清视频| 3d成人动漫网站| 91精选在线观看| 欧美一区二区三区精品| 日韩你懂的电影在线观看| 精品美女一区二区三区| 久久先锋影音av| 欧美经典一区二区| 亚洲欧美日韩在线不卡| 亚洲欧美电影院| 亚洲国产va精品久久久不卡综合| 亚洲一区视频在线| 免费高清视频精品| 国产一区二区调教| 99国产精品久久| 欧美三片在线视频观看| 欧美一二区视频| 欧美精品一区二| 国产精品动漫网站| 一级做a爱片久久| 男人的j进女人的j一区| 国内偷窥港台综合视频在线播放| 黑人巨大精品欧美黑白配亚洲| 国产精品中文字幕日韩精品| 成人毛片视频在线观看| 欧美丝袜丝交足nylons图片| 在线播放中文字幕一区| 久久青草欧美一区二区三区| 亚洲欧美在线视频| 日韩中文字幕亚洲一区二区va在线| 麻豆精品一区二区av白丝在线| 国产精品一二二区| 欧美视频一区二区三区在线观看| 欧美一级片在线看| 亚洲天堂精品视频| 免费观看成人av| 99re8在线精品视频免费播放| 欧美精品自拍偷拍动漫精品| 欧美精品一区二区蜜臀亚洲| 亚洲人成影院在线观看| 狂野欧美性猛交blacked| 成人妖精视频yjsp地址| 51精品久久久久久久蜜臀| 中文字幕av一区二区三区| 日韩在线一区二区| av亚洲精华国产精华精华| 日韩一区二区三免费高清| 综合在线观看色| 久久99国产精品免费网站| 91国产视频在线观看| 国产无遮挡一区二区三区毛片日本| 亚洲福利一区二区| 成人午夜在线视频| 欧美一级一级性生活免费录像| 亚洲色图丝袜美腿| 国产精品主播直播| 欧美一区二区视频免费观看| 一区二区三区四区国产精品| 国产盗摄一区二区| 91精品国产综合久久精品麻豆| 亚洲欧洲日韩在线| 国产精品99久久久久久似苏梦涵| 欧美日韩精品电影| 伊人开心综合网| 成人福利电影精品一区二区在线观看| 欧美一区二区三区人| 亚洲综合色噜噜狠狠| a级精品国产片在线观看| www欧美成人18+| 日本三级韩国三级欧美三级| 色婷婷综合久久久久中文| 国产精品入口麻豆原神| 国产一区二区免费在线| 91精品国产黑色紧身裤美女| 亚洲一二三区在线观看| 91啦中文在线观看| 中文字幕五月欧美| 成人免费观看av| 中文字幕不卡一区| 成人av在线电影| 中文字幕免费观看一区| 国产精品66部| 国产区在线观看成人精品| 激情成人午夜视频| 精品91自产拍在线观看一区| 蜜桃久久精品一区二区| 日韩亚洲国产中文字幕欧美| 免费成人在线观看| 精品国产一区二区三区av性色| 日本不卡中文字幕| 日韩欧美国产三级电影视频| 青青草97国产精品免费观看无弹窗版| 欧美日韩在线免费视频| 婷婷夜色潮精品综合在线| 欧美日免费三级在线| 亚洲高清免费视频| 8v天堂国产在线一区二区| 蜜桃av一区二区三区电影| 日韩欧美亚洲国产另类| 国产乱人伦偷精品视频不卡| 久久婷婷一区二区三区| 国产成人免费在线观看| 国产精品女主播在线观看| 99精品偷自拍| 亚洲高清不卡在线观看| 欧美一二三在线| 韩国成人在线视频| 国产精品黄色在线观看| 欧美亚洲动漫另类| 秋霞av亚洲一区二区三| 久久久影院官网| 91在线国产福利| 午夜欧美大尺度福利影院在线看| 欧美一级片免费看| 国产91在线|亚洲| 亚洲免费三区一区二区| 欧美精品一二三| 久99久精品视频免费观看| 国产精品久久久久永久免费观看| 色综合婷婷久久| 美女免费视频一区二区| 国产精品家庭影院| 69精品人人人人| 成人亚洲精品久久久久软件|