当前位置:网站首页>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
![ Insert picture description here ](https://img-blog.csdnimg.cn/369a3b2b7eb84d9fb2846a3bec8549cf.png
You can see from the picture ,
D0–D7 yes PD register
D8–D13 yes PB register
A0–A5+RESET yes PC register
Now we know the location of the register , How to use it ? Suppose we need to change the pin state
We need to understand three instructions first
DDRx --------- Control the output direction ; // Set the input / output mode of the register pin (0: Input ;1: Output )
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
边栏推荐
- Principle and implementation of MySQL master-slave replication
- 优先级反转与死锁
- arduino获取随机数
- Contiki source code + principle + function + programming + transplantation + drive + network (turn)
- Using LinkedHashMap to realize the caching of an LRU algorithm
- Programmers can make mistakes. Basic pointers and arrays of C language
- Priority inversion and deadlock
- RT-Thread 线程的时间片轮询调度
- Kconfig Kbuild
- I2C总线时序详解
猜你喜欢
Fashion-Gen: The Generative Fashion Dataset and Challenge 论文解读&数据集介绍
IOT system framework learning
电商数据分析--用户行为分析
Correspondence between STM32 model and contex M
锂电池基础知识
uCOS-III 的特点、任务状态、启动
Reno7 60W super flash charging architecture
[esp32 learning-2] esp32 address mapping
Mall project -- day09 -- order module
机器学习--决策树(sklearn)
随机推荐
高通&MTK&麒麟 手机平台USB3.0方案对比
使用LinkedHashMap实现一个LRU算法的缓存
Togglebutton realizes the effect of switching lights
Variable parameter principle of C language function: VA_ start、va_ Arg and VA_ end
arduino JSON数据信息解析
Arm pc=pc+8 is the most understandable explanation
[template] KMP string matching
XML file explanation: what is XML, XML configuration file, XML data file, XML file parsing tutorial
FreeRTOS 任务函数里面的死循环
电商数据分析--薪资预测(线性回归)
Cannot change version of project facet Dynamic Web Module to 2.3.
Several declarations about pointers [C language]
小天才电话手表 Z3工作原理
Unit test - unittest framework
物联网系统框架学习
RT-Thread 线程的时间片轮询调度
RT-Thread API参考手册
Understanding of AMBA, AHB, APB and Axi
互聯網協議詳解
Pytoch implements simple linear regression demo