当前位置:网站首页>Drive LED -- GPIO control
Drive LED -- GPIO control
2022-07-05 07:54:00 【Soy sauce;】
GPIO Overview of pin operation methods
- Hardware knowledge _LED Schematic diagram
- Different main chips control GPIO Overview of pin methods
- Specific board control GPIO The method of pin is explained in detail
- Specific board LED Programming and experiment
- Assembly and machine code
- Programming knowledge _ Base number
- Programming knowledge _ Byte order _ Bit operation
- To write C Program control LED
- analysis C Internal mechanism of procedure
- perfect LED Program
- Write key control LED The program
GPIO: General-purpose input/output, Universal input and output port
1.GPIO Module general structure :
a. There are multiple groups GPIO, There are multiple in each group GPIO
b. Can make : Power Supply / The clock
c. Pattern (Mode): Pins can be used for GPIO Or other functions
d. Direction : Pin Mode Set to GPIO when , You can continue to set it to be the output pin , Or input pin
e. The number : For output pins , You can set the register to output high 、 Low level
For input pins , The current level of the pin can be obtained by reading the register
2. Control principle
3.GPIO Register operation - Program configuration process :
The principle should not affect other bits
The process
Can make , Working mode , Input and output direction , High and low level
a. Chip manuals generally have relevant chapters , To introduce :power/clock
You can set the corresponding register to enable a certain GPIO modular (Module)
Some chips GPIO There is no enabling start , That is, it is always enabled
b. One pin can be used for GPIO、 A serial port 、USB Or other functions ,
There is a corresponding register to select the function of the pin
c. For already set to GPIO Function pin , There is a direction register to set its direction : Output 、 Input
d. For already set to GPIO Function pin , There are data registers for writing 、 Read pin level status
GPIO The register of 2 Common operation methods :
principle : Cannot affect other bits
a. Direct reading and writing : read out 、 Modify corresponding bit 、 write in
To set up bit n:
val = data_reg;
val = val | (1<<n);
data_reg = val;
To clear away bit n:
val = data_reg;
val = val & ~(1<<n);
data_reg = val;
b.set-and-clear protocol:
set_reg, clr_reg, data_reg The three registers correspond to the same physical register ,
To set up bit n:set_reg = (1<<n); Default No 0 Location 1, And then move
To clear away bit n:clr_reg = (1<<n); Default No 0 Location 0, And then move
Access register mode
Application framework
Compilation result
Makefile file
4.GPIO Other functions of : debounce 、 interrupt 、 Wake up the :
In the following chapters
Code
void delay(volatile int d)
{
while(d--);
}
int main(void)
{
volatile unsigned int *pReg;
/* Must be added volatile, Prevent variables from being optimized */
/* Can make GPIO5: Default enable */
/* hold GPIO5_3 Set to GPIO function */
pReg = (volatile unsigned int *)(0x02290000 + 0x14);
*pReg |= (0x5);
/* hold GPIO5_3 Set to output pin */
pReg = (volatile unsigned int *)(0x020AC004);
*pReg |= (1<<3);// Shift left and right for one digit , Just write more directly
pReg = (volatile unsigned int *)(0x020AC000);
while (1)
{
/* Set up GPIO5_3 Output 1 */
*pReg |= (1<<3);
delay(1000000);
/* Set up GPIO5_3 Output 0 */
*pReg &= ~(1<<3);
delay(1000000);
}
return 0;
}
边栏推荐
- A series of problems in offline installation of automated test environment (ride)
- Realization of binary relation of discrete mathematics with C language and its properties
- 生产中影响滑环质量的因素
- How to excavate and research ideas from the paper
- . Net service governance flow limiting middleware -fireflysoft RateLimit
- Calibre garbled
- Rename directory in C [closed] - renaming a directory in C [closed]
- Embedded AI intelligent technology liquid particle counter
- The printer encountered an abnormal configuration problem 0x8007007e (win10)
- Baiwen 7-day smart home learning experience of Internet of things
猜你喜欢
Can't find real-time chat software? Recommend to you what e-commerce enterprises are using!
Package ‘*****‘ has no installation candidate
Altium designer 19.1.18 - change the transparency of copper laying
Extended application of single chip microcomputer-06 independent key
Altium Designer 19.1.18 - 更改铺铜的透明度
High end electronic chips help upgrade traditional oil particle monitoring
MySql——存储引擎
Use of orbbec Astra depth camera of OBI Zhongguang in ROS melody
Scm-05 basis of independent keyboard
Create inf module in AMI code
随机推荐
The printer encountered an abnormal configuration problem 0x8007007e (win10)
Application of ultra pure water particle counter in electronic semiconductors
Detailed explanation of C language pointer
Global and Chinese market of rammers 2022-2028: Research Report on technology, participants, trends, market size and share
Numpy——1.數組的創建
Acwing-宠物小精灵之收服-(多维01背包+正序倒序+两种形式dp求答案)
"Source code interpretation" famous programmer TJ's only library
Opendrive arc drawing script
[popular science] some interesting things that I don't know whether they are useful or not
A simple method to prove 1/t Fourier transform
Beijing Winter Olympics opening ceremony display equipment record 3
QT excellent articles
RTOS in the development of STM32 single chip microcomputer
导电滑环磨损快的原因
找不到实时聊天软件?给你推荐电商企业都在用的!
Batch modify the txt file code to UTF-8 (notepad++)
LED display equipment records of the opening ceremony of the Beijing Winter Olympics
Logistic regression: the most basic neural network
Oracle triggers and packages
solver. Learning notes of prototxt file parameters