当前位置:网站首页>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;
}
边栏推荐
- Screen record of the opening ceremony of the Beijing winter olympics 2
- Global and Chinese market of resistivity meter 2022-2028: Research Report on technology, participants, trends, market size and share
- A simple method to prove 1/t Fourier transform
- RTOS in the development of STM32 single chip microcomputer
- Day07 type of mathematical operator automatic conversion relational operator bitwise operator blind date math
- Day01 markdown log entry tips
- Rename directory in C [closed] - renaming a directory in C [closed]
- High end electronic chips help upgrade traditional oil particle monitoring
- [professional literacy] core conferences and periodicals in the field of integrated circuits
- Some errors in configuring the environment
猜你喜欢
Interview catalogue
Application of ultra pure water particle counter in electronic semiconductors
Consul installation
Acwing-宠物小精灵之收服-(多维01背包+正序倒序+两种形式dp求答案)
万字详解八大排序 必读(代码+动图演示)
Latex notes
Altium designer 19.1.18 - clear information generated by measuring distance
UEFI development learning 6 - creation of protocol
Logistic regression: the most basic neural network
Altium Designer 19.1.18 - 清除测量距离产生的信息
随机推荐
Realization of binary relation of discrete mathematics with C language and its properties
C language uses arrays to realize the intersection, union, difference and complement of sets
Record the visual shock of the Winter Olympics and the introduction of the screen 2
GPIO circuit principle of stm32
Global and Chinese market for blood typing 2022-2028: Research Report on technology, participants, trends, market size and share
Consul installation
Day08 ternary operator extension operator character connector symbol priority
LED display equipment records of the opening ceremony of the Beijing Winter Olympics
Create inf module in AMI code
Detailed explanation of C language pointer
How to realize audit trail in particle counter software
Numpy——1.數組的創建
Reasons for rapid wear of conductive slip rings
1-stm32 operation environment construction
Global and Chinese markets for waste treatment air switches 2022-2028: Research Report on technology, participants, trends, market size and share
Latex notes
A simple method to prove 1/t Fourier transform
mysql 盲注常见函数
Global and Chinese market of core pallets 2022-2028: Research Report on technology, participants, trends, market size and share
String judgment