diff --git a/12x16_horizontal_LSB_1.h b/12x16_horizontal_LSB_1.h index 7a31197..19339c0 100644 --- a/12x16_horizontal_LSB_1.h +++ b/12x16_horizontal_LSB_1.h @@ -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 diff --git a/8x8_horizontal_LSB_1.h b/8x8_horizontal_LSB_1.h index 93b4cd6..0fba522 100644 --- a/8x8_horizontal_LSB_1.h +++ b/8x8_horizontal_LSB_1.h @@ -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 diff --git a/include/adc.c b/include/adc.c index 0bb35e0..3fc1cc6 100644 --- a/include/adc.c +++ b/include/adc.c @@ -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); diff --git a/include/adc.h b/include/adc.h index 077b243..eb93e22 100644 --- a/include/adc.h +++ b/include/adc.h @@ -6,6 +6,8 @@ #include +#define ADC_READ_CYCELS 5 + uint16_t readADC(uint8_t channel); #endif /* ADC_H */ diff --git a/include/lc7981.c b/include/lc7981.c index 37954e1..d48f07b 100644 --- a/include/lc7981.c +++ b/include/lc7981.c @@ -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); + } } diff --git a/include/lc7981.h b/include/lc7981.h index d636876..78b1b2b 100644 --- a/include/lc7981.h +++ b/include/lc7981.h @@ -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(); diff --git a/main.c b/main.c index e2eb0ce..c355d3d 100644 --- a/main.c +++ b/main.c @@ -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()); diff --git a/writing_demo.c b/writing_demo.c index 103fb6f..c5f4dbe 100644 --- a/writing_demo.c +++ b/writing_demo.c @@ -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);