ATMEGA16 Ioport Related summaries

Source: Internet
Author: User

ATMEGA16 Ioport Total co-ownership registers have three Ddrx, Portx and PinX.

Suppose you want the IO action to basically manipulate with these three registers. Ddrx is also known as data direction registers, portx so-called data registers, PinX called port input pins.

The role of Ddrx:

When Ddrx = 0 o'clock. Indicates that the PIN for a port is input, and that the pin for a port is output when Ddrx = 0xFF.

Pin Status: What is the definition of the input or output?

is based on the high and low level is the input microcontroller or from a single-chip computer output. Input refers to: does not belong to the MCU external level input to the microcontroller; the output refers to: MCU level output to the outside of the microcontroller.

The role of Portx:

When Ddrx = 0 o'clock, if the portx is set to start the pull-up resistor, if the portx is 0, the pull-up resistor is not activated. When Ddrx = 0xFF, if the portx is set to indicate the output high level, if the portx is 0, the output is low.

The role of PinX:

The value of the PinX register is not related to the value of the DDRX register (input or output), but only to the value above the port pin (PORTX). Assuming portxn = 0XDD, no matter what value the DDTX takes. The PinX are 0Xdd.

#include <avr/io.h> #include <util/delay.h>int main (void) {   uint8_t temp;   DDRC = 0xFF;   PORTC = 0xFF;   Ddra = 0;   PORTA = 0XDD;   ASM ("NOP");//assembly instruction NOP, i.e. empty operation. Its running time is one clock cycle   PORTC = Pina;    return 0;}

Whether the value of Ddra is 0 or 0xFF. The results are all the same.

It is also possible to draw a conclusion that the values in the PinX register can be set according to their own wishes. The reason is that the single-chip function captures the level of port and resets the PinX register.

Initial value problem:

The microcontroller has just been power-up. What is the initial value of the register on the port?

When power is on, the default initial value is 0. That is ddrx= 0;portx = 0. PINX = 0;

#include <avr/io.h> #include <util/delay.h>//#include <intrins.h>int main (void) {   uint8_t temp;   DDRC = 0xFF;   PORTC = 0xFF;   Ddra = 0;   PORTA = 0XDD;   ASM ("NOP");//assembly instruction NOP, i.e. empty operation. Its running time is a clock cycle   //_nop ();   PORTC = Pina;    return 0;}

Initialization Method 1:
Porta=0xff; Internal pull-up, high level

Ddra=0xff; Output high-level---------lamp is always off

Initialization Method 2:

Ddra=0xff; The output low--------light is lit by mistake.

Porta=0xff; The output high level--------is immediately extinguished, the time is very short (1 instructions less than us time), the lamp flashed, the eyes can not detect



Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

ATMEGA16 Ioport Related summaries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.