⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test-8led.c

📁 深圳英培特EduKit-III实验箱实验程序。一共有10多个
💻 C
字号:
/*********************************************************************
* File:		test-8led.c
* Author:	
* Desc:		
* History:	
*********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <linux/i2c.h>
#include <linux/fcntl.h>
#include "zlg7290.h"


/* control code */
#define I2C_SET_DATA_ADDR	0x0601
#define I2C_SET_BUS_CLOCK	0x0602


unsigned char digit[] = {
/*0*/(SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F),
/*1*/(SEG_B | SEG_C),
/*2*/(SEG_A | SEG_B | SEG_D | SEG_E | SEG_G),
/*3*/(SEG_A | SEG_B | SEG_C | SEG_D | SEG_G),
/*4*/(SEG_B | SEG_C | SEG_F | SEG_G),
/*5*/(SEG_A | SEG_C | SEG_D | SEG_F | SEG_G),
/*6*/(SEG_A | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G),
/*7*/(SEG_A | SEG_B | SEG_C | SEG_F),
/*8*/(SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G),
/*9*/(SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G)
};


int main(int argc, char** argv)
{
	int i, j, fd, idx;
	char ch;

	/* open device */
	fd = open("/dev/i2c0", O_RDWR);
	/* set zlg7290 slave address */
	ioctl(fd, I2C_SLAVE_FORCE, ZLG_SLAVE_ADDR);
	/* set i2c bus clock 16KHz */
	ioctl(fd, I2C_SET_BUS_CLOCK, 16*1000);

	/* display all segment */
	ch = 0xff;
	for(j=0; j<8; j++)
	{
		/* zlg7290 inner register access address */
		ioctl(fd, I2C_SET_DATA_ADDR, REG_Dis7-j);
		write(fd, &ch, 1);
	}
	sleep(2);

	/* display digit */
	for(i=0; i<10; i++)
	{
		for(j=0; j<8; j++)
		{
			idx = (i + j + 1) % sizeof(digit);
			/* zlg7290 inner register access address */
			ioctl(fd, I2C_SET_DATA_ADDR, REG_Dis7-j);
			write(fd, &digit[idx], 1);
		}
		sleep(1);
	}
	sleep(2);

	/* turn off all segment */
	ch = 0x00;
	for(j=0; j<8; j++)
	{
		/* zlg7290 inner register access address */
		ioctl(fd, I2C_SET_DATA_ADDR, REG_Dis7-j);
		write(fd, &ch, 1);
	}
	
	close(fd);

	return 0;
}

⌨️ 快捷键说明

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