uart0_init.c
来自「基于8051F单片机,实现1024点的FFT 用C 语言实现的.效果与FPGA」· C语言 代码 · 共 50 行
C
50 行
#include "common.h"
//-----------------------------------------------------------------------------
// UART0_Init
//-----------------------------------------------------------------------------
//
// Configure the UART0 using Timer1, for <baudrate> and 8-N-1. In order to
// increase the clocking flexibility of Timer0, Timer1 is configured to count
// SYSCLKs.
//
// To use this routine SYSCLK/BAUDRATE/16 must be less than 256. For example,
// if SYSCLK = 50 MHz, the lowest standard baud rate supported by this
// routine is 19,200 bps.
void UART0_Init (void)
{
char old_SFRPAGE = SFRPAGE; // Store current SFRPAGE
SFRPAGE = UART0_PAGE; // Switch to UART0 Page
SCON0 = 0x50; // SCON0: mode 0, 8-bit UART, enable RX
SSTA0 = 0x10; // Timer 1 generates UART0 baud rate and
// UART0 baud rate divide by two disabled
SFRPAGE = TIMER01_PAGE;
TMOD &= ~0xF0;
TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit reload
TH1 = -(SYSCLK/BAUDRATE/16); // Set the Timer1 reload value
// When using a low baud rate, this
// equation should be checked to ensure
// that the reload value will fit in
// 8-bits.
CKCON |= 0x10; // T1M = 1; SCA1:0 = xx
TL1 = TH1; // initialize Timer1
TR1 = 1; // start Timer1
SFRPAGE = UART0_PAGE;
TI0 = 1; // Indicate TX0 ready
SFRPAGE = old_SFRPAGE; // restore SFRPAGE
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?