EVM LED Blinking.c
Revision as of 13:15, 12 September 2007 by Ekiller200 (talk | contribs)
/**********************************************************************
* EVM_LED_BLINKING.C
* Eric Tanner 2007.
*
* Simple program to blink the LEDs on the DaVinci
* EVM using the the LED port expander PCF8574A at I2C Slave Address 0x38.
* I2C Support and I2C device interface must be turned on in the kernel.
*
**************************************************************************/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <signal.h>
#define I2C_DEVICE "/dev/i2c/0"
#define I2C_DEV_ADDR 0x38
#define I2C_SLAVE 0x0703
int main()
{
int i2c_fd;
int state = 0;
unsigned char val = 0x00;
int ret;
struct timespec req =
{
.tv_sec = 0,
.tv_nsec = 100000000,
};
if((i2c_fd = open(I2C_DEVICE,O_RDWR)) < 0)
{
printf("Unable to open the i2c port!\n");
exit(1);
}
if(ioctl(i2c_fd, I2C_SLAVE, I2C_DEV_ADDR)== -1)
{
close( i2c_fd );
printf("Unable to setup the i2c port!\n");
exit(1);
}
do
{
val <<= 1;
val |= 0x01;
if(val == 0xFF)
val = 0xFE;
write( i2c_fd, &val, 1);
} while (!nanosleep (&req, NULL));
close ( i2c_fd );
printf ("End.\n");
return 0;
}