#include
typedef unsigned char uint8_t;
#define DF_Config_Uart0_BaudRate 9600
//UART0 initialization
// desired baud rate: 9600
// actual: baud rate:9600 (0.0%)
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
//Configure baud rate
#if DF_Config_Uart0_BaudRate==9600
//----------11.0592M 9600kbps:
UBRRL = 0x47; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
#else if DF_Config_Uart0_BaudRate==19200
//----------11.0592M 19200kbps:
UBRRL = 0x23; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
#endif
UCSRB = 0x98;
}
// Send a byte
void uart0_sendByte(uint8_t dat)
{
while(!(UCSRA&(1<
}
// Send multiple bytes of data
void uart0_sendData(uint8_t *pDat,uint8_t nCount)
{
uint8_t i;
uint8_t *p = pDat;
for (i=0; i
uart0_sendByte(*p++);
}
}
// Send string
void uart0_sendString(uint8_t *pDat)
{
uint8_t *p = pDat;
while(*p)
{
uart0_sendByte(*p++);
}
}
// Serial port receive interrupt
#pragma interrupt_handler uart0_rx_isr:iv_USART0_RXC
void uart0_rx_isr(void)
{
//uart has received a character in UDR
#if 1 // For test
uint8_t dat=UDR;
uart0_sendByte(dat);
#else
#endif
}
/*-----------------------------------------------------------------
Function name: void uart_receive(void)
Function function: Query mode, receive data
Parameter:
Return value: None
-----------------------------------------------------------------*/
uint8_t uart0_receive(void) //Define the return value type, otherwise an error
{
while(!(UCSRA&(1<
}
/*
Previous article:ATMEGA16 read and write iic (24c02) C language program test passed
Next article:How to define string constants in AVR assembler
Recommended ReadingLatest update time:2024-11-16 19:25
- Popular Resources
- Popular amplifiers
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
- 【MM32 eMiniBoard Review】2a. Found that the virtual serial port may have problems, and the serial port routines cannot receive
- Help! Does anyone know what sensor this is?
- Do you usually read e-books or paper books now?
- ADC12 single channel multiple conversion routine (MSP430F5529)
- Motor startup interferes with the microcontroller problem
- Chapter 3 Interrupts, Clocks, and Low Power Consumption
- The difference between C64x+ and C64x CACHE in the C6000 series
- Realization of voltage to current conversion in Multisim12
- 【Smart Network Desk Lamp】7. Get real-time weather information and analyze it
- [RISC-V MCU CH32V103 Review] +01 Try the use of GPIO to light up the first LED