📄 saa1064_x86.c.txt
字号:
/*
* SAA1064_x86 v1.0 11/05/01
* www.embeddedlinuxinterfacing.com
*
* The original location of this code is
* http://www.embeddedlinuxinterfacing.com/chapters/10/
*
* Copyright (C) 2001 by Craig Hollabaugh
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* SAA1064_x86
* This program demonstrates communication with a SAA1064 I2C LED
* display driver using the i2c-pport x86 parallel port device driver.
*
* For more Linux I2C information, visit the lm_sensors site at
* http://www.lm-sensors.nu/
*
* This program opens the I2C device driver file, sets the address for
* SAA1064-#0 then sends it 6 bytes.
* byte 1 - internal starting SAA1064 register address
* byte 2 - configuration register setting
* byte 3 - LED segment 1 value
* byte 4 - LED segment 2 value
* byte 5 - LED segment 3 value
* byte 6 - LED segment 4 value
*
* For more SAA1064 or I2C protocol, visit the Philips Semiconductor website
* at http://www.semiconductors.philips.com
*/
/*
gcc -I/usr/src/linux/include -o SAA1064_x86 SAA1064_x86.c
*/
#include <fcntl.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
int main(void)
{
int file;
int address;
unsigned char buffer[10], i;
/* seg is a segment mapping table. Element 0, 0xFC, tells the
* SAA1064 to turn on the segments to display a 0. Likewise,
* seg's other entries map to 1 through 9 and a through f.
*/
unsigned char seg[] = { 0xFC, 0x60, 0xDA, 0xF2, 0x66,
0xB6, 0xBE, 0xE0, 0xFE, 0xF6,
0xEE, 0x3E, 0x9C, 0x7A, 0x9E, 0x8E } ;
if (( file = open("/dev/i2c0",O_RDWR)) < 0) {
printf("Can't open /dev/i2c0\n");
exit(1);
}
address = 0x38;
/*
* Why 0x38? Philip's SAA1064 group address is 0111, the SAA1064-#0 is
* an address zero, making it's full address 0111.0000 which is 0x70.
* The I2C driver wants addresses divided by 2, so 0x70 / 2 = 0x38.
*/
if (ioctl(file,I2C_SLAVE,address) < 0) {
printf("Can't set address\n");
exit(1);
}
buffer[0] = 0x00; /* internal starting SAA1064 register address */
buffer[1] = 0x46; /* 12mA current, all digits on, dynamic mode */
buffer[2] = seg[1]; /* this puts a '1' on the display segment 1 */
buffer[3] = seg[2]; /* this puts a '2' on the display segment 2 */
buffer[4] = seg[3]; /* this puts a '3' on the display segment 3 */
buffer[5] = seg[4]; /* this puts a '4' on the display segment 4 */
if ( write(file,buffer,6) != 6) {
printf("Write failed\n");
close(file);
exit(1);
}
close(file);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -