// Led. c
# Include <stdio. h>
# Include <stdlib. h>
# Include <unistd. h>
# Include <sys/IOCTL. h>
Int main (INT argc, char ** argv)
{
Int on;
Int led_no;
Int FD;
/* Check the two parameters of LED control. Exit if no parameter is input. */
If (argc! = 3 | sscanf (argv [1], "% d", & led_no )! = 1 | sscanf (argv [2], "% d", & on )! = 1 | on <0 | on> 1
| Led_no <0 | led_no> 3)
{
Fprintf (stderr, "Usage: LEDs led_no 0 | 1/N ");
Exit (1 );
}
/* Open the/dev/LEDs Device File */
FD = open ("/dev/LEDs", 0 );
If (FD <0)
{
Perror ("open device LEDs ");
Exit (1 );
}
/* Control the led by calling IOCTL and input parameters */
IOCTL (FD, on, led_no );
/* Close the device handle */
Close (FD );
Return 0;
}
The above is the source code.
The command for compiling in a Linux virtual machine is: Arm-Linux-gcc-O led. c
After compilation, It is uploaded to the target board through FTP.
At this time, you can use a Super Terminal or telnet to the console on the target board to view the file led.
The LED cannot be executed. The command chmod A + x LED is used to run the LED file.
According to the source program, we can use the LEDs led_no 0 | 1 method to start the application to control the LED lighting and quenching.
Led_no is the led to be operated (can be 0, 1, 2, 3), 0 and 1 respectively indicate to close and light up.
# Led 2 1
Will light up led3
It is worth noting that the source generation has been downloaded to the target board and the application is started with an additional sample.