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.
Previous article:AVR MCU Introduction--MEGA Port Operation
Next article:How to efficiently learn AVR microcontrollers
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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- Report: Four key factors driving the development of IoT chips
- Where can I find the most complete Chinese version of the tutorial for ad18? Some videos on the Internet are incomplete.
- Cadence Allegro software option question
- 【Mil MYS-8MMX】- 0: Unboxing Post
- Ask God for help
- 【EVAL-M3-TS6-665PN】1. Here comes a big guy-----EVAL-M3-TS6-665PN
- Working Principles and Applications of Embedded Systems
- A brief discussion on the application of PD and QC fast charging protocol deception chip circuit
- IAR prompts that the device cannot be connected
- I have a wireless radio code and I open it with IAR, but I don't have a board. How can I test it?