当前位置:网站首页>Arduino uno R3 register writing method (1) -- pin level state change
Arduino uno R3 register writing method (1) -- pin level state change
2022-07-06 12:04:00 【A geek is as deep as the sea】
Have studied 51 or STM32 Of , In particular STM32 The developers of register have a deep understanding and pain , because arduino The encapsulated function of , Make us in use , Don't look for the corresponding register , We only need to use the corresponding function , Once configured, it can be used . This is really the gospel of Xiaobai .arduino UNO It uses ATMEGA328P yes AVR A model of SCM , frequently-used Ardunio UNO and Arduino Pro Mini Are based on this chip , I studied arduino Register writing of , Make a note of . After saving, I forgot .
Statement : The author has never been in contact with AVR The writing method of single chip microcomputer , All the research materials come from Du Niang . Grammatical error or usage error , Welcome learned people to point out the maze
There are pairs in the official arduino Detailed annotation of relevant registers and pins of 

PORTx - Control output data 0、1; // Change the level state of the register pin
PINx — control ( Read ) input data ; // Read the level state of the register pin
Bold in instructions x Represents the register to be used ,
For example, to use D0—D7 Of , We used PD register , So that is
DDRD
PORTD
PIND
The basic introduction has been finished , Direct program comparison , Let's feel , If you want to light up D2 This pin
Let's first look at the usual writing
Look at the register writing
//#include <avr/io.h> // If the compilation is wrong , Then this function is introduced
void setup() {
DDRD=0B00000100; // The binary order is D7--D0;1 For export ,0 For input
PORTD=0B00000100; // The binary order is D7--D0;1 High level ,0 Low level
}
void loop() {
}
The simulation results are as follows 
Compare from one pin , We can see , Use register usage , You can use very small program storage space . Of course , This is a direct comparison , It makes no sense , Like playing hooligans . Functions are the encapsulation of registers , There are many things to call , It's like a middleman . It's easy to use, but of course it has to pay a certain cost .
Now let's take a look at the read pin status , This time we use A0-A5 To see the data
//#include <avr/io.h> // If the compilation is wrong , Then this function is introduced
void setup() {
DDRC=0B000100; // The binary order is A5--A0;1 For export ,0 For input
PORTC=0B000100; // The binary order is A5--A0;1 High level ,0 Low level
Serial.begin(9600);
Serial.print(PINC,BIN); // Read PC The pin status of the register
}
void loop() {
}

Simulation results 
I will continue to introduce later , Update from time to time
边栏推荐
- Vert. x: A simple TCP client and server demo
- R & D thinking 01 ----- classic of embedded intelligent product development process
- sklearn之feature_extraction.text.CountVectorizer / TfidVectorizer
- Reading notes of difficult career creation
- Small L's test paper
- Détails du Protocole Internet
- ESP8266通过Arduino IDE连接Onenet云平台(MQTT)
- MySQL START SLAVE Syntax
- Apprentissage automatique - - régression linéaire (sklearn)
- C language, log print file name, function name, line number, date and time
猜你喜欢

ESP learning problem record

Basic use of pytest

2019 Tencent summer intern formal written examination

E-commerce data analysis -- salary prediction (linear regression)

AMBA、AHB、APB、AXI的理解

Implementation scheme of distributed transaction

电商数据分析--薪资预测(线性回归)

STM32 how to locate the code segment that causes hard fault

Linux Yum install MySQL

优先级反转与死锁
随机推荐
ESP learning problem record
Time slice polling scheduling of RT thread threads
Some concepts often asked in database interview
机器学习--线性回归(sklearn)
ToggleButton实现一个开关灯的效果
IOT system framework learning
Arm pc=pc+8 is the most understandable explanation
Priority inversion and deadlock
Variable parameter principle of C language function: VA_ start、va_ Arg and VA_ end
列表的使用
Kaggle competition two Sigma connect: rental listing inquiries (xgboost)
gcc 编译选项
[template] KMP string matching
[esp32 learning-2] esp32 address mapping
RT-Thread的main线程“卡死”的一种可能原因及解决方案
Togglebutton realizes the effect of switching lights
Mall project -- day09 -- order module
Stage 4 MySQL database
Dependency in dependencymanagement cannot be downloaded and red is reported
Unit test - unittest framework

