|
发表于 2013-9-11 06:06:29
|
显示全部楼层
void lcd1602_init(void) {
char filename[40];
const char *buffer;
unsigned addr = 0b00100111; // The I2C address of the 1602 0x27
unsigned char out_byte=0;
sprintf(filename,"/dev/i2c-1");
if ((file = open(filename,O_RDWR)) < 0) {
printf("Failed to open the bus.");
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
if (ioctl(file,I2C_SLAVE,addr) < 0) {
printf("Failed to acquire bus access and/or talk to slave.\n");
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
out_byte=0x2c;
write(file,&out_byte,1);
out_byte=0x28;
write(file,&out_byte,1);
char buf[10] = {0};
buf[0] |= ( LCD_FUNCTIONSET | LCD_4BITMODE | LCD_2LINE | LCD_5x8DOTS); |
|