AVR ATMEGA8 Serial Port USART

Publisher:古古斋Latest update time:2019-12-10 Source: eefocusKeywords:AVR  ATMEGA8  USART Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The avr serial port configuration is very simple, just configure a few registers to send and receive;


But there are a few things to understand:


1. Once the serial port is successfully configured, the IO function is automatically occupied, which is different from LPC or STM8/32 (registered configuration is required);


2. There is no dedicated serial port opening or closing position (the entire serial port);


3. When reading and writing control register C, the URSEL bit needs to be written as 1, and when reading and writing the UBRRH register, URSEL needs to be written as 0;


   1: //Crystal oscillator frequency  

   2: #define F_CPU 6000000UL  

   3: //Baud rate  

   4: #define BAUD 9600  

   5:  

   6: //M8 serial port 1 initialization

   7: void UsartInit(void)

   8: {

   9:     unsigned int tmp;

  10:     FifoInit(&RxFifo, sizeof(RxFifo.data));

  11:     FifoInit(&TxFifo, sizeof(TxFifo.data));

  12:     tmp= F_CPU/BAUD/16-1;

  13: SetBit(SREG, 7);

  14:     UCSRB = 0;

  15:     UCSRC = 0;

  16:     UBRRH=(unsigned char)(tmp>>8);

  17:     UBRRL=(unsigned char)tmp;

  18: UCSRB |= (1<  19: UCSRC |= (1 << URSEL)|(1<  20: }


Keywords:AVR  ATMEGA8  USART Reference address:AVR ATMEGA8 Serial Port USART

Previous article:AVR official charger
Next article:FreeModbus Lite Version (Only RTU) for M128 (Modbus Slave)

Recommended ReadingLatest update time:2024-11-15 15:39

Design of portable instrument by using AVR microcontroller ATXmega128A1
1 Introduction Industrial instruments have become one of the foundations and cores of the industrial control field because they integrate information acquisition, conversion, storage, transmission, analysis, processing and display. With the development of computer technology and microelectronics technology, industrial
[Microcontroller]
Design of portable instrument by using AVR microcontroller ATXmega128A1
STM32 library function assertion
When we learn STM32, the function assert_param is very likely to appear. If you search online, you will find that the assertion mechanism is generally explained online and is used during the program development and debugging stage. Next, I will talk about my views on these applications. When learning something, you sho
[Microcontroller]
STM32 library function assertion
AVR Development Arduino Method (I) Port Subsystem
  There are three 8-bit input/output ports on the main processor ATMega328P of Arduino UNO R3, namely PB, PC and PD. The Blink example provided by Arduino IDE can help us understand the digital output function of the port:   1 // Blink.ino  2 int led = 13;  3   4 void setup() {  5   pinMode(led, OUTPUT);  6 }  7   8
[Microcontroller]
AVR Development Arduino Method (I) Port Subsystem
Fuse settings to enable Atmega8A-PU to support external crystal
I played with an Arduino recently, but I felt that the board I bought was not satisfying enough, so I followed the online tutorials to tinker with the minimum Arduino system. The process was very tortuous, so I have summarized and recorded some of the content for future reference. Reference article: Arduino 1.0 - Ma
[Microcontroller]
Fuse settings to enable Atmega8A-PU to support external crystal
AVR MCU driver NOKIA3310 sample program
#include          #include          #include           void main(void)         {             PORTB&=209;           DDRB|=46; //Set the MCU's 4 LCD pins to output 0            while(1)                 {                    lcd_init(); //LCD initialization                           lcd_cls(); //Clear the screen,
[Microcontroller]
AVR single chip microcomputer and LCD liquid crystal module to control the information monitoring terminal design
At present, with the rapid development of the information industry, all kinds of ships are in urgent need of being equipped with more high-quality and low-cost small and medium-sized information monitoring terminals to monitor weather conditions and obtain navigation information to ensure navigation safety. 32-bit pro
[Microcontroller]
AVR single chip microcomputer and LCD liquid crystal module to control the information monitoring terminal design
AVR_GCC Programming Basics
1. In the project options of avr studio, in the General option, you need to pay attention to the following: edit configuration: This option means that the default output folder of the current project is default, and the name of this folder can be changed Device: is the chip we want to choose to work Frequency: is t
[Microcontroller]
AVR_GCC Programming Basics
Operation of internal EEPROM of AVR series
This program targets the internal EEPROM of M16. Its size is only 512 bytes. When operating it, you should pay attention to its operation timing. First, wait for the operation (read or write) of EEPROM to be disabled, that is, EEWE/EERE in the control register is 0. Then write the address and then write data to the da
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号