Subversion Repositories group.electronics

Rev

Rev 42 | Rev 44 | Go to most recent revision | Details | Compare with Previous | 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"
43 pfowler 4
#include "macros.h"
42 pfowler 5
#include <util/delay.h>
6
 
43 pfowler 7
 
42 pfowler 8
void lcd_init() {
9
	lcd_sendNib(0x30);	
43 pfowler 10
	_delay_ms(150);
11
 
42 pfowler 12
	lcd_sendNib(0x30);	
43 pfowler 13
	_delay_ms(150);
14
 
42 pfowler 15
	lcd_sendNib(0x30);	
43 pfowler 16
	_delay_ms(50);
17
 
42 pfowler 18
	lcd_sendNib(0x20);	
43 pfowler 19
	_delay_ms(50);
42 pfowler 20
 
43 pfowler 21
	lcd_command(LCD_FUNCTIONSET | LCD_2LINE);
22
	_delay_ms(50);
23
 
42 pfowler 24
	lcd_command(LCD_DISPLAYCONTROL | LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF);
43 pfowler 25
	_delay_ms(50);
42 pfowler 26
 
27
	lcd_command(LCD_CLEARDISPLAY);
43 pfowler 28
	_delay_ms(50);
42 pfowler 29
 
30
	lcd_command(LCD_RETURNHOME);
43 pfowler 31
	_delay_ms(50);
42 pfowler 32
}
33
 
34
void lcd_command(uint8_t data) {
35
	lcd_send(data, LCD_MODE_CM);
36
}
37
 
38
void lcd_char(uint8_t data) {
39
	lcd_send(data, LCD_MODE_RS);
40
}
41
 
42
 
43
void lcd_send(uint8_t value, uint8_t mode) {
44
	uint8_t high = value & 0xf0;
45
	uint8_t low = (value << 4) & 0xf0;
46
	lcd_sendNib((high)|mode);
47
	lcd_sendNib((low)|mode);
48
}
49
 
50
void lcd_sendNib(uint8_t nib) {
43 pfowler 51
	//lcd_write(nib);
42 pfowler 52
	lcd_pulse(nib);
53
}
54
 
55
void lcd_write(uint8_t data) {
56
	i2c_beginTransmission(LCD_ADDR);
57
	i2c_writeByte((int) data | 0x08);
58
	i2c_endTransmission(1);
59
}
60
 
61
void lcd_pulse(uint8_t data) {
62
	lcd_write(data | LCD_MODE_EN);
43 pfowler 63
	_delay_us(40);
42 pfowler 64
 
43 pfowler 65
	//lcd_write(data & ~LCD_MODE_EN);
66
	lcd_write(data );
67
	_delay_us(40);
42 pfowler 68
}