AVR I/O port settings

Publisher:温馨如家Latest update time:2017-12-18 Source: eefocusKeywords:AVR  I  Port Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

We often need to set an I/O port as output, input, or input with pull-up. In fastavr, this is how it works: 

Example:

Set the entire A port as output:

ddra=255 'Decimal representation, the single quote at the beginning or end of a line is a comment, the default color is green

ddra=&hff 'Hexadecimal representation, hexadecimal number plus prefix &h

ddra=&B11111111 ' Binary representation, binary number plus prefix &B

Set the high four bits of port A as output and the low four bits as input:

ddra=&B11110000

porta=porta Or &b00001111 'Use the logic OR method to turn on the pull-up of the lower four bits without affecting the output state of the upper four bits

Set the entire B port as input:

ddrb=0

ddrb=&h00

ddrb=&b00000000

Enable all pull-ups on port B, or enable partial pull-ups on port B:

portb=255: portb=&b11000011 'When we want to write multiple statements in one line, please separate them with colons

To set a single I/O port:

set ddra.7 'porta seventh position is the output port

reset ddrb.0 'portb.0 is the input port

set portb.0 'Then turn on the pull-up of portb.0

When we want to clear some bits without affecting other bits, we use logical AND.

porta=porta and &B01111110 'porta.7, porta.0 are cleared without affecting other bits

Summary: If we only want to set a single input and output port, we can use the set and reset instructions. If we want to change several bits of a port at the same time, it is best to use

Use logical AND or NOT to complete it. AND can be used to clear, OR can be used to set, and NOT can be used to negate.


Keywords:AVR  I  Port Reference address:AVR I/O port settings

Previous article:AVR C language programming style
Next article:AVR GCC Chinese Manual

Latest Microcontroller Articles
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号