1. GPIO Description
GPIO (General Purpose I/O ports) is a general purpose input/output port. In practical applications, whether it is connecting an LCD, connecting a keyboard, controlling a running light, etc., it is inseparable from the operation of I/O. It can be said that GPIO operation is the basis of all hardware operations.
S3C2440 has 130 I/O ports, divided into nine groups: GPA, GPB, ..., GPJ. We can operate these IOs through registers. S3C2440 has three registers: GPxCON, GPxDAT, and GPxUP. GPxCON is used to select pin functions; GPxDAT is used to read/write pin data; GPxUp is used to determine whether to use internal pull-up resistors. It should be noted that Group A does not have a GPAUP register, that is, Group A I/O ports do not have a pull-up resistor selection function
1、GPxCON
The GPxCON of the A group I/O port is special. Each bit in GPACON corresponds to a pin (a total of 23 pins). When a bit is set to 0, the corresponding pin is an output pin. Otherwise, the corresponding pin is an address line or used for address control. In this case, GPADAT is useless.
The I/O of Group B to Group J are identical in register operation. Every two bits in GPxCON control one pin: 00 indicates input, 01 indicates output, 10 indicates special function, and 11 is reserved.
2、GPxDAT
GPxDAT is used to read/write pin data: when the pin is set to output, writing the corresponding bit of its register can make the pin output high or low level; when the pin is set to input, reading the corresponding bit of this register can determine whether the level state of the pin is high or low.
3、GPxUP
GPxUP is used to set whether the corresponding pin uses a pull-up resistor. When a bit is 0, a pull-up resistor is used; when a bit is 1, a pull-up resistor is not used.
2. Development Environment
IDE environment: ADS1.2
Development board: TX2440
Hardware wiring diagram:
LED1---GPF0, common anode connection, to light up the LED, just give the corresponding low level.
LED2---GPF1
LED3---GPF2
LED4---GPF3
3. Source code and analysis
//======================================================================
// Project name: LED.mcp
// Function description: Use GPIO to control four LEDs
// IDE environment: ADS v1.2
// Component file: main.c
//======================================================================
//====================================================
// Include header file area
//====================================================
#include "2440addr.h"
#include "2440lib.h"
#include "option.h"
#include "def.h"
#include "uart.h"
#define LED1ON 0xFE //LED1 lighting value is 0xFE (low level lighting)
#define LED2ON (LED1ON<<1) //LED2 lighting value is LED1 shifted left by 1 bit
#define LED3ON (LED1ON<<2) //LED3 light value is LED2 shifted left by 1 bit
#define LED4ON (LED1ON<<3) //LED4 lighting value is LED3 shifted left by 1 bit
extern unsigned int PCLK;
void usDelay(unsigned long time)
{
U32 i,j;
for (i = time; i > 0; i--)
for (j = 50; j > 0; j--);
}
void Main(void)
{
rGPFCON = (rGPFCON | 0xFFFF) & 0xFFFFFF55; //GPF0--GPF3 are set to output
rGPFUP = 0xFFFF;
rGPFDAT = 0x0F; //GPF lower 4 bits are initialized to 1
while(1)
{
rGPFDAT = LED1ON; //Turn on LED1
usDelay(10000);
rGPFDAT = LED2ON; //Turn on LED2
usDelay(10000);
rGPFDAT = LED3ON; //Turn on LED3
usDelay(10000);
rGPFDAT = LED4ON; //Turn on LED4
usDelay(10000);
}
}
Test result: LED1--4 light up in sequence, all go out, and then light up in sequence.
Previous article:TX2440 Bare Metal Clock-PWM
Next article:s3c2440 NAND and NOR boot methods detailed explanation + personal verification
Recommended ReadingLatest update time:2024-11-16 09:00
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Problems encountered in debugging the Southchip SC8721 high-efficiency synchronous buck-boost converter
- (A-Current signal detection device) Chongqing "TI Cup" Award_Chongqing University of Posts and Telecommunications
- This appears and I can't choose it. It's grayed out.
- 【AT-START-F403A Review】3. Try USB Composite_Device
- Communication system cannot do without filter series 2
- [Sipeed LicheeRV 86 Panel Review] 10. LVGL Timer
- Today at 10:00 AM, live broadcast with prizes: Protecting clean water sources - ADI water quality monitoring solutions
- [Ateli Development Board AT32F421 Review] + Unboxing and Learning Plan
- What are risc-v chips?
- sensortile box source code