Subversion Repositories group.electronics

Rev

Rev 55 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 55 Rev 58
Line 1... Line 1...
1
#include <avr/io.h>
1
#include <avr/io.h>
2
#include <stdlib.h>
2
#include <stdlib.h>
3
#include "wire.h"
3
#include "wire.h"
4
#include "lcd.h"
4
#include "lcd.h"
5
#include "petelib.h"
5
#include "util.h"
6
#include <util/delay.h>
6
#include <util/delay.h>
7
 
7
 
8
void lcd_init() {
8
void lcd_init() {
9
	lcd.backlight = LCD_BACKLIGHT;
9
	lcd.backlight = LCD_BACKLIGHT;
10
	lcd.display = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
10
	lcd.display = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
Line 73... Line 73...
73
}
73
}
74
 
74
 
75
void lcd_overprint_right(char *str, uint8_t len, uint8_t col, uint8_t row) {
75
void lcd_overprint_right(char *str, uint8_t len, uint8_t col, uint8_t row) {
76
	uint8_t c = 1;
76
	uint8_t c = 1;
77
	char* oldstr = str;
77
	char* oldstr = str;
78
        while ((++str)[0] != 0x00)
78
	while ((++str)[0] != 0x00)
79
                c++;
79
		c++;
80
 
80
 
81
	lcd_setCursor(col+1, row);
81
	lcd_setCursor(col+1, row);
82
	uint8_t i = 0;
82
	uint8_t i = 0;
83
	for (i = 0; i<(len-c); i++) 
83
	for (i = 0; i<(len-c); i++) 
84
		lcd_char(0x20);
84
		lcd_char(0x20);
Line 86... Line 86...
86
	for (i = 0; i<c; i++) 
86
	for (i = 0; i<c; i++) 
87
		lcd_char(oldstr[i]);
87
		lcd_char(oldstr[i]);
88
}
88
}
89
 
89
 
90
uint8_t lcd_print(char* str) {
90
uint8_t lcd_print(char* str) {
91
        uint8_t c = 0;
91
	uint8_t c = 0;
92
        while ((str++)[0] != 0x00) {
92
	while ((str++)[0] != 0x00) {
93
                lcd_char((uint8_t) (str-1)[0]);
93
		lcd_char((uint8_t) (str-1)[0]);
94
                c++;
94
		c++;
95
        }
95
	}
96
        return c;
96
	return c;
97
}
97
}
98
 
98
 
99
void lcd_overprint(char * str, uint8_t len, uint8_t col, uint8_t row) {
99
void lcd_overprint(char * str, uint8_t len, uint8_t col, uint8_t row) {
100
        uint8_t i = 0;
100
	uint8_t i = 0;
101
        lcd_setCursor(col, row);
101
	lcd_setCursor(col, row);
102
 
102
 
103
        uint8_t size = lcd_print(str);
103
	uint8_t size = lcd_print(str);
104
        for (i=size; i<=len; i++)
104
	for (i=size; i<=len; i++)
105
                lcd_char(0x20);
105
		lcd_char(0x20);
106
}
106
}
107
 
107
 
108
 
108
 
109
/************************/
109
/************************/
110
/** Helper functions **/
110
/** Helper functions **/
Line 135... Line 135...
135
	lcd.display &= ~LCD_DISPLAYON;
135
	lcd.display &= ~LCD_DISPLAYON;
136
	lcd_command(LCD_DISPLAYCONTROL | lcd.display);
136
	lcd_command(LCD_DISPLAYCONTROL | lcd.display);
137
}
137
}
138
 
138
 
139
void lcd_autocursorLeft(void) {
139
void lcd_autocursorLeft(void) {
140
        lcd.display |= LCD_ENTRYLEFT;
140
	lcd.display |= LCD_ENTRYLEFT;
141
        lcd_command(LCD_ENTRYMODESET | lcd.display);
141
	lcd_command(LCD_ENTRYMODESET | lcd.display);
142
}
142
}
143
 
143
 
144
void lcd_autocursorRight(void) {
144
void lcd_autocursorRight(void) {
145
        lcd.display &= ~LCD_ENTRYLEFT;
145
	lcd.display &= ~LCD_ENTRYLEFT;
146
        lcd_command(LCD_ENTRYMODESET | lcd.display);
146
	lcd_command(LCD_ENTRYMODESET | lcd.display);
147
}
147
}
148
 
148
 
149
void lcd_autoscroll() {
149
void lcd_autoscroll() {
150
        lcd.display |= LCD_ENTRYSHIFTINCREMENT;
150
	lcd.display |= LCD_ENTRYSHIFTINCREMENT;
151
        lcd_command(LCD_ENTRYMODESET | lcd.display);
151
	lcd_command(LCD_ENTRYMODESET | lcd.display);
152
}
152
}
153
 
153
 
154
void lcd_noAutoscroll() {
154
void lcd_noAutoscroll() {
155
        lcd.display &= ~LCD_ENTRYSHIFTINCREMENT;
155
	lcd.display &= ~LCD_ENTRYSHIFTINCREMENT;
156
        lcd_command(LCD_ENTRYMODESET | lcd.display);
156
	lcd_command(LCD_ENTRYMODESET | lcd.display);
157
}
157
}
158
 
158
 
159
void lcd_setCursor(uint8_t col, uint8_t row) {
159
void lcd_setCursor(uint8_t col, uint8_t row) {
160
	uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
160
	uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
161
	lcd_command(LCD_SETDDRAMADDR | ((col - 1)+ row_offsets[row]));
161
	lcd_command(LCD_SETDDRAMADDR | ((col - 1)+ row_offsets[row]));
Line 187... Line 187...
187
	i2c_endTransmission(1);
187
	i2c_endTransmission(1);
188
	_delay_us(5);
188
	_delay_us(5);
189
}
189
}
190
 
190
 
191
void lcd_createChar(uint8_t location, uint8_t charmap[]) {
191
void lcd_createChar(uint8_t location, uint8_t charmap[]) {
192
        location &= 0x7; // we only have 8 locations 0-7
192
	location &= 0x7; // we only have 8 locations 0-7
193
        lcd_command(LCD_SETCGRAMADDR | (location << 3));
193
	lcd_command(LCD_SETCGRAMADDR | (location << 3));
194
	uint8_t i = 0;
194
	uint8_t i = 0;
195
        for (i=0; i<8; i++) {
195
	for (i=0; i<8; i++) {
196
                lcd_char(charmap[i]);
196
		lcd_char(charmap[i]);
197
        }
197
	}
198
}
198
}