#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar g_bTxdPos=0; //Send positioning counter
uchar g_bTxdLen=0; //Waiting for the number of bytes to be sent
uchar g_bRxdPos=0; //Receive positioning counter
uchar g_bRxdLen=0; //Waiting for the number of bytes to be received
uchar g_aSendBuf[16]; //Send data buffer
uchar g_aRecvBuf[16]; //Receive data buffer
//Receive interrupt
SIGNAL (SIG_ UART _RECV)
{
uchar c=UDR;
if(g_bRxdLen>0)
{
g_aRecvBuf[g_bRxdPos++]=c;
g_bRxdLen--;
}
}
//Send interrupt
SIGNAL (SIG_UART_TRANS)
{
if(--g_bTxdLen>0)
UDR=g_aSendBuf[++g_bTxdPos];
}
//Is reception completed
uchar IsRecvComplete(void)
{
return g_bRxdLen==0;
}
//Send data of specified length from send buffer
void SendToUart(uchar size)
{
g_bTxdPos=0;
g_bTxdLen=size;
UDR=g_aSendBuf[0];
while(g_bTxdLen>0);
}
//Receive data of specified length to receive buffer
void RecvFromUart(uchar size,uchar bwait)
{
g_bRxdPos=0;
g_bRxdLen=size;
if(bwait)
while(g_bRxdLen>0);
}
int main( void )
{
uchar i;
//uart initialization
//receive enable, transmit enable, receive interrupt enable, transmit interrupt enable
UCSRB=(1<
sei();//Total interrupt enabledwhile
(1)
{
//Asynchronously receive 16 bytes of dataRecvFromUart
(16,0);
//Wait for reception to completewhile
(!IsRecvComplete());
//Copy the received data to the send bufferfor
(i=0;i<16;i++)
g_aSendBuf=g_aRecvBuf;
//Send back the received dataSendToUart
(16);
}
}
Previous article:AVR-GCC about reti()
Next article:AVR simple and universal serial port configuration method
Recommended ReadingLatest update time:2024-11-16 13:28
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- 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
- Summary of DSP boot mode / boot loader / power-on sequence / online upgrade and other issues
- [ATmega4809 Curiosity Nano Review] Using MCC in MPALB Xpress
- Use a simple field strength meter to test 433 wireless coverage, wireless dead spots, and compare antenna differences
- Will the reset pin of the microcontroller be invalid?
- Received the X-NUCLEO-IKS01A3 sensor kit
- 【Mil MYD-YA15XC-T】- 0: How to power on?
- Xilinx Zynq-7015 SoC Industrial Core Board SOM-XQ7Z15 Cortex-A9 + Artix-7
- ADI Power Supply Expert Training Course Advanced Edition is in progress! What are you waiting for?
- ARM Architecture and Programming
- Gigabit RISC-V GD32VF103USB CDC debugging