当前位置:网站首页>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
边栏推荐
- map文件粗略分析
- GCC compilation options
- Internet protocol details
- Unit test - unittest framework
- Distribute wxWidgets application
- Analysis of charging architecture of glory magic 3pro
- .elf .map .list .hex文件
- Reading notes of difficult career creation
- Using LinkedHashMap to realize the caching of an LRU algorithm
- Comparaison des solutions pour la plate - forme mobile Qualcomm & MTK & Kirin USB 3.0
猜你喜欢
随机推荐
Detailed explanation of express framework
Variable star user module
Comparison of solutions of Qualcomm & MTK & Kirin mobile platform USB3.0
Rough analysis of map file
Hutool中那些常用的工具类和方法
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries
Come and walk into the JVM
Apprentissage automatique - - régression linéaire (sklearn)
Unit test - unittest framework
物联网系统框架学习
FTP文件上传文件实现,定时扫描文件夹上传指定格式文件文件到服务器,C语言实现FTP文件上传详解及代码案例实现
gcc 编译选项
Redis面试题
Keyword inline (inline function) usage analysis [C language]
Some concepts often asked in database interview
uCOS-III 的特点、任务状态、启动
锂电池基础知识
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries(XGBoost)
几个关于指针的声明【C语言】
There are three iPhone se 2022 models in the Eurasian Economic Commission database






![Several declarations about pointers [C language]](/img/9b/ace0abbd1956123a945a98680b1e86.png)


