test2.c

来自「基于嵌入式Linux系统的led驱动程序开发源程序及详细文档」· C语言 代码 · 共 35 行

C
35
字号
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

int main()
{
	int fd;
	int i;
	char drv_buf[8][2] = {0x60,0x00,0x61,0x01,0x62,0x02,0x63,0x03,0x64,0x040,0x65,0x05,0x66,0x06,0x67,0x07};
	char drv_buf1[8][2] = {0x60,0x1f,0x61,0x1f,0x62,0x1f,0x63,0x1f,0x64,0x1f,0x65,0x1f,0x66,0x1f,0x67,0x1f};
	char drv_buf2[16][2]= {0x60,0xc0,0x60,0x1f,0x61,0xc1,0x61,0x1f,0x62,0xc2,0x62,0x1f,0x63,0xc3,0x63,0x1f,
		                   0x64,0xc4,0x64,0x1f,0x65, 0xc5,0x65,0x1f,0x66,0xc6,0x66,0x1f,0x67,0xc7,0x67,0x1f};

	fd=open("/dev/led2",O_RDWR);
	if(fd < 0){
		printf("####DEMO device open fail####\n");
		return (-1);
	}

 for(i = 0;i < 8; i++)
	 write(fd, drv_buf[i], 2);
 sleep(1);
 for(i = 0;i < 8; i++)
	 write(fd, drv_buf1[i], 2);
 sleep(1);
 for(i = 0;i < 8; i++)
	{
	 write(fd, drv_buf2[2*i], 2);
	 sleep(1);
	 write(fd, drv_buf2[2*i+1], 2);
	}    
	close(fd);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?