Embedded Linux Learning Primer: Control LED Lights

Source: Internet
Author: User
Tags volatile

Keep track of your Linux learning process so that you can keep going

1. Schematic analysis:

Nled_1, Nled_2, Nled_4, to the low level of the corresponding LED light, high-level corresponding to the LED light off,

s3c2440 chip Gpf4-gpf6 corresponds to Nled_1, Nled_2, Nled_4,

So the code inside the Operation GPF4-GPF6 can control led light off.

2. Know things before writing code

First step: Configure GPF0-GPF4 as output function

Step two: Control the GPF0-GPF4 output low level

3. Write code

1 . Text2 . Global _start3 _start:4 LDR R0, =0x53000000 @ Watchdog register address5             movR1, #0x06             StrR1, [r0] @ Write 0, prohibit watchdog, otherwise the CPU will continue to restart7             8Ldr sp, =1024x768*4@ set Stack, note: cannot be greater than 4k, because memory available now is only 4 K9 code in NAND Flash is moved to internal RAM after reset, this RAM is only 4 KTen BL Main @ Call the main function in C program One Halt_loop: Ab halt_loop

Refer to the Assembly section of Vedon video mimic writing, mainly for calling C language programs, preparing conditions

1 #defineGpfcon (* (volatile unsigned long *) 0x56000050)2 #defineGpfdat (* (volatile unsigned long *) 0x56000054)3 4 5 intMainvoid)6 {7UnsignedLongi =0;8 9Gpfcon =0x00001500;//set the GPF4 GPF5 GPF6 to outputTen  One      while(1) A     { -  -Gpfdat =0x00000060;//control GPF4 output low level, LED1 bright the          for(i=0; i<30000; i++);//Delay -  -Gpfdat =0x00000050;//control GPF5 output low level, LED2 bright -          for(i=0; i<30000; i++);  +  -Gpfdat =0x00000030;//control GPF6 output low level, LED4 bright +          for(i=0; i<30000; i++); A     } at      -     return 0; -}

4, compiling code, burning execution

Using GCC compilation in a Linux environment, as well as video learning to write makefile

led_test:main.c start. S arm-linux-gcc-c start. S-o start.o arm-linux-gcc-c main.c-o main.o arm0x0000000 start.o main.o-o led_test_el F arm-linux-objcopy-o binary-S led_test_elf led_test.bin arm-linux-objdump-d-m arm led_test_elf >
   
    -F *.o led_test.bin led_test_elf Led_test.dis
   

The generated led_test.bin burned to the board, observe the phenomenon, according to the expected running lights go up!

Embedded Linux Learning Primer: Control LED Lights

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.