#define SENDBUFSIZE 0x0f
#define BR_19K2 0xfd
#define RMAX 0x10 //Must be an integer power of 2. Seen on 21ic, seems to be the idea of "Senior Liu"
unsigned char xdata *cpSendBufPtr;
unsigned char cFront;
unsigned char cBack;
unsigned char sendData;
bit cTranFlag;
unsigned char cTranData;
bit cRecFlag;
unsigned char cRecData;
bit cJudge;
unsigned char temp;
void HardWareInit();
void Uart_Init(void);
void Uart_Init(void);
void COMM_Init(unsigned char cBaudRate, bit bSMOD); //初始化UART
//sfr AUXR = 0x8E;
//MODE COM4 19200,0,8,1;ASSIGN COM4
//The baud rate is 19200Hz. Will the data received by the serial port be forwarded again?
//The data receiving speed may be greater than the sending speed. Increase the buffer and save the received data first.
main()
{
sendData=0;
cFront=0; //
cBack=0;//
cRecFlag=0; //No data received yet
cTranFlag=1;//After the system is reset, as long as the queue is not empty, data can be sent at any time
RS0 = RS1 = 0;// Use register group 0
AUXR = 0x01; //Disable ALE signal output
EA = 0;
P1 = 0xFF;
P2 = 0xFF;
P3 = 0xFF;
P4 = 0xFF;
ES = 0;
TR1 = 0;
TMOD = TMOD & 0x0f | 0x20;
TH1 = BR_19K2;
TL1 = BR_19K2; ////------------------------------------------------------------------------------------------
PCON = 0x80; // If SMOD=1, baud rate multiplication
SCON = 0x50; // 8-bit
IP = 0x10; // Serial port priority interrupt
ES = 1;
// wifi module: baud rate 19200/38400/57600/115200bps data bit: 8bits check bit: none stop bit: 1bit flow control: none
EA = 1;
TR1 = 1;
// SBUF=0x12;
while(1)
{
/*
*/// 14 15 16 17 18 19 20 21
if(cRecFlag)
{
temp=((cFront+1)^cBack)&0x0f;
if(temp!=0) //The circular linked list is not full yet, you can continue to add data
{
cFront=cFront+1;
cFront=cFront&(RMAX-1);
cpSendBufPtr[cFront]=cRecData;
cRecFlag=0;
}
}
if(cTranFlag)
{
temp=(cBack^cFront)&0x0f;//A new number is sent, this place is cBack instead of cBack+1
if(temp!=0) //Data can be sent when the circular linked list is not empty
{
cBack=cBack+1;
SBUF=cpSendBufPtr[cBack];
cpSendBufPtr[cBack]=0x00;
cBack=cBack&(RMAX-1);
cTranFlag=0;
}
}
}
}
/*******************************************************************************
// Function: UART completes data transmission and reception and generates an interrupt program
// Input parameter: None
// Output parameter: None
// Return value: None
******************************************************************************/
void COMM_INT() interrupt 4 using 3
{
if(RI)//If the received data is being processed, the data in SBUF is discarded ^cRecFlag
{
cRecData=SBUF;
cRecFlag=1;
RI=0;
}
if(TI)
{
cTranFlag=1;
TI=0;
}//Sending is completed, and cTranData is assigned a new value*/
}
Previous article:DAC0832 generates triangle wave and sine wave
Next article:Analysis and Research on the Baud Rate of Simulated Serial Port
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Everyone is paying attention to Qorvo's broadband access CATV and FTTH products
- Introduction to TI C2000 Chopper Module
- TI - MCU - MSP430 User Guide 31 -> BSL
- EEWORLD University - How to use independent measurement ADC to design high-precision CT phase meter
- A collection of selected PCB design resources, free points download for a limited time
- MCU model confirmation and decryption
- [Zero-knowledge ESP8266 tutorial] Quick start 25 Blynk control RGB LED
- Need a 10uh inductor, ESR < 0.2Ω, saturation current > 0.8A
- Ti DSP optimization basic strategy
- Bluetooth Protocol Stack-01