The following contains: three files, main.c, gpoi.c, gpio.h
1 /*
2 * Main function
3 */
4
5 #include
6 #include
7
8 void main()
9
10 {
11 P2 = 0;
12 setBit(GPIO_2,3); //GPIO_2 means select P2 port, 3 means select P2.3 bit
13 while(1);
14 }
1 /*
2 *gpio.c file
3 */
4
5
6 #include
7 #include
8
9 void setBit(unsigned char gpio, unsigned char pin)
10 {
11 unsigned char i = 1;//0000 0001
12 i = i<
13 switch(gpio) //Select P0 P1 P2 P3
14 {
15 case 0:
16 P0 |=i;
17 break;
18 case 1:
19 P1 |=i;
20 break;
21 case 2:
22 P2 |=i;
23 break;
24 case 3:
25 P3 |=i;
26 break;
27
28 }
29 }
30 void resetBit(unsigned char gpio, unsigned char pin)
31 {
32 unsigned char i = 1; //0000 0001
33 i = i<
34 i = ~i;//reverse 1111 1011
35 switch (gpio)
36 {
37 case 0:
38 P0 &=i; //Bitwise AND operation requires two 1s to be 1 1111 1011 So the third bit is definitely 0, output low level
39 break;
40 case 1:
41 P1 &=i;
42 break;
43 case 2:
44 P2 &=i;
45 break;
46 case 3:
47 P3 &=i;
48 break;
49
50 }
51 }
1 /*
2 *gpio.h file
3 */
4
5 #ifndef _GPIO_H_
6 #define _GPIO_H_
7 // Enumeration 0 1 2 3 represents P0 P2 P3 P4
8 enum gpio{
9 GPIO_0 = 0, GPIO_1 = 1,
10 GPIO_2 = 2, GPIO_3 = 3
11 };
12 /*
13 *Set a pin to high level
14 *@param gpio: enumeration constant gpio
15 *@param pin: the pin number corresponding to each IO register
16 */
17
18 void etBit(
19 unsigned char gpio,
20 unsigned char pin);
twenty one
22 void resetBit(
23 unsigned char gpio,
24 unsigned char pin);
25 #endif
Previous article:Flashing LED lights
Next article:Customize the reg52.h header file (key knowledge points of microcontroller learning)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- MSP430F5529 IO port pin interrupt study notes
- Circuit-level electrostatic protection design techniques and ESD protection methods
- [ESK32-360 Review] +TFT screen display function and expansion (3)
- Can the 7805 and 1117-5 power supplies be used within ±0.05?
- CC3200 Kit OURS-SDK-WFB_Exploration 4——FreeRTOS Run
- The microcontroller outputs PWM wave to control the load supply voltage 0-12V adjustable
- 【Insights】If you don’t plant flowers in your heart, weeds will grow
- [ESP32-Korvo Review] 1: ESP32-Korvo Audio Development Board Hardware Circuit Connection
- I would like to ask which manufacturers produce unipolar TMR tunneling effect switches. I only found MDT, and Magne does not have unipolar ones.
- Altium16.1 manufacturing output IPC-2581 and odb++ formats are not working