doc changes and lcd_plot_text for pgm space added

This commit is contained in:
Sebastian Schumb (softwerker 2009-06-11 14:48:22 +02:00
parent 1d5c73b5f0
commit 671d966944
8 changed files with 41 additions and 28 deletions

View File

@ -1,6 +1,6 @@
//taken from : http://www.mikrocontroller.net/topic/54860
const uint8_t font_12x16[] PROGMEM = {
const char font_12x16[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x00
0x0E,0x00,0x31,0x80,0x40,0x40,0x40,0x40,0x9B,0x20,0x9B,0x20,0x80,0x20,0x80,0x20,0x91,0x20,0x8E,0x20,0x40,0x40,0x40,0x40,0x31,0x80,0x0E,0x00,0x00,0x00,0x00,0x00, // 0x01
0x0E,0x00,0x3F,0x80,0x7F,0xC0,0x7F,0xC0,0xE4,0xE0,0xE4,0xE0,0xFF,0xE0,0xFF,0xE0,0xEE,0xE0,0xF1,0xE0,0x7F,0xC0,0x7F,0xC0,0x3F,0x80,0x0E,0x00,0x00,0x00,0x00,0x00, // 0x02

View File

@ -1,6 +1,6 @@
//taken from : http://www.mikrocontroller.net/topic/54860
const uint8_t font_8x8[] PROGMEM = {
const char font_8x8[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x00
0x7E,0x81,0xA5,0x81,0xBD,0x99,0x81,0x7E, // 0x01
0x7E,0xFF,0xDB,0xFF,0xC3,0xE7,0xFF,0x7E, // 0x02

View File

@ -3,6 +3,7 @@
uint16_t readADC(uint8_t channel) {
uint16_t result;
uint8_t i;
//ADC aktiv, Prescaler 16
ADCSRA = (1 << ADEN) | (1 << ADPS2);
@ -17,10 +18,14 @@ uint16_t readADC(uint8_t channel) {
ADCSRA |= (1 << ADSC);
while(ADCSRA & (1 << ADSC));
result = 0;
for(i = 0; i < ADC_READ_CYCELS; i++) {
ADCSRA |= (1 << ADSC);
while(ADCSRA & (1 << ADSC));
result = ADCW;
result += ADCW / ADC_READ_CYCELS;
_delay_us(1);
}
//ADC aus
ADCSRA &= ~(1 << ADEN);

View File

@ -6,6 +6,8 @@
#include <inttypes.h>
#define ADC_READ_CYCELS 5
uint16_t readADC(uint8_t channel);
#endif /* ADC_H */

View File

@ -187,16 +187,16 @@ uint8_t c,tmp,x,y;
if(lcd_mode == LCD_TEXT) {
c = 0;
while(!(*txt == 0)) {
c = 0; //variable to count the chars in the current line
while(!(*txt == 0)) { //loop through the string
if(*txt == '\n' || c == LCD_TEXT_COLUMNS) {
if(lcd_curline < LCD_TEXT_LINES - 1) {
if(*txt == '\n' || c == LCD_TEXT_COLUMNS) { //linebreak if //n or if a line is too long
if(lcd_curline < LCD_TEXT_LINES - 1) { //next line
lcd_curline++;
c = 0;
lcd_gotoxy(0,lcd_curline);
}
else {
else { //scroll up
for(y = 1; y < LCD_TEXT_LINES; y++ ) {
for(x = 0; x < LCD_TEXT_COLUMNS; x++) {
lcd_gotoxy(x,y);
@ -205,7 +205,7 @@ uint8_t c,tmp,x,y;
lcd_write_command(0x0C,tmp);
}
}
for(x = 0; x < LCD_TEXT_COLUMNS; x++) {
for(x = 0; x < LCD_TEXT_COLUMNS; x++) { //free the last line
lcd_write_command(0x0C,' ');
}
lcd_gotoxy(0,LCD_TEXT_LINES-1);
@ -213,7 +213,7 @@ uint8_t c,tmp,x,y;
}
}
if(*txt != '\n') {
if(*txt != '\n') { //write the character
lcd_write_command(0x0C,*txt);
c++;
}
@ -291,13 +291,15 @@ uint8_t xr;
* This function is dedicated to Greta, one of the most important persons in my life so far.\n
*
*/
void lcd_plot_bitmap(uint8_t x_off, uint8_t y_off, const uint8_t *bitmap, uint8_t w, uint8_t h) {
void lcd_plot_bitmap(uint8_t x_off, uint8_t y_off, PGM_P bitmap, uint8_t w, uint8_t h) {
uint8_t x,y,cur,curs,sr,dr;
uint16_t pos;
//check if the bitmap fits on the display
if((x_off <= LCD_GRAPHIC_WIDTH - 1) && (y_off <= LCD_GRAPHIC_HEIGHT - 1)
&& (x_off + w <= LCD_GRAPHIC_WIDTH - 1) && (y_off + h <= LCD_GRAPHIC_HEIGHT - 1)) {
curs = 0;
dr = 0;
//loop linewise through the bitmap
for(y = y_off; y < y_off + h; y++) {
cur = 0;
@ -359,8 +361,8 @@ uint16_t pos;
* @param font pointer to the flash area where the font is stored
*
*/
inline void lcd_plot_char(uint8_t x_off, uint8_t y_off, uint8_t c, uint8_t fw, uint8_t fh, const uint8_t* font) {
const uint8_t *letter;
inline void lcd_plot_char(uint8_t x_off, uint8_t y_off, uint8_t c, uint8_t fw, uint8_t fh, PGM_P font) {
PGM_P letter;
uint8_t fsize;
fsize = fh * fw / 8;
@ -383,7 +385,7 @@ uint8_t fsize;
*
* @see lcd_plot_char
*/
void lcd_plot_text(uint8_t x_off, uint8_t y_off, const char *text, uint8_t fw, uint8_t fh, const uint8_t *font) {
void lcd_plot_text(uint8_t x_off, uint8_t y_off, const char *text, uint8_t fw, uint8_t fh, PGM_P font) {
while(*text) {
lcd_plot_char(x_off,y_off,(uint8_t) *text,fw,fh,font);
@ -394,10 +396,17 @@ while(*text) {
}
void lcd_plot_pgmtext(uint8_t x_off, uint8_t y_off, const char *text, uint8_t fw, uint8_t fh, const uint8_t *font) {
void lcd_plot_pgmtext(uint8_t x_off, uint8_t y_off, PGM_P text, uint8_t fw, uint8_t fh, PGM_P font) {
uint8_t c;
c = pgm_read_byte (text);
while (c != 0)
{
lcd_plot_char(x_off,y_off,c,fw,fh,font);
x_off += fw;
text++;
c = pgm_read_byte (text);
}
}

View File

@ -74,10 +74,11 @@ void lcd_write_text(char *txt);
inline void lcd_gotoxy(uint8_t x, uint8_t y);
void lcd_plot_pixel(uint8_t x, uint8_t y, uint8_t set);
void lcd_plot_bitmap(uint8_t x, uint8_t y, const uint8_t *bitmap, uint8_t w, uint8_t h);
void lcd_plot_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint8_t w, uint8_t h);
inline void lcd_plot_char(uint8_t x_off, uint8_t y_off, uint8_t c, uint8_t fw, uint8_t fh, const uint8_t* font);
void lcd_plot_text(uint8_t x_off, uint8_t y_off, const char *text, uint8_t fw, uint8_t fh, const uint8_t *font);
inline void lcd_plot_char(uint8_t x_off, uint8_t y_off, uint8_t c, uint8_t fw, uint8_t fh, PGM_P font);
void lcd_plot_text(uint8_t x_off, uint8_t y_off, const char *text, uint8_t fw, uint8_t fh, PGM_P font);
void lcd_plot_pgmtext(uint8_t x_off, uint8_t y_off, PGM_P text, uint8_t fw, uint8_t fh, PGM_P font);
inline void lcd_strobe();

3
main.c
View File

@ -30,7 +30,8 @@ int main() {
lcd_plot_text(5,5,"Hello",16,16,font_12x16);
lcd_plot_text(50,22,"World",16,16,font_12x16);
lcd_plot_pgmtext(50,22,PSTR("World"),16,16,font_12x16);
while(!touch_is_pressed());

View File

@ -11,7 +11,6 @@
void writing_demo() {
uint8_t i;
uint16_t x,y;
lcd_clear();
@ -23,15 +22,11 @@ void writing_demo() {
x = touch_readX();
y = touch_readY();
lcd_plot_pixel(x-1,y+1,PIXEL_ON);
lcd_plot_pixel(x,y+1,PIXEL_ON);
lcd_plot_pixel(x+1,y+1,PIXEL_ON);
lcd_plot_pixel(x-1,y,PIXEL_ON);
lcd_plot_pixel(x,y,PIXEL_ON);
lcd_plot_pixel(x+1,y+1,PIXEL_ON);
lcd_plot_pixel(x+1,y,PIXEL_ON);
lcd_plot_pixel(x-1,y-1,PIXEL_ON);
lcd_plot_pixel(x,y-1,PIXEL_ON);
lcd_plot_pixel(x+1,y-1,PIXEL_ON);
}
_delay_ms(1);