当前位置:网站首页>Drive LED -- GPIO control

Drive LED -- GPIO control

2022-07-05 07:54:00 Soy sauce;

GPIO Overview of pin operation methods

  1. Hardware knowledge _LED Schematic diagram
  2. Different main chips control GPIO Overview of pin methods
  3. Specific board control GPIO The method of pin is explained in detail
  4. Specific board LED Programming and experiment
  5. Assembly and machine code
  6. Programming knowledge _ Base number
  7. Programming knowledge _ Byte order _ Bit operation
  8. To write C Program control LED
  9. analysis C Internal mechanism of procedure
  10. perfect LED Program
  11. 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

 Insert picture description here
 Insert picture description here

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
 Insert picture description here

Application framework

 Insert picture description here
Compilation result
 Insert picture description here
Makefile file
 Insert picture description here

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;
}


原网站

版权声明
本文为[Soy sauce;]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140548510766.html