|
- //-----------------------------------------------------------------------------
- // FILE: UART.c
- //-----------------------------------------------------------------------------
- // Copyright 2014 Sonix Technology Corp. All rights reserved.
- //
- // AUTHOR: Sonix
- // DATE: 2015/11/03
- //
- // CheckSum = 0xD0A8
- // The program is an example of UART to implement it.
- //
- // UART decription:
- // Mode 1 of UART -- 10bit
- //
- // The system clock frequency is IHRC 32MHz
- //
- // Device: SN8F5703
- // Tool chain: KEIL C51 V9.50a
- //
- //-----------------------------------------------------------------------------
- // Includes
- //-----------------------------------------------------------------------------
- #include <SN8F5703.h>
- #include "UART.h"
- //-----------------------------------------------------------------------------
- // Main loop
- //-----------------------------------------------------------------------------
- void main(void)
- {
- uint8_t tmp;
- CLKSEL = 0x06; // Fcpu = 32M/2 = 16M
- CLKCMD = 0X69;
- CKCON = 0X10; // From = 8M
-
- WDTR = 0x5A; // clear watchdog
-
- P0 = 0x01;
- P0M = 0x01; // UTX is output high, URX is input
- P0UR = 0xFF;
-
- P1 = 0;
- P1M = 0;
- P1UR = 0xFF;
-
- P2 = 0;
- P2M = 0;
- P2UR = 0xFF;
-
- UART_Init();
- while (1)
- {
- if(u8RxBufLength1!=u8RxBufLength) //如果收到数据
- {
- tmp=u8RxBuf[u8RxBufLength1++]; //发送收到的数据
- UART_WriteOneByte(tmp);
- if (u8RxBufLength1 >= BufSize) //取指针超过设定值,从0开始取数据,指向0
- {
- u8RxBufLength1 = 0;
- }
- }
- }
- }
复制代码 |
|