Difference between revisions of "EVM LED Blinking.c"

From eLinux.org
Jump to: navigation, search
m (Fix spelling of category)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
See [http://wiki.davincidsp.com/index.php?title=LED_usage_on_DVEVM LED usage on DaVinci EVM] article of [http://wiki.davincidsp.com/index.php?title=Main_Page official DaVinci wiki].
  
/**********************************************************************
+
[[Category:DaVinci]]
* EVM_LED_BLINKING.C
 
*
 
* 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;
 
 
 
}
 

Latest revision as of 13:33, 27 October 2011