Rev 43 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include <avr/io.h>
#include "wire.h"
#include "lcd.h"
#define F_CPU 12000000
#include <util/delay.h>
void lcd_init() {
lcd_sendNib(0x30);
_delay_ms(4500);
lcd_sendNib(0x30);
_delay_ms(4500);
lcd_sendNib(0x30);
_delay_ms(150);
lcd_sendNib(0x20);
lcd_command(LCD_FUNCTIONSET | LCD_4BITMODE | LCD_2LINE | LCD_5x8DOTS);
lcd_command(LCD_DISPLAYCONTROL | LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF);
lcd_command(LCD_CLEARDISPLAY);
_delay_ms(2000);
lcd_command(LCD_RETURNHOME);
}
void lcd_command(uint8_t data) {
lcd_send(data, LCD_MODE_CM);
}
void lcd_char(uint8_t data) {
lcd_send(data, LCD_MODE_RS);
}
void lcd_send(uint8_t value, uint8_t mode) {
uint8_t high = value & 0xf0;
uint8_t low = (value << 4) & 0xf0;
lcd_sendNib((high)|mode);
lcd_sendNib((low)|mode);
}
void lcd_sendNib(uint8_t nib) {
lcd_write(nib);
lcd_pulse(nib);
}
void lcd_write(uint8_t data) {
i2c_beginTransmission(LCD_ADDR);
i2c_writeByte((int) data | 0x08);
i2c_endTransmission(1);
}
void lcd_pulse(uint8_t data) {
lcd_write(data | LCD_MODE_EN);
_delay_ms(1);
lcd_write(data & ~LCD_MODE_EN);
_delay_ms(50);
}