MiraBox User Guide
–page
27
/
29
Give this program the name
“i2c_led.c”
and save to
“/home”
directory, then compile it.
# cd /home
# arm-marvell-linux-gnueabi-gcc -o led i2c_led.c
Then copy the executable file
“led” to Mirabox and run it. You can see the LED is controlled by yourself.
/*********** control the GPIO OP-4 **************************************/
//turn on LED
sleep(1);
(e2prom_data.msgs[0]).buf[0]=0x1c;// e2prom write address
(e2prom_data.msgs[0]).buf[1]=0x0;//the data to write
ret=ioctl(fd,I2C_RDWR,(unsigned long)&e2prom_data);
if(ret<0)
{
perror("ioctl error5");
}
//turn off LED
sleep(1);
(e2prom_data.msgs[0]).buf[0]=0x1c;// e2prom write address
(e2prom_data.msgs[0]).buf[1]=0xFF;// the data to write
ret=ioctl(fd,I2C_RDWR,(unsigned long)&e2prom_data);
if(ret<0)
{
perror("ioctl error5");
}
printf("testing ok\n");
close(fd);
return 0;
}