Subversion Repositories group.electronics

Rev

Rev 42 | Rev 44 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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