Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

06-GPIO experiment

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

  GPIO (General Purpose I Ports O Ports) means universal input / output port, which, in popular terms, refers to pins through which you can output high and low levels or read into the state of the pins whether the ── is high or low.

  Samsung S3C2440, which has 130 I-amp O ports, is divided into nine A-J groups. You can set registers to determine whether a pin is used for input, output or special functions. Here we introduce the simple use of GPIO through four experiments.

1. Light up the LED lamp through assembly language

  first needs to look at the schematic diagram to know the relationship between LED and chip pins.

   

As can be known from the schematic diagram, the 2440 pin is connected with the LED lamp as the output pin. In order to make the LED lamp light, configure the relevant register as the output pin, and the LED lamp can be lit by outputting the pin at a low level. Look at the 2440 chip manual, the GPB group pin control register address is: 0x56000010, the data register address is: 0x56000014. The assembly code that lights up the LED1 is:

.text.global _ start_start: LDR R0Magneol 0x56000010 @ R0 is set to the GPBCON register. This register is used to select the function of each pin of port B: output, input, or other MOV R1 STR 0x00000400 STR R1, [R0] @ sets GPB5 as the output, bit [11:10] = 0b01 LDR R0memery 0x56000014 @ R0 as the GPBDAT register. This register is used to read / write port B pin data MOV R1 < 0x00000000 @ this value is changed to 0x00000020, so that LED1 can turn off STR R1, [R0] @ GPB5 output 0Led1 lights up MAIN_LOOP: B MAIN_LOOP

Its Makefile is:

Led_on.bin: led_on.S arm-linux-gcc-g-c-o led_on.o led_on.S arm-linux-ld-Ttext 0x0000000-g led_on.o-o led_on_elf arm-linux-objcopy-O binary-S led_on_elf led_on.binclean: rm- f led_on.bin led_on_elf * .o

After compiling and downloading to the TQ2440 development board, the effect: led_1 lights up

2. Lighting the LED lamp by C language

When   uses C language to light LED lamp, it first needs hardware-related initialization and software-related initialization. Hardware related are: turn off the watchdog, initialize the clock, initialize the SDRAM, etc., but for the experiment of lighting LED lights, you only need to turn off the watchdog; in terms of software, you need to set the return address, that is, set the stack, call the main function and so on. First of all, the assembly code part:

.text.global _ start_start: ldr R0, = 0x53000000 @ WATCHDOG register address mov R1, # 0x0 str R1, [R0] @ write 0, disable WATCHDOG, otherwise CPU will keep restarting ldr sp, = 1024room4 @ set stack Note: it cannot be greater than 4k, because there is only 4K memory available now. The code in the 4K bl main flash will be moved to the internal ram after the reset. This ram only has 4K bl main @ to call the main function halt_loop: B halt_loop in the C program.

C language part:

# define GPBCON (* (volatile unsigned long *) 0x56000010) # define GPBDAT (* (volatile unsigned long *) 0x56000014) int main () {GPBCON = 0x00000400; / / set GPB5 as the output, bit [11:10] = 0b01 GPBDAT = 0x0000000000; / / GPB5 output 0PowerLED1 lights up return 0;}

The Makefile code is:

Led_on_c.bin: crt0.S led_on_c.c arm-linux-gcc-g-c-o crt0.o crt0.S arm-linux-gcc-g-c-o led_on_c.o led_on_c.c arm-linux-ld-Ttext 0x0000000-g crt0.o led_on_c.o-o led_on_c_elf arm-linux-objcopy-O binary-S led_on_c_elf led_on_c.bin arm- Linux-objdump-D-m arm led_on_c_elf > led_on_c.disclean: rm-f led_on_c.dis led_on_c.bin led_on_c_elf * .o

After compiling and downloading to the TQ2440 development board, the effect: led_1 lights up

3. Control the LED light by pressing the button.

When   controls the LED lamp through the key, first look at the schematic diagram to understand the pin relationship between the key and the 2440 chip.

  uses assembly to complete the relevant initialization, jumps to the main function, and the C program part turns the LED light on and off by pressing the key.

Assembly code:

.text.global _ start_start: ldr R0, = 0x53000000 @ WATCHDOG register address mov R1, # 0x0 str R1, [R0] @ write 0, disable WATCHDOG, otherwise CPU will keep restarting ldr sp, = 1024room4 @ set stack Note: it cannot be greater than 4k, because there is only 4K memory available now. The code in the 4K precinct nand flash will be moved to the internal ram after reset. For this ram, only 4K bl main @ calls the main function halt_loop in the C program: B halt_loopC language code: # define GPFCON (* (volatile unsigned long *) 0x56000050) # define GPFDAT (* (volatile unsigned long *) 0x56000054) # define GPBCON (* (volatile unsigned long *) 0x56000010) # define GPBDAT (* (volatile unsigned long *) 0x56000014) / * * LED1,LED2 LED3 and LED4 correspond to GPB5, GPB6, GPB7, GPB8 * / # define GPB5_out (1

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report