📄 function.c
字号:
//=================================================================================================
//*************************************************************************************************
// Module Name : Function.C
// Device object:
// CreateDate : 2005-11-14
// ModifData : 2005-11-14
// Description :
// Author : 李远正
// Version : V1.0
//*************************************************************************************************
//=================================================================================================
//
#include <regx52.h> // SFR declarations
#include "Function.H"
//=================================================================================================
//
//=================================================================================================
//
//=================================================================================================
//=================================================================================================
//#define SYSCLK 11059200 // SYSCLK frequency in Hz
//=================================================================================================
// UART_Init
//=================================================================================================
// Configure the UART0 using Timer2, for <baudrate> and 8-N-1.
//
#define BAUDRATE0 115200 // Baud rate of UART0 in bps
//-------------------------------------------------------------------------------------------------
// UART Initialization
void UART0Init( void )
{
SCON = 0x50; // 串行口工作在方式3
TMOD = 0x20; // T1为方式2
TH1 = 0xFE; // 计数常数0xFE,波特率:14400 晶振:11.0592MHz
TL1 = 0xFE;
PCON &= 0x7F; // SMOD=0
TR1 = 1;
#if UART0_INT_EN == 1 // Enable UART0 interrupts
ES = 1; // Enable UART0 interrupts
#endif
}
//-------------------------------------------------------------------------------------------------
#if UART0SendByte_EN
//-------------------------------------------------------------------------------------------------
// UART0 Send Byte
void UART0SendByte( unsigned char datum )
{
ES = 0; // Disable UART0 interrupts
TI = 0;
SBUF = datum;
while ( TI == 0 ) ; // Waiting...
#if UART0_INT_EN == 1 // Enable UART0 interrupts
ES = 1; // Enable UART0 interrupts
#endif
}
//-------------------------------------------------------------------------------------------------
#endif
//-------------------------------------------------------------------------------------------------
#if UART0SendString_EN
//-------------------------------------------------------------------------------------------------
// UART0 Send String
void UART0SendString( unsigned char *p )
{
ES = 0; // Disable UART0 interrupts
while( *p != '\0' )
{
SBUF = *p++;
while( TI == 0 ) ; // Waiting...
TI = 0;
}
#if UART0_INT_EN == 1 // Enable UART0 interrupts
ES = 1; // Enable UART0 interrupts
#endif
}
//-------------------------------------------------------------------------------------------------
#endif
//-------------------------------------------------------------------------------------------------
#if UART0RecvByte_EN
//-------------------------------------------------------------------------------------------------
// UART0 Receive Byte
unsigned char UART0RecvByte( void )
{
unsigned char datum;
ES = 0; // Disable UART0 interrupts
while ( RI == 0 ) ; // Waiting...
datum = SBUF;
RI = 0;
#if UART0_INT_EN == 1 // Enable UART0 interrupts
ES = 1; // Enable UART0 interrupts
#endif
return( datum );
}
//-------------------------------------------------------------------------------------------------
#endif
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
// UART0 Receive Interrupt
#if UART0_INT_EN == 1 // Enable UART0 interrupts
void UART0_ISR( void ) interrupt 4
{
unsigned int count;
unsigned char buffer;
RI = 0; // Clear Flag of RI0
ES = 0; // Disable UART0 interrupts
ES = 1; // Enable UART0 interrupts
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -