当前位置:网站首页>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
边栏推荐
- Those commonly used tool classes and methods in hutool
- Mall project -- day09 -- order module
- ES6语法总结--下篇(进阶篇 ES6~ES11)
- Détails du Protocole Internet
- Bubble sort [C language]
- RT thread API reference manual
- Cannot change version of project facet Dynamic Web Module to 2.3.
- Pytorch-温度预测
- arduino UNO R3的寄存器写法(1)-----引脚电平状态变化
- 機器學習--線性回歸(sklearn)
猜你喜欢
随机推荐
ESP learning problem record
冒泡排序【C语言】
关键字 inline (内联函数)用法解析【C语言】
C语言函数之可变参数原理:va_start、va_arg及va_end
arduino UNO R3的寄存器写法(1)-----引脚电平状态变化
Those commonly used tool classes and methods in hutool
Contiki source code + principle + function + programming + transplantation + drive + network (turn)
Pytoch implements simple linear regression demo
GNN的第一个简单案例:Cora分类
XML file explanation: what is XML, XML configuration file, XML data file, XML file parsing tutorial
机器学习--决策树(sklearn)
Hutool中那些常用的工具类和方法
B tree and b+ tree of MySQL index implementation
FreeRTOS 任务函数里面的死循环
C language callback function [C language]
I2C bus timing explanation
Kconfig Kbuild
RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED
ESP8266通过arduino IED连接巴法云(TCP创客云)
C语言,log打印文件名、函数名、行号、日期时间











