標(biāo)題: 松翰SN8F5703單片機USART例程 [打印本頁]

作者: hexinquan    時間: 2020-12-8 11:39
標(biāo)題: 松翰SN8F5703單片機USART例程
  1. //-----------------------------------------------------------------------------
  2. //  FILE:   UART.c
  3. //-----------------------------------------------------------------------------
  4. //  Copyright 2014 Sonix Technology Corp. All rights reserved.
  5. //
  6. //  AUTHOR:     Sonix
  7. //  DATE:       2015/11/03
  8. //
  9. //        CheckSum = 0xD0A8
  10. //  The program is an example of UART to implement it.
  11. //
  12. //  UART decription:
  13. //      Mode 1 of UART  --  10bit
  14. //
  15. //  The system clock frequency is IHRC 32MHz
  16. //
  17. //  Device:     SN8F5703
  18. //  Tool chain: KEIL C51 V9.50a
  19. //
  20. //-----------------------------------------------------------------------------
  21. // Includes
  22. //-----------------------------------------------------------------------------
  23. #include <SN8F5703.h>
  24. #include "UART.h"
  25. //-----------------------------------------------------------------------------
  26. // Main loop
  27. //-----------------------------------------------------------------------------
  28. void main(void)
  29. {
  30.   uint8_t tmp;

  31.         CLKSEL = 0x06;                                                                                        // Fcpu = 32M/2 = 16M
  32.         CLKCMD = 0X69;                               
  33.         CKCON = 0X10;                                                                                                // From = 8M
  34.        
  35.         WDTR = 0x5A;                                    // clear watchdog
  36.        
  37.         P0 = 0x01;
  38.         P0M = 0x01;                                                                                                        // UTX is output high, URX is input
  39.         P0UR = 0xFF;
  40.        
  41.         P1 = 0;
  42.         P1M = 0;
  43.         P1UR = 0xFF;
  44.        
  45.         P2 = 0;
  46.         P2M = 0;
  47.         P2UR = 0xFF;
  48.        
  49.   UART_Init();

  50.     while (1)
  51.         {
  52.                 if(u8RxBufLength1!=u8RxBufLength)        //如果收到數(shù)據(jù)
  53.                 {       
  54.                         tmp=u8RxBuf[u8RxBufLength1++];        //發(fā)送收到的數(shù)據(jù)
  55.                         UART_WriteOneByte(tmp);
  56.                         if (u8RxBufLength1 >= BufSize)  //取指針超過設(shè)定值,從0開始取數(shù)據(jù),指向0
  57.                         {
  58.                                 u8RxBufLength1 = 0;                                               
  59.                         }
  60.                 }
  61.     }
  62. }
復(fù)制代碼

5703_UART_20161103.rar

110.81 KB, 下載次數(shù): 14, 下載積分: 黑幣 -5






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1