AVR MCU Port Settings

Publisher:翅膀小鹰Latest update time:2013-01-05 Source: 21IC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

DDRA=OXFF;

PORT=OXFF;

and

PORT=OXFF;

DDRA=OXFF;

There is a difference. The level changes of the IO ports corresponding to these two sequences are different. This difference is in the performance of the product. There is no obvious difference on the surface. It may be difficult to understand without a certain circuit foundation. DDRA and PORTA are both 0x00 by default when powered on; if you set the direction DDRA and then PORTA, set it to all output low levels in the output direction, and then set the level. At this time, the output is high. Then, on the IO port that outputs the high level, there will be an instantaneous change from low level to high level. Because the IO port direction is already output during the change, the signal has a certain amount of energy and will produce certain interference. If you set the level first and then the direction: the instantaneous change mentioned above will not occur.

[MCU port settings]

ATMEGA8 MCU I/O port initialization problem

Generally, unused IO ports are set as inputs and pull-up is enabled.

Even if something goes wrong with the input, such as a short circuit, there will be no level conflict. If it is set to output and is connected to the opposite level by mistake, it is inevitable that tens of milliamperes of current will be wasted, which may damage the device over time.

The purpose of pull-up is to stabilize the electrical level of the IO port. If only input is applied but no pull-up is performed, the IO port will be in a high-impedance state. When there is an external interference signal, it will easily receive the signal, causing high-frequency changes in the internal circuit of the IO port, which will also waste current. What's worse is that the CPU will easily be interfered with and freeze.

I saw some people on the Internet who didn't quite understand the pull-up and pull-down of resistors. The pull-up and pull-down of the input terminal are very simple but also very important.

Pull-up: Connect to power through a resistor. Pull-down: Connect to ground through a resistor.

Pulling up and down generally has two uses: improving the driving capability of the output signal and determining the level of the input signal (to prevent interference).

Anyone who has used 8051 knows that the CPU I/O is usually connected with a resistor (pull-up to 5V), which is mainly to improve the output drive capability. Because the 8051 CPU is not a standard I/O port, it can absorb 20mA of current when the output is low, but when the output is high, it is pulled up by a large internal resistor. The driving capability is very poor when the output is high, so an external pull-up is used to improve the output drive capability.

Generally, the base of a transistor has two resistors, one for current limiting and the other for pull-up or pull-down. The pull-up and pull-down here are mainly used to determine the level of the input signal. In fact, the goal is to prevent interference, because the input interface of the device generally has a large internal resistance and is easily interfered. Connecting a pull-up and pull-down resistor actually reduces the input impedance and improves the anti-interference ability.

Generally, unused input ports of components are required to be connected with pull-up or pull-down resistors. Note that unused output ports should not be connected with anything.

Reference address:AVR MCU Port Settings

Previous article:AVR MCU Introduction--MEGA Port Operation
Next article:How to efficiently learn AVR microcontrollers

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号