Subversion Repositories group.electronics

Rev

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

Rev 51 Rev 52
Line 38... Line 38...
38
 
38
 
39
	lcd_home();
39
	lcd_home();
40
	_delay_ms(10);
40
	_delay_ms(10);
41
}
41
}
42
 
42
 
-
 
43
 
-
 
44
/************************/
-
 
45
/** Fancy functions    **/
-
 
46
/************************/
43
void lcd_pergraph(uint8_t val, uint8_t col, uint8_t row) {
47
void lcd_percent_graph(uint8_t val, uint8_t row, uint8_t col) {
44
	uint8_t i = 0;
48
	uint8_t i = 0;
45
	uint8_t c = val / 10;	
49
	uint8_t c = val / 10;	
46
	lcd_setCursor(col, row);
50
	lcd_setCursor(col, row);
47
	for (i = 0; i<10; i++) {
51
	for (i = 0; i<10; i++) {
48
		if (i < c)
52
		if (i < c)
Line 50... Line 54...
50
		else
54
		else
51
			lcd_char(0x00);
55
			lcd_char(0x00);
52
	}
56
	}
53
}
57
}
54
 
58
 
-
 
59
/************************/
-
 
60
/** Character Printing **/
-
 
61
/************************/
-
 
62
 
-
 
63
uint8_t lcd_print_right(char *str) {
-
 
64
	uint8_t c = 0;
-
 
65
	char* oldp = str;
-
 
66
	while (str[0] != 0x00) 
-
 
67
		c++;
-
 
68
	lcd_autoscroll();
-
 
69
	while (str != oldp) {
-
 
70
		lcd_char((uint8_t) str[0]);
-
 
71
		str--;
-
 
72
	}
-
 
73
	lcd_noAutoscroll();
-
 
74
	return c;
-
 
75
}
-
 
76
 
-
 
77
uint8_t lcd_print(char* str) {
-
 
78
        uint8_t c = 0;
-
 
79
        while (str[0] != 0x00) {
-
 
80
                lcd_char((uint8_t) str[0]);
-
 
81
                str++;
-
 
82
                c++;
-
 
83
        }
-
 
84
        return c;
-
 
85
}
-
 
86
 
-
 
87
void lcd_overprint(char * str, uint8_t len, uint8_t col, uint8_t row) {
-
 
88
        uint8_t i = 0;
-
 
89
        lcd_setCursor(row, col);
-
 
90
 
-
 
91
        uint8_t size = lcd_print(str);
-
 
92
        for (i=size; i<=len; i++)
-
 
93
                lcd_char(0x20);
-
 
94
}
-
 
95
 
-
 
96
 
-
 
97
/************************/
55
/** Helper functions **/
98
/** Helper functions **/
-
 
99
/************************/
56
 
100
 
57
inline void lcd_clear() {
101
inline void lcd_clear() {
58
	lcd_command(LCD_CLEARDISPLAY);
102
	lcd_command(LCD_CLEARDISPLAY);
59
}
103
}
60
 
104
 
Line 83... Line 127...
83
void lcd_autoscroll() {
127
void lcd_autoscroll() {
84
        lcd.display |= LCD_ENTRYSHIFTINCREMENT;
128
        lcd.display |= LCD_ENTRYSHIFTINCREMENT;
85
        lcd_command(LCD_ENTRYMODESET | lcd.display);
129
        lcd_command(LCD_ENTRYMODESET | lcd.display);
86
}
130
}
87
 
131
 
-
 
132
void lcd_noAutoscroll() {
-
 
133
        lcd.display &= ~LCD_ENTRYSHIFTINCREMENT;
-
 
134
        lcd_command(LCD_ENTRYMODESET | lcd.display);
-
 
135
}
-
 
136
 
88
void lcd_setCursor(uint8_t col, uint8_t row) {
137
void lcd_setCursor(uint8_t col, uint8_t row) {
89
	uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
138
	uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
90
	lcd_command(LCD_SETDDRAMADDR | ((col - 1)+ row_offsets[row]));
139
	lcd_command(LCD_SETDDRAMADDR | ((col - 1)+ row_offsets[row]));
91
}
140
}
92
 
141
 
93
void lcd_overprint(char * str, uint8_t len, uint8_t col, uint8_t row) {
-
 
94
	uint8_t i = 0;
-
 
95
	lcd_setCursor(col, row);
142
/************************/
96
	uint8_t size = lcd_print(str);
143
/** Low level functions **/
97
	for (i=size; i<len; i++)
-
 
98
		lcd_char(0x20);	
-
 
99
}
-
 
100
 
-
 
101
/** End helpers **/
144
/************************/
102
 
-
 
103
 
145
 
104
void lcd_command(uint8_t data) {
146
void lcd_command(uint8_t data) {
105
	lcd_send(data, LCD_MODE_CM);
147
	lcd_send(data, LCD_MODE_CM);
106
}
148
}
107
 
149
 
108
void lcd_char(uint8_t data) {
150
void lcd_char(uint8_t data) {
109
	lcd_send(data, LCD_MODE_RS);
151
	lcd_send(data, LCD_MODE_RS);
110
}
152
}
111
 
153
 
112
uint8_t lcd_print(char* str) {
-
 
113
	uint8_t c = 0;
-
 
114
	while (str[0] != 0x00) {
-
 
115
		lcd_char((uint8_t) str[0]);
-
 
116
		str++;
-
 
117
		c++;
-
 
118
	}
-
 
119
	return c;
-
 
120
}
-
 
121
 
-
 
122
void lcd_send(uint8_t value, uint8_t mode) {
154
void lcd_send(uint8_t value, uint8_t mode) {
123
	uint8_t high = value & 0xf0;
155
	uint8_t high = value & 0xf0;
124
	uint8_t low = (value << 4) & 0xf0;
156
	uint8_t low = (value << 4) & 0xf0;
125
	lcd_pulse((high)|mode);
157
	lcd_pulse((high)|mode);
126
	lcd_pulse((low)|mode);
158
	lcd_pulse((low)|mode);
Line 132... Line 164...
132
	i2c_writeByte((int) data | lcd.backlight);
164
	i2c_writeByte((int) data | lcd.backlight);
133
	i2c_endTransmission(1);
165
	i2c_endTransmission(1);
134
	_delay_us(5);
166
	_delay_us(5);
135
}
167
}
136
 
168
 
137
 
-
 
138
void lcd_createChar(uint8_t location, uint8_t charmap[]) {
169
void lcd_createChar(uint8_t location, uint8_t charmap[]) {
139
        location &= 0x7; // we only have 8 locations 0-7
170
        location &= 0x7; // we only have 8 locations 0-7
140
        lcd_command(LCD_SETCGRAMADDR | (location << 3));
171
        lcd_command(LCD_SETCGRAMADDR | (location << 3));
141
	uint8_t i = 0;
172
	uint8_t i = 0;
142
        for (i=0; i<8; i++) {
173
        for (i=0; i<8; i++) {