ARM9嵌入式系统,用C语言编写7段LED数码管

2025-03-29 05:51:10
推荐回答(1个)
回答1:

//显示123456的程序,这只是整个程序片段
#include "led_ioctl.h"
int Led_123()
{
int led_fd,count;
char ret[7]; //数组ret[i] 存放送LED显示的数据

//【打开LED设备】
led_fd = open("/dev/led",O_RDWR);
if (led_fd <= 0){
printf("open led device error\n");
return 0;
}//if

ret[6] = 0xcf; //初始化数组数值为 6.
ret[5] = 0x4f; //初始化数组数值为 5.
ret[4] = 0x53; //初始化数组数值为 4.
ret[3] = 0x5d; //初始化数组数值为 3.
ret[2] = 0x9d; //初始化数组数值为 2.
ret[1] = 0x50; //初始化数组数值为 1.

ioctl(led_fd,IOCTRL_LED_1);
count = write(led_fd,ret+1,1);
ioctl(led_fd,IOCTRL_LED_2);
count = write(led_fd,ret+2,1);
ioctl(led_fd,IOCTRL_LED_3);
count = write(led_fd,ret+3,1);
ioctl(led_fd,IOCTRL_LED_4);
count = write(led_fd,ret+4,1);
ioctl(led_fd,IOCTRL_LED_5);
count = write(led_fd,ret+5,1);
ioctl(led_fd,IOCTRL_LED_6);
count = write(led_fd,ret+6,1);

return 0;
}