ARM bare metal - FS2410 button control LED light (query method)

Publisher:数字梦行Latest update time:2018-12-18 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

Keywords:ARM Reference address:ARM bare metal - FS2410 button control LED light (query method)

Previous article:S3C2410A GPIO introduction and application
Next article:S3C2410 (ARM9) startup method

Recommended ReadingLatest update time:2024-11-16 12:03

Systematic Study of ARM Part 1--Introduction to ARM
FS4412 is located in Cortex-A9          1, 3, 8, 7: 1. 3 states of ARM processor       The ARM processor is running that instruction and is in that state.       (1) ARM state --- running ARM instructions       (2) Thumber state --- Thumber instructions       (3) Java status --- Java bytecode 2. ARM has 8 basic
[Microcontroller]
Introduction to ARM application analysis
ARM Application Analysis 1. Industrial control field: As a 32-bit RISC architecture, microcontroller chips based on ARM core not only occupy most of the market share of high-end microcontroller market, but also gradually expand to the application field of low-end microcontrollers. The low power consumption and high
[Microcontroller]
GNU-ARM Assembly
Part 1 ARM assembly syntax under Linux Although it is convenient to write programs in C or C++ under Linux, the assembly source program is used for the most basic initialization of the system, such as initializing the stack pointer, setting up the page table, operating the ARM coprocessor, etc. After the initializatio
[Microcontroller]
ARM disassembly learning
In the bin file, there are machine instructions one by one, each instruction is 4 bytes. Open a .s file in ADS and select project- disassemble You can see the assembled machine code The assembly code is as follows (a routine in ADS, ARM ADS v1_2 Examples as marmex.s): AREA ARMex, CODE, READONLY ; name this block of
[Microcontroller]
ARM disassembly learning
Address remapping for ARM chips
Mapping means one-to-one correspondence. Remapping means reallocating this one-to-one correspondence. We can think of the memory as a black box with output and input ports. As shown in the figure below, the input is the address, and the output is the data stored at the corresponding address. Of course, this black box
[Microcontroller]
Address remapping for ARM chips
ARM instruction coprocessor processes instructions
ARM supports 16 coprocessors. During program execution, each coprocessor ignores instructions belonging to the ARM processor and other coprocessors. When a coprocessor hardware cannot execute its coprocessor instructions, an undefined exception interrupt will be generated. In the exception interrupt handler, the opera
[Microcontroller]
Foreign media said that Arm will set up an AI chip department and strive to create a prototype product by 2025
On May 13, according to foreign media reports, the vigorous development of artificial intelligence, especially generative artificial intelligence, has brought new development opportunities to the chip field. Nvidia, which started its layout in the field of artificial intelligence earlier, has occupied most of the ma
[Semiconductor design/manufacturing]
A Design Scheme of Audio Processing System Based on ARM+DSP
1 Introduction With the rapid development of computer technology, electronic technology and communication technology, audio processing technology has also been widely used in many fields, such as mobile phones and IP phones in the communication field, MP3 and CD players in consumer electronics, and speech recognition
[Embedded]
A Design Scheme of Audio Processing System Based on ARM+DSP
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号