Subversion Repositories group.electronics

Rev

Rev 43 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
42 pfowler 1
#include <avr/io.h>
2
#include "wire.h"
3
#include "lcd.h"
4
 
5
#define F_CPU 12000000
6
#include <util/delay.h>
7
 
8
void lcd_init() {
9
	lcd_sendNib(0x30);	
10
	_delay_ms(4500);
11
	lcd_sendNib(0x30);	
12
	_delay_ms(4500);
13
	lcd_sendNib(0x30);	
14
	_delay_ms(150);
15
	lcd_sendNib(0x20);	
16
 
17
	lcd_command(LCD_FUNCTIONSET | LCD_4BITMODE | LCD_2LINE | LCD_5x8DOTS);
18
	lcd_command(LCD_DISPLAYCONTROL | LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF);
19
 
20
	lcd_command(LCD_CLEARDISPLAY);
21
	_delay_ms(2000);
22
 
23
	lcd_command(LCD_RETURNHOME);
24
}
25
 
26
void lcd_command(uint8_t data) {
27
	lcd_send(data, LCD_MODE_CM);
28
}
29
 
30
void lcd_char(uint8_t data) {
31
	lcd_send(data, LCD_MODE_RS);
32
}
33
 
34
 
35
void lcd_send(uint8_t value, uint8_t mode) {
36
	uint8_t high = value & 0xf0;
37
	uint8_t low = (value << 4) & 0xf0;
38
	lcd_sendNib((high)|mode);
39
	lcd_sendNib((low)|mode);
40
}
41
 
42
void lcd_sendNib(uint8_t nib) {
43
	lcd_write(nib);
44
	lcd_pulse(nib);
45
}
46
 
47
void lcd_write(uint8_t data) {
48
	i2c_beginTransmission(LCD_ADDR);
49
	i2c_writeByte((int) data | 0x08);
50
	i2c_endTransmission(1);
51
}
52
 
53
void lcd_pulse(uint8_t data) {
54
	lcd_write(data | LCD_MODE_EN);
55
	_delay_ms(1);
56
 
57
	lcd_write(data & ~LCD_MODE_EN);
58
	_delay_ms(50);
59
}