/****************************************************************************** *Name: myled1.c *Desc: 依次点亮lec0-led7,然后再依次熄灭led7-led0,运行该程序前,应使用insmod i2c.o命令,加载i2c.o驱动模块 *Parameter: *Return: *Author: yoyoba(stuyou@126.com) *Date: 2010-9-17 *Modify: 2010-9-17 ********************************************************************************/
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> #include <linux/i2c.h> #include <linux/fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include "test-8led.h"
/* control code */ #define I2C_SET_DATA_ADDR 0x0601 #define I2C_SET_BUS_CLOCK 0x0602 unsigned char digit[] ={0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6,0xEE,0x3E,0x9C,0x7A,0x9E,0x8E}; //0-F
int main() { int fd,i; char chon=0xff,choff=0x0; printf("this is a example for 8-led,writed by youhaidong!\n"); if((fd=open("/dev/i2c/0",O_RDWR))==-1) /*打开i2c设备*/ { printf("open led device FAILD!\n"); exit(1); } else printf("open led device SUCCESS!\n"); ioctl(fd, I2C_SLAVE_FORCE, ZLG_SLAVE_ADDR); /*设置zlg7290从设备地址*/ ioctl(fd, I2C_SET_BUS_CLOCK, 250*1000); /*设置i2c总线时钟频率为250khz*/ for(i=0;i<8;i++) { ioctl(fd, I2C_SET_DATA_ADDR, REG_Dis0+i); write(fd,&chon,1); /*依次把led0-led8全部点亮*/ sleep(2); } for(i=0;i<8;i++) { ioctl(fd, I2C_SET_DATA_ADDR, REG_Dis7-i); write(fd,&choff,1); /*依次把led7-led0熄灭*/ sleep(2); } printf("led example is over!\n");
return 0; }
|