/**********Serial port definition**********/
#define RxD PD0
#define TxD PD1
#define baudrate 9600 //Baud rate
#define F_CPU 8000000UL //Define crystal frequency
void uart_init(void)
{
/*****RS232 port line settings*****/
PORTD|=BIT(RxD)|BIT(TxD);
DDRD&=~BIT(RxD);
DDRD|=BIT(TxD);
/* Set baud rate*/
UBRRL=(F_CPU/baudrate/16-1)%256; //This setting does not double the baud rate and U2X=0
UBRRH=(F_CPU/baudrate/16-1)/256;
/* Receiver and transmitter enable*/
UCSRB|=BIT(4)|BIT(3);
/* Set transmission format*/
//Asynchronous, 8-bit data, no parity, one stop bit, no speed
UCSRC|=BIT(7)|BIT(2)|BIT(1);
}
//Serial port data transmission, query method
void putc(unsigned char c)
{
/* Wait for the transmission buffer to be empty*/
while (!(UCSRA&(1<
UDR = c;
}
//Serial string sending, query method
void puts(unsigned char *s)
{
while(*s)
{
putc(*s);
s++;
}
putc('\n');
//return 1;
}
//Serial port data reception, query method
unsigned char getc(void)
{
/* Wait for receiving data*/
while (!(UCSRA&(1<
return UDR;
}
//Serial port receives data and stores it in an array
void get_s(unsigned char *js,unsigned int num)
{
unsigned int i;
for(i=0;i
js[i]=getc(); //Save data into the array
}
}
//test.c
//ICC-AVR application builder : 2008-11-4 12:34:31
// Target : M16
// Crystal: 8.0000Mhz
#include
#include
#include "uart.h"
void main(void)
{
uart_init();
while(1)
{
putc(getc());
}
}
Previous article:mega16 test board test code 2 - LCD 1602 four-line display
Next article:PCF8563 source code of AVRM16
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- 【IoT Graduation Project】Gizwits IoT Platform + Arduino Nano Control Board + Fully Automatic and Efficient Intelligent Tree Planting Car
- HC32F460 Clock System Introduction
- Swagbadge2021 Digital Badge
- Power inductor parameter issues
- How to use arrays in C language for microcontrollers
- Newbies to the forum
- How to read the level of P9~p0 of MAX7317
- October is Open Hardware Month
- Invitation: EEWorld 15th Anniversary Carnival series of activities has begun, it’s great to have you!
- Stock materials, transfer to those in need at low prices.