Add files via upload

pull/7/head
Sylaina 6 years ago committed by GitHub
parent 779310c839
commit be58852484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

80
lcd.c

@ -15,22 +15,22 @@
*
* Diese Datei ist Teil von lcd library for ssd1306/sh1106 oled-display.
*
* lcd library for ssd1306/sh1106 oled-display ist Freie Software: Sie kÃnnen es unter den Bedingungen
* lcd library for ssd1306/sh1106 oled-display ist Freie Software: Sie können es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder jeder späteren
* verÃffentlichten Version, weiterverbreiten und/oder modifizieren.
* Version 3 der Lizenz oder jeder späteren
* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
*
* lcd library for ssd1306/sh1106 oled-display wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÃHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÃHIGKEIT oder EIGNUNG FÃœR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
* lcd library for ssd1306/sh1106 oled-display wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*
* lcd.h
*
* Created by Michael Koehler on 22.12.16.
* Created by Michael Köhler on 22.12.16.
* Copyright 2016 Skie-Systems. All rights reserved.
*
* lib for OLED-Display with ssd1306/sh1106-Controller
@ -45,9 +45,6 @@
#include "font.h"
#include <string.h>
/* TODO: setUp Font*/
const char *font = ssd1306oled_font6x8;
static struct {
uint8_t x;
uint8_t y;
@ -121,8 +118,8 @@ void lcd_home(void){
void lcd_invert(uint8_t invert){
i2c_start((LCD_I2C_ADR << 1) | 0);
uint8_t commandSequence[1];
if (invert == YES) {
commandSequence[0] = 0xA7;
if (invert != YES) {
commandSequence[0] = 0xA6;
} else {
commandSequence[0] = 0xA7;
}
@ -157,10 +154,10 @@ void lcd_clrscr(void){
lcd_home();
}
void lcd_gotoxy(uint8_t x, uint8_t y) {
if( x > (DISPLAY_WIDTH/6) || y > (DISPLAY_HEIGHT/8-1)) return;// out of display
if( x > (DISPLAY_WIDTH/sizeof(FONT[0])) || y > (DISPLAY_HEIGHT/8-1)) return;// out of display
cursorPosition.x=x;
cursorPosition.y=y;
x = x * 6; // one char: 6 pixel width
x = x * sizeof(FONT[0]);
#if defined SSD1306
uint8_t commandSequence[] = {0xb0+y, 0x21, x, 0x7f};
#elif defined SH1106
@ -170,12 +167,18 @@ void lcd_gotoxy(uint8_t x, uint8_t y) {
}
void lcd_putc(char c){
switch (c) {
case '\b':
// backspace
lcd_gotoxy(cursorPosition.x-1, cursorPosition.y);
lcd_putc(' ');
lcd_gotoxy(cursorPosition.x-1, cursorPosition.y);
break;
case '\t':
// tab
if( (cursorPosition.x+4) < (DISPLAY_WIDTH/6-4) ){
if( (cursorPosition.x+4) < (DISPLAY_WIDTH/ sizeof(FONT[0])-4) ){
lcd_gotoxy(cursorPosition.x+4, cursorPosition.y);
}else{
lcd_gotoxy(DISPLAY_WIDTH/6, cursorPosition.y);
lcd_gotoxy(DISPLAY_WIDTH/ sizeof(FONT[0]), cursorPosition.y);
}
break;
case '\n':
@ -189,21 +192,20 @@ void lcd_putc(char c){
lcd_gotoxy(0, cursorPosition.y);
break;
default:
if((c > 127 ||
cursorPosition.x > 20 ||
c < 32) &&
(getCharCode(c) > 0) ) return;
if( (cursorPosition.x > 20) ||
(getCharPosition(c) == 0xff) ) return;
cursorPosition.x++;
// mapping char
c=getCharCode(c);
c=getCharPosition(c);
uint8_t temp;
// print char at display
for (uint8_t i = 0; i < 6; i++)
for (uint8_t i = 0; i < sizeof(FONT[0]); i++)
{
// load bit-pattern from flash
temp=pgm_read_byte(&font[c * 6 + i]);
temp=pgm_read_byte(&(FONT[(uint8_t)c][i]));
lcd_data((void*)&temp,1); // print font to ram, print 6 columns
}
break;
}
@ -228,10 +230,10 @@ void lcd_clrscr(void){
lcd_home();
}
void lcd_gotoxy(uint8_t x, uint8_t y){
if( x > (DISPLAY_WIDTH/6) || y > (DISPLAY_HEIGHT/8-1)) return;// out of display
if( x > (DISPLAY_WIDTH/sizeof(FONT[0])) || y > (DISPLAY_HEIGHT/8-1)) return;// out of display
cursorPosition.x=x;
cursorPosition.y=y;
x = x * 6; // one char: 6 pixel width
x = x * sizeof(FONT[0]);
actualIndex = (x)+(y*DISPLAY_WIDTH);
#if defined SSD1306
uint8_t commandSequence[] = {0xb0+y, 0x21, x, 0x7f};
@ -242,12 +244,18 @@ void lcd_gotoxy(uint8_t x, uint8_t y){
}
void lcd_putc(char c){
switch (c) {
case '\b':
// backspace
lcd_gotoxy(cursorPosition.x-1, cursorPosition.y);
lcd_putc(' ');
lcd_gotoxy(cursorPosition.x-1, cursorPosition.y);
break;
case '\t':
// tab
if( (cursorPosition.x+4) < (DISPLAY_WIDTH/6-4) ){
if( (cursorPosition.x+4) < (DISPLAY_WIDTH/sizeof(FONT[0])-4) ){
lcd_gotoxy(cursorPosition.x+4, cursorPosition.y);
}else{
lcd_gotoxy(DISPLAY_WIDTH/6, cursorPosition.y);
lcd_gotoxy(DISPLAY_WIDTH/sizeof(FONT[0]), cursorPosition.y);
}
break;
case '\n':
@ -262,23 +270,21 @@ void lcd_putc(char c){
break;
default:
if((actualIndex+1)%127 != 0){
if((c > 127 ||
cursorPosition.x > 20 ||
c < 32) &&
(getCharCode(c) > 0) ) return;
if( (cursorPosition.x > 20) ||
(getCharPosition(c) == 0xff) ) return;
cursorPosition.x++;
// mapping char
c=getCharCode(c);
c=getCharPosition(c);
// print char at display
for (uint8_t i = 0; i < 6; i++)
for (uint8_t i = 0; i < sizeof(FONT[0]); i++)
{
// load bit-pattern from flash
displayBuffer[actualIndex+i] =pgm_read_byte(&font[c * 6 + i]);
displayBuffer[actualIndex+i] =pgm_read_byte(&(FONT[(uint8_t)c][i]));;
}
}
actualIndex += 6;
actualIndex += sizeof(FONT[0]);
break;
}
}
@ -397,4 +403,4 @@ void lcd_display() {
}
#endif
}
#endif
#endif

139
lcd.h

@ -22,39 +22,15 @@
*
* lcd library for ssd1306/sh1106 oled-display wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK./*
* This file is part of lcd library for ssd1306/sh1106 oled-display.
*
* lcd library for ssd1306/sh1106 oled-display is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
*
* lcd library for ssd1306/sh1106 oled-display is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*
* Diese Datei ist Teil von lcd library for ssd1306/sh1106 oled-display.
*
* lcd library for ssd1306/sh1106 oled-display ist Freie Software: Sie kÃnnen es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder jeder späteren
* verÃffentlichten Version, weiterverbreiten und/oder modifizieren.
*
* lcd library for ssd1306/sh1106 oled-display wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÃHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÃHIGKEIT oder EIGNUNG FÃœR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*
* lcd.h
*
* Created by Michael KÃhler on 22.12.16.
* Created by Michael Köhler on 22.12.16.
* Copyright 2016 Skie-Systems. All rights reserved.
*
* lib for OLED-Display with ssd1306/sh1106-Controller
@ -68,13 +44,6 @@
#ifndef LCD_H
#define LCD_H
#ifndef YES
#define YES 1
#define NO 0
#else
#error "Check #defines for YES and NO in other sources !"
#endif
#if (__GNUC__ * 100 + __GNUC_MINOR__) < 303
#error "This library requires AVR-GCC 3.3 or later, update to newer AVR-GCC compiler !"
#endif
@ -87,105 +56,27 @@
// i2c_start(), i2c_byte(), i2c_stop()
/* TODO: define displaycontroller */
#define SSD1306 // or SSD1306, check datasheet of your display
#define SH1106 // or SSD1306, check datasheet of your display
/* TODO: define displaymode */
#define TEXTMODE // TEXTMODE for only text to display,
// GRAPHICMODE for text and graphic
/* TODO: define font */
#define FONT ssd1306oled_font
/* TODO: define I2C-adress for display */
// using 7-bit-adress for lcd-library
// if you use your own library for twi check I2C-adress-handle
#define LCD_I2C_ADR 0x3C // 7 bit slave-adress without r/w-bit
#define LCD_I2C_ADR (0x7a >> 1) // 7 bit slave-adress without r/w-bit
// r/w-bit are set/unset by library
// e.g. 8 bit slave-adress:
// 0x78 = adress 0x3C with cleared r/w-bit (write-mode)
#define LCD_DISP_OFF 0xAE
#define LCD_DISP_ON 0xAF
#define WHITE 0x01
#define BLACK 0x00
#define DISPLAY_WIDTH 128
#define DISPLAY_HEIGHT 64
#define DISPLAYSIZE DISPLAY_WIDTH*DISPLAY_HEIGHT/8
void lcd_command(uint8_t cmd[], uint8_t size); // transmit command to display
void lcd_data(uint8_t data[], uint16_t size); // transmit data to display
void lcd_init(uint8_t dispAttr);
void lcd_home(void); // set cursor to 0,0
void lcd_invert(uint8_t invert); // invert display
void lcd_set_contrast(uint8_t contrast); // set contrast for display
void lcd_puts(const char* s); // print string, \n-terminated, from ram on screen (TEXTMODE)
// or buffer (GRAPHICMODE)
void lcd_puts_p(const char* progmem_s); // print string from flash on screen (TEXTMODE)
// or buffer (GRAPHICMODE)
void lcd_clrscr(void); // clear screen (and buffer at GRFAICMODE)
void lcd_gotoxy(uint8_t x, uint8_t y); // set curser at pos x, y. x means character,
// y means line (page, refer lcd manual)
void lcd_putc(char c); // print character on screen at TEXTMODE
// at GRAPHICMODE print character to buffer
#if defined GRAPHICMODE
void lcd_drawPixel(uint8_t x, uint8_t y, uint8_t color);
void lcd_drawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color);
void lcd_drawRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color);
void lcd_fillRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color);
void lcd_drawCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color);
void lcd_fillCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color);
void lcd_drawBitmap(uint8_t x, uint8_t y, const uint8_t picture[], uint8_t width, uint8_t height, uint8_t color);
void lcd_display(void); // copy buffer to display RAM
#endif
#endif /* LCD_H */
* Siehe die GNU General Public License für weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*
* lcd.h
*
* Created by Michael Köhler on 22.12.16.
* Copyright 2016 Skie-Systems. All rights reserved.
*
* lib for OLED-Display with ssd1306/sh1106-Controller
* first dev-version only for I2C-Connection
* at ATMega328P like Arduino Uno
*
* at GRAPHICMODE lib needs SRAM for display
* DISPLAY-WIDTH * DISPLAY-HEIGHT + 2 bytes
*/
#ifndef LCD_H
#define LCD_H
#ifndef YES
#define YES 1
#define NO 0
#else
#error "Check #defines for YES and NO in other sources !"
#endif
#if (__GNUC__ * 100 + __GNUC_MINOR__) < 303
#error "This library requires AVR-GCC 3.3 or later, update to newer AVR-GCC compiler !"
#define YES 1
#endif
#include <inttypes.h>
#include <avr/pgmspace.h>
#include "i2c.h" // library for I2C-communication
// if you want to use other lib for I2C
// edit i2c_xxx commands in this library
// i2c_start(), i2c_byte(), i2c_stop()
/* TODO: define displaycontroller */
#define SH1106 // or SSD1306, check datasheet of your display
/* TODO: define displaymode */
#define GRAPHICMODE // TEXTMODE for only text to display,
// GRAPHICMODE for text and graphic
/* TODO: define I2C-adress for display */
// using 8-bit-mode (slave-mode) for i2c-library
// if you use your own library for twi check I2C-adress-handle
#define LCD_I2C_ADR 0x7A
#define LCD_DISP_OFF 0xAE
#define LCD_DISP_ON 0xAF
@ -196,6 +87,8 @@ void lcd_display(void); // copy buffer to display RAM
#define DISPLAY_HEIGHT 64
#define DISPLAYSIZE DISPLAY_WIDTH*DISPLAY_HEIGHT/8
void lcd_command(uint8_t cmd[], uint8_t size); // transmit command to display
void lcd_data(uint8_t data[], uint16_t size); // transmit data to display
void lcd_init(uint8_t dispAttr);
@ -203,15 +96,15 @@ void lcd_home(void); // set cursor to 0,0
void lcd_invert(uint8_t invert); // invert display
void lcd_set_contrast(uint8_t contrast); // set contrast for display
void lcd_puts(const char* s); // print string, \n-terminated, from ram on screen (TEXTMODE)
// or buffer (GRAPHICMODE)
// or buffer (GRAPHICMODE)
void lcd_puts_p(const char* progmem_s); // print string from flash on screen (TEXTMODE)
// or buffer (GRAPHICMODE)
// or buffer (GRAPHICMODE)
void lcd_clrscr(void); // clear screen (and buffer at GRFAICMODE)
void lcd_gotoxy(uint8_t x, uint8_t y); // set curser at pos x, y. x means character,
// y means line (page, refer lcd manual)
// y means line (page, refer lcd manual)
void lcd_putc(char c); // print character on screen at TEXTMODE
// at GRAPHICMODE print character to buffer
// at GRAPHICMODE print character to buffer
#if defined GRAPHICMODE
void lcd_drawPixel(uint8_t x, uint8_t y, uint8_t color);
void lcd_drawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color);
@ -222,4 +115,4 @@ void lcd_fillCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t
void lcd_drawBitmap(uint8_t x, uint8_t y, const uint8_t picture[], uint8_t width, uint8_t height, uint8_t color);
void lcd_display(void); // copy buffer to display RAM
#endif
#endif /* LCD_H */
#endif /* LCD_H */
Loading…
Cancel
Save