1. Development Environment
1. Hardware platform: FS2410 (s3c2410)
2. Host: Ubuntu 10.10
2. Hardware schematics (LEDs and buttons)
1. Schematic diagram of LED lamp:
2. Schematic diagram of the buttons:
Wiring resources for buttons:
KSCAN0 -> GPE11 KSCAN1 -> GPG6 KSCAN2 -> GPE13 KSCAN3 -> GPG2
EINT0 -> GPF0 EINT2 -> GPF2 EINT11 -> GPG3 EINT19 -> GPG11
3. Main principles of the procedure:
It mainly involves the four keys K1, K2, K3, and K4. It is necessary to use the query method to determine which key is pressed. Therefore, EINT11 and EINT19 are set as input for reading, and KSCAN0, KSCAN1, and KSACAN2 are set as output, and are set to 0, 1, 1 or 1, 0, 1 or 1, 1, 0 respectively. This can be used to distinguish which key among K1, K2, and K3 is pressed. For example, let KSCAN0~2 = 011 first, then when K1 is pressed, EINT19 will become a low level. At this time, when K2 is pressed, EINT19 will not become low, so that keys K1 and K2 are distinguished. The principle of distinguishing other keys is the same.
4. Register Configuration
1. Configuration of LED registers: (set GPF4-GPF7 as output)
2. The key aspects involve register configuration (setting related register input and output):
5. Detailed code of the program:
led_key.c: (s3c2410.h header file can be found in the keil directory, renamed from s3c2440.h)
#include "s3c2410.h"
void delay(long long max) //delay function
{
for(; max > 0; max--);
}
int main(void)
{
int read_value;
GPFCON = GPFCON & (~(0xff) << 8) | (0x55 << 8); //Set 4 LEDs as output (GPF4-GPF7 output)
GPFDAT |= (0xf << 4); //Turn off all 4 lights first
GPGCON = (0 << 7) | (1 << 12) | (0 << 23); //GPG3, GPG11 input, GPG6, GPE11, GPE13 output
GPECON = (1 << 22) | (1 << 26);
while(1)
{
GPEDAT &= (0 << 11); //Set GPE11 to 0 and GPE13 and GPG6 to 1
GPEDAT |= (1 << 13);
GPGDAT |= (1 << 6);
read_value = GPGDAT & 0x808; //Read the input values of GPG11 and GPG3
if((read_value & 0x800) == 0) //Judge whether the GPG11 input is 0, and thus whether the K1 key is pressed
{
read_value = 0x800;
delay(200000); //key debounce
if((read_value &= GPGDAT) == 0)
{
if((GPFDAT & (1 << 4)) == 0) //Judge whether D12 is on, if it is on, turn it off, otherwise
GPFDAT |= (0x1 << 4);
else
GPFDAT &= (0xe << 4);
}
}
else
{
if((read_value & 0x8) == 0) //Judge whether the value of GPG3 input is 0, and whether the K4 key is pressed
{
read_value = 0x8;
delay(200000); //key debounce
if((read_value &= GPGDAT) == 0)
{
if((GPFDAT & (0x8 << 4)) == 0) //Judge whether D9 is on, if so, turn it off, otherwise
GPFDAT |= (0x8 << 4);
else
GPFDAT &= (0x7 << 4);
}
}
}
GPEDAT |= (1 << 11); //Set GPE11 and GPE13 to 1 and GPG6 to 0
GPEDAT |= (1 << 13);
GPGDAT &= (0 << 6);
read_value = GPGDAT & (0x8 << 8); //Read the value of GPG11
if(read_value == 0) //Judge whether GPG11 input is 0, and thus judge whether K2 is pressed
{
read_value = 0x800;
delay(200000); //key debounce
if((read_value &= GPGDAT) == 0)
{
if((GPFDAT & (0x2 << 4)) == 0) //Judge whether D11 is on, if it is on, turn it off, otherwise
GPFDAT |= (0x2 << 4);
else
GPFDAT &= (0xd << 4);
}
}
GPEDAT &= (0 << 13); //Set GPE13 to 0 and GPE11 and GPG6 to 1
GPEDAT |= (1 << 11);
GPGDAT |= (1 << 6);
read_value = GPGDAT & 0x800; //Read the value of GPG11
if(read_value == 0) //Judge whether GPG11 is 0 to determine whether the K3 key is pressed
{
read_value = 0x800;
delay(200000); //Debounce the button and delay for a while
if((read_value &= GPGDAT) == 0)
{
if((GPFDAT & (0x4 << 4)) == 0) //Judge whether D10 is on, if it is on, turn it off, otherwise
GPFDAT |= (0x4 << 4);
else
GPFDAT &= (0xb << 4);
}
}
}
return 0;
}
Makefile:
led.bin: start.S led_key.c
arm-none-linux-gnueabi-gcc -c start.S -o start.o
arm-none-linux-gnueabi-gcc -c led_key.c -o led_key.o
arm-none-linux-gnueabi-ld -Ttext 0x30008000 start.o led_key.o -o led_key
arm-none-linux-gnueabi-objcopy -O binary -S led_key led_key.bin
clean:
rm -f *.o led_key.bin
Startup file start.S:
.text
.global _start
_start:
#define WATCHDOG 0x53000000
ldr r0, =WATCHDOG
mov r1, #0
str r1, [r0]
ldr sp, =1024*4
bl main
loop:
b loop
Then execute the following command on the uboot of the development board:
tftp 30008000 led_key.bin
go 30008000
Previous article:S3C2410A GPIO introduction and application
Next article:S3C2410 (ARM9) startup method
Recommended ReadingLatest update time:2024-11-16 12:03
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
- Rethinking 5G
- MSP430 Program Library--Use of DAC12
- Precision rectification is not precise
- Micron invites you to post window decorations and receive benefits during the Lantern Festival
- The most comprehensive article on ultra-wideband.
- How to calculate the frequency of this oscillator circuit
- [Job seeking] Xia Xian; Bachelor degree, 35 years old, graduated in Mechanical and Electrical Engineering; Looking for a job as a Mechanical Engineer
- Regarding proteus simulation, it should be considered a circuit problem
- cadence ic design teaching
- TMS320C6748 DSP Development Kit