[Embedded Linux] (Step 6): Use the eclipse integrated development environment to develop the first embedded Linux program and test the LED driver.

Source: Internet
Author: User
Tags usleep

 

There is almost no difference between using eclipse to develop embedded Linux programs and PC Linux programs. It is easy to use the integrated development environment of the eclipse GUI for easy learning. Here we will teach you how to develop the first embedded Linux program, the program function is to test the LED Driver written last time.

1. Create a project

Enter the project name, select the executable program, and select cross GCC. Next, enter the path of arm-Linux-GCC according to your actual situation.

Click Finish.

2. Enter the code and compile it.

The code is simple, just an instance

/*************************************** **************************************** * ********************************** File Name: main. C * main functions: LED test * Author: different spirit yuan (cp1300@139.com) * Creation Time: 2012 11:52:59 * last modification time: 2012 11:52:59 * Description: Using ok6410 Development Board, test your own LED driver ********************************** **************************************** **************************************/# include <stdio. h> # include <stdlib. h> # include <unistd. h> # Inc Lude <fcntl. h> # include <sys/IOCTL. h> # include <unistd. h> int main (void) {int FD; int retval; unsigned char led; // LED test printf ("LED test... \ n "); FD = open ("/dev/ok6410_led ", o_rdwr); // open led. Note: it is the driver module name, not the driver file name if (FD =-1) {printf ("Open led error! \ N "); exit (-1);} else {printf (" Open led OK! \ N ") ;}while (1) {for (retval = 0; retval <4; retval ++) {led = 1 <retval; led = ~ Led; write (FD, & LED, sizeof (unsigned char) 1); // read (FD, & LED, sizeof (unsigned char) 1 )); // printf ("led = 0x % x \ n", LED); usleep (1000*100); // 100 ms} For (retval = 2; retval> 0; retval --) {led = 1 <retval; led = ~ Led; write (FD, & LED, sizeof (unsigned char) 1); // read (FD, & LED, sizeof (unsigned char) 1 )); // printf ("led = 0x % x \ n", LED); usleep (1000*100); // 100 ms} Close (FD ); exit (0 );}

After the code is compiled, it is usually saved first. If it is set to automatically save before compilation, press Ctrl + B. After compilation, relevant executable programs are generated, however, this program can only be executed on ARM Linux and cannot be executed on PC.

3. Execute the program

Copy the program to the Development Board for execution. If NFS is mounted, you can run the program directly. The running result is as follows. Of course, you can see that the light on the Development Board is running back and forth...

Sometimes the program cannot run. You need to add executable attributes.

Run: chmod + x xxxx is the name of the compiled executable program.

Related Article

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.