added oled

This commit is contained in:
Hendrik Schutter 2018-11-25 12:54:48 +01:00
parent c07f93fb7d
commit 423ed66f06
6 changed files with 647 additions and 2 deletions

View File

@ -28,6 +28,7 @@ todo
https://github.com/marenz2569/libws2812_avr
https://www.ulrichradig.de/home/index.php/avr/oled-display-ssd1306
todo

View File

@ -23,6 +23,7 @@ int main(void) {
clk = &tmp;
ioController io;
oled_ssd1306 disp;
io.setBuzzer(false);
io.deactivateChargers();
@ -31,10 +32,12 @@ int main(void) {
createChargers();
disp.oled_init();
disp.oled_gotoxy(0, 0);
disp.oled_write("Hallo Welt!");
io.setWS2812(0, 255, 255);
//loop till power off
while (true) {
checkForBattery();

View File

@ -0,0 +1,273 @@
/*
* Created: 1.05.2016 09:17:00
* Author: Ulrich
* From: https://www.ulrichradig.de/home/index.php/avr/oled-display-ssd1306
*/
#ifndef FONT_H
#define FONT_H
#include <inttypes.h>
#include <avr/pgmspace.h>
static const char font[256][8] PROGMEM ={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x00
{0x7E,0x81,0x95,0xB1,0xB1,0x95,0x81,0x7E}, // 0x01
{0x7E,0xFF,0xEB,0xCF,0xCF,0xEB,0xFF,0x7E}, // 0x02
{0x0E,0x1F,0x3F,0x7E,0x3F,0x1F,0x0E,0x00}, // 0x03
{0x08,0x1C,0x3E,0x7F,0x3E,0x1C,0x08,0x00}, // 0x04
{0x38,0x3A,0x9F,0xFF,0x9F,0x3A,0x38,0x00}, // 0x05
{0x10,0x38,0xBC,0xFF,0xBC,0x38,0x10,0x00}, // 0x06
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x07
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x08
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x09
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x0A
{0x70,0xF8,0x88,0x88,0xFD,0x7F,0x07,0x0F}, // 0x0B
{0x00,0x4E,0x5F,0xF1,0xF1,0x5F,0x4E,0x00}, // 0x0C
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x0D
{0xC0,0xFF,0x7F,0x05,0x05,0x65,0x7F,0x3F}, // 0x0E
{0x99,0x5A,0x3C,0xE7,0xE7,0x3C,0x5A,0x99}, // 0x0F
{0x7F,0x3E,0x3E,0x1C,0x1C,0x08,0x08,0x00}, // 0x10
{0x08,0x08,0x1C,0x1C,0x3E,0x3E,0x7F,0x00}, // 0x11
{0x00,0x24,0x66,0xFF,0xFF,0x66,0x24,0x00}, // 0x12
{0x00,0x5F,0x5F,0x00,0x00,0x5F,0x5F,0x00}, // 0x13
{0x06,0x0F,0x09,0x7F,0x7F,0x01,0x7F,0x7F}, // 0x14
{0xDA,0xBF,0xA5,0xA5,0xFD,0x59,0x03,0x02}, // 0x15
{0x00,0x70,0x70,0x70,0x70,0x70,0x70,0x00}, // 0x16
{0x80,0x94,0xB6,0xFF,0xFF,0xB6,0x94,0x80}, // 0x17
{0x00,0x04,0x06,0x7F,0x7F,0x06,0x04,0x00}, // 0x18
{0x00,0x10,0x30,0x7F,0x7F,0x30,0x10,0x00}, // 0x19
{0x08,0x08,0x08,0x2A,0x3E,0x1C,0x08,0x00}, // 0x1A
{0x08,0x1C,0x3E,0x2A,0x08,0x08,0x08,0x00}, // 0x1B
{0x3C,0x3C,0x20,0x20,0x20,0x20,0x20,0x00}, // 0x1C
{0x08,0x1C,0x3E,0x08,0x08,0x3E,0x1C,0x08}, // 0x1D
{0x30,0x38,0x3C,0x3E,0x3E,0x3C,0x38,0x30}, // 0x1E
{0x06,0x0E,0x1E,0x3E,0x3E,0x1E,0x0E,0x06}, // 0x1F
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0x20
{0x00,0x06,0x5F,0x5F,0x06,0x00,0x00,0x00}, // 0x21
{0x00,0x07,0x07,0x00,0x07,0x07,0x00,0x00}, // 0x22
{0x14,0x7F,0x7F,0x14,0x7F,0x7F,0x14,0x00}, // 0x23
{0x24,0x2E,0x6B,0x6B,0x3A,0x12,0x00,0x00}, // 0x24
{0x46,0x66,0x30,0x18,0x0C,0x66,0x62,0x00}, // 0x25
{0x30,0x7A,0x4F,0x5D,0x37,0x7A,0x48,0x00}, // 0x26
{0x04,0x07,0x03,0x00,0x00,0x00,0x00,0x00}, // 0x27
{0x00,0x1C,0x3E,0x63,0x41,0x00,0x00,0x00}, // 0x28
{0x00,0x41,0x63,0x3E,0x1C,0x00,0x00,0x00}, // 0x29
{0x08,0x2A,0x3E,0x1C,0x1C,0x3E,0x2A,0x08}, // 0x2A
{0x08,0x08,0x3E,0x3E,0x08,0x08,0x00,0x00}, // 0x2B
{0x00,0xA0,0xE0,0x60,0x00,0x00,0x00,0x00}, // 0x2C
{0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00}, // 0x2D
{0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00}, // 0x2E
{0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00}, // 0x2F
{0x3E,0x7F,0x59,0x4D,0x7F,0x3E,0x00,0x00}, // 0x30
{0x42,0x42,0x7F,0x7F,0x40,0x40,0x00,0x00}, // 0x31
{0x62,0x73,0x59,0x49,0x6F,0x66,0x00,0x00}, // 0x32
{0x22,0x63,0x49,0x49,0x7F,0x36,0x00,0x00}, // 0x33
{0x18,0x1C,0x16,0x13,0x7F,0x7F,0x10,0x00}, // 0x34
{0x27,0x67,0x45,0x45,0x7D,0x39,0x00,0x00}, // 0x35
{0x3C,0x7E,0x4B,0x49,0x79,0x30,0x00,0x00}, // 0x36
{0x03,0x63,0x71,0x19,0x0F,0x07,0x00,0x00}, // 0x37
{0x36,0x7F,0x49,0x49,0x7F,0x36,0x00,0x00}, // 0x38
{0x06,0x4F,0x49,0x69,0x3F,0x1E,0x00,0x00}, // 0x39
{0x00,0x00,0x6C,0x6C,0x00,0x00,0x00,0x00}, // 0x3A
{0x00,0xA0,0xEC,0x6C,0x00,0x00,0x00,0x00}, // 0x3B
{0x08,0x1C,0x36,0x63,0x41,0x00,0x00,0x00}, // 0x3C
{0x14,0x14,0x14,0x14,0x14,0x14,0x00,0x00}, // 0x3D
{0x00,0x41,0x63,0x36,0x1C,0x08,0x00,0x00}, // 0x3E
{0x02,0x03,0x51,0x59,0x0F,0x06,0x00,0x00}, // 0x3F
{0x3E,0x7F,0x41,0x5D,0x5D,0x1F,0x1E,0x00}, // 0x40
{0x7C,0x7E,0x13,0x13,0x7E,0x7C,0x00,0x00}, // 0x41
{0x41,0x7F,0x7F,0x49,0x49,0x7F,0x36,0x00}, // 0x42
{0x1C,0x3E,0x63,0x41,0x41,0x63,0x22,0x00}, // 0x43
{0x41,0x7F,0x7F,0x41,0x63,0x7F,0x1C,0x00}, // 0x44
{0x41,0x7F,0x7F,0x49,0x5D,0x41,0x63,0x00}, // 0x45
{0x41,0x7F,0x7F,0x49,0x1D,0x01,0x03,0x00}, // 0x46
{0x1C,0x3E,0x63,0x41,0x51,0x73,0x72,0x00}, // 0x47
{0x7F,0x7F,0x08,0x08,0x7F,0x7F,0x00,0x00}, // 0x48
{0x00,0x41,0x7F,0x7F,0x41,0x00,0x00,0x00}, // 0x49
{0x30,0x70,0x40,0x41,0x7F,0x3F,0x01,0x00}, // 0x4A
{0x41,0x7F,0x7F,0x08,0x1C,0x77,0x63,0x00}, // 0x4B
{0x41,0x7F,0x7F,0x41,0x40,0x60,0x70,0x00}, // 0x4C
{0x7F,0x7F,0x06,0x0C,0x06,0x7F,0x7F,0x00}, // 0x4D
{0x7F,0x7F,0x06,0x0C,0x18,0x7F,0x7F,0x00}, // 0x4E
{0x1C,0x3E,0x63,0x41,0x63,0x3E,0x1C,0x00}, // 0x4F
{0x41,0x7F,0x7F,0x49,0x09,0x0F,0x06,0x00}, // 0x50
{0x1E,0x3F,0x21,0x71,0x7F,0x5E,0x00,0x00}, // 0x51
{0x41,0x7F,0x7F,0x19,0x39,0x6F,0x46,0x00}, // 0x52
{0x26,0x67,0x4D,0x59,0x7B,0x32,0x00,0x00}, // 0x53
{0x03,0x41,0x7F,0x7F,0x41,0x03,0x00,0x00}, // 0x54
{0x7F,0x7F,0x40,0x40,0x7F,0x7F,0x00,0x00}, // 0x55
{0x1F,0x3F,0x60,0x60,0x3F,0x1F,0x00,0x00}, // 0x56
{0x7F,0x7F,0x30,0x18,0x30,0x7F,0x7F,0x00}, // 0x57
{0x63,0x77,0x1C,0x08,0x1C,0x77,0x63,0x00}, // 0x58
{0x07,0x4F,0x78,0x78,0x4F,0x07,0x00,0x00}, // 0x59
{0x67,0x73,0x59,0x4D,0x47,0x63,0x71,0x00}, // 0x5A
{0x00,0x7F,0x7F,0x41,0x41,0x00,0x00,0x00}, // 0x5B
{0x01,0x03,0x06,0x0C,0x18,0x30,0x60,0x00}, // 0x5C
{0x00,0x41,0x41,0x7F,0x7F,0x00,0x00,0x00}, // 0x5D
{0x08,0x0C,0x06,0x03,0x06,0x0C,0x08,0x00}, // 0x5E
{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80}, // 0x5F
{0x00,0x00,0x03,0x07,0x04,0x00,0x00,0x00}, // 0x60
{0x20,0x74,0x54,0x54,0x3C,0x78,0x40,0x00}, // 0x61
{0x41,0x3F,0x7F,0x44,0x44,0x7C,0x38,0x00}, // 0x62
{0x38,0x7C,0x44,0x44,0x6C,0x28,0x00,0x00}, // 0x63
{0x30,0x78,0x48,0x49,0x3F,0x7F,0x40,0x00}, // 0x64
{0x38,0x7C,0x54,0x54,0x5C,0x18,0x00,0x00}, // 0x65
{0x48,0x7E,0x7F,0x49,0x03,0x02,0x00,0x00}, // 0x66
{0x98,0xBC,0xA4,0xA4,0xF8,0x7C,0x04,0x00}, // 0x67
{0x41,0x7F,0x7F,0x08,0x04,0x7C,0x78,0x00}, // 0x68
{0x00,0x44,0x7D,0x7D,0x40,0x00,0x00,0x00}, // 0x69
{0x40,0xC4,0x84,0xFD,0x7D,0x00,0x00,0x00}, // 0x6A
{0x41,0x7F,0x7F,0x10,0x38,0x6C,0x44,0x00}, // 0x6B
{0x00,0x41,0x7F,0x7F,0x40,0x00,0x00,0x00}, // 0x6C
{0x7C,0x7C,0x0C,0x18,0x0C,0x7C,0x78,0x00}, // 0x6D
{0x7C,0x7C,0x04,0x04,0x7C,0x78,0x00,0x00}, // 0x6E
{0x38,0x7C,0x44,0x44,0x7C,0x38,0x00,0x00}, // 0x6F
{0x84,0xFC,0xF8,0xA4,0x24,0x3C,0x18,0x00}, // 0x70
{0x18,0x3C,0x24,0xA4,0xF8,0xFC,0x84,0x00}, // 0x71
{0x44,0x7C,0x78,0x44,0x1C,0x18,0x00,0x00}, // 0x72
{0x48,0x5C,0x54,0x54,0x74,0x24,0x00,0x00}, // 0x73
{0x00,0x04,0x3E,0x7F,0x44,0x24,0x00,0x00}, // 0x74
{0x3C,0x7C,0x40,0x40,0x3C,0x7C,0x40,0x00}, // 0x75
{0x1C,0x3C,0x60,0x60,0x3C,0x1C,0x00,0x00}, // 0x76
{0x3C,0x7C,0x60,0x30,0x60,0x7C,0x3C,0x00}, // 0x77
{0x44,0x6C,0x38,0x10,0x38,0x6C,0x44,0x00}, // 0x78
{0x9C,0xBC,0xA0,0xA0,0xFC,0x7C,0x00,0x00}, // 0x79
{0x4C,0x64,0x74,0x5C,0x4C,0x64,0x00,0x00}, // 0x7A
{0x08,0x08,0x3E,0x77,0x41,0x41,0x00,0x00}, // 0x7B
{0x00,0x00,0x00,0x77,0x77,0x00,0x00,0x00}, // 0x7C
{0x41,0x41,0x77,0x3E,0x08,0x08,0x00,0x00}, // 0x7D
{0x02,0x03,0x01,0x03,0x02,0x03,0x01,0x00}, // 0x7E
{0x78,0x7C,0x46,0x43,0x46,0x7C,0x78,0x00}, // 0x7F
{0x1E,0xBF,0xE1,0x61,0x33,0x12,0x00,0x00}, // 0x80
{0x3A,0x7A,0x40,0x40,0x7A,0x7A,0x40,0x00}, // 0x81
{0x38,0x7C,0x56,0x57,0x5D,0x18,0x00,0x00}, // 0x82
{0x02,0x23,0x75,0x55,0x55,0x7D,0x7B,0x42}, // 0x83
{0x21,0x75,0x54,0x54,0x7D,0x79,0x40,0x00}, // 0x84
{0x20,0x75,0x57,0x56,0x7C,0x78,0x40,0x00}, // 0x85
{0x00,0x22,0x77,0x55,0x55,0x7F,0x7A,0x40}, // 0x86
{0x1C,0xBE,0xE2,0x62,0x36,0x14,0x00,0x00}, // 0x87
{0x02,0x3B,0x7D,0x55,0x55,0x5D,0x1B,0x02}, // 0x88
{0x39,0x7D,0x54,0x54,0x5D,0x19,0x00,0x00}, // 0x89
{0x38,0x7D,0x57,0x56,0x5C,0x18,0x00,0x00}, // 0x8A
{0x01,0x45,0x7C,0x7C,0x41,0x01,0x00,0x00}, // 0x8B
{0x02,0x03,0x45,0x7D,0x7D,0x43,0x02,0x00}, // 0x8C
{0x00,0x45,0x7F,0x7E,0x40,0x00,0x00,0x00}, // 0x8D
{0x79,0x7D,0x26,0x26,0x7D,0x79,0x00,0x00}, // 0x8E
{0x70,0x7A,0x2D,0x2D,0x7A,0x70,0x00,0x00}, // 0x8F
{0x44,0x7C,0x7E,0x57,0x55,0x44,0x00,0x00}, // 0x90
{0x20,0x74,0x54,0x54,0x7C,0x7C,0x54,0x54}, // 0x91
{0x7C,0x7E,0x0B,0x09,0x7F,0x7F,0x49,0x00}, // 0x92
{0x32,0x7B,0x49,0x49,0x7B,0x32,0x00,0x00}, // 0x93
{0x32,0x7A,0x48,0x48,0x7A,0x32,0x00,0x00}, // 0x94
{0x30,0x79,0x4B,0x4A,0x78,0x30,0x00,0x00}, // 0x95
{0x3A,0x7B,0x41,0x41,0x7B,0x7A,0x40,0x00}, // 0x96
{0x38,0x79,0x43,0x42,0x78,0x78,0x40,0x00}, // 0x97
{0xBA,0xBA,0xA0,0xA0,0xFA,0x7A,0x00,0x00}, // 0x98
{0x39,0x7D,0x44,0x44,0x44,0x7D,0x39,0x00}, // 0x99
{0x3D,0x7D,0x40,0x40,0x7D,0x3D,0x00,0x00}, // 0x9A
{0x38,0x7C,0x64,0x54,0x4C,0x7C,0x38,0x00}, // 0x9B
{0x68,0x7E,0x7F,0x49,0x43,0x66,0x20,0x00}, // 0x9C
{0x5C,0x3E,0x73,0x49,0x67,0x3E,0x1D,0x00}, // 0x9D
{0x44,0x6C,0x38,0x38,0x6C,0x44,0x00,0x00}, // 0x9E
{0x40,0xC8,0x88,0xFE,0x7F,0x09,0x0B,0x02}, // 0x9F
{0x20,0x74,0x56,0x57,0x7D,0x78,0x40,0x00}, // 0xA0
{0x00,0x44,0x7E,0x7F,0x41,0x00,0x00,0x00}, // 0xA1
{0x30,0x78,0x48,0x4A,0x7B,0x31,0x00,0x00}, // 0xA2
{0x38,0x78,0x40,0x42,0x7B,0x79,0x40,0x00}, // 0xA3
{0x7A,0x7B,0x09,0x0B,0x7A,0x73,0x01,0x00}, // 0xA4
{0x7A,0x7B,0x19,0x33,0x7A,0x7B,0x01,0x00}, // 0xA5
{0x00,0x26,0x2F,0x29,0x2F,0x2F,0x28,0x00}, // 0xA6
{0x00,0x26,0x2F,0x29,0x29,0x2F,0x26,0x00}, // 0xA7
{0x30,0x78,0x4D,0x45,0x60,0x20,0x00,0x00}, // 0xA8
{0x1C,0x22,0x7D,0x4B,0x5B,0x65,0x22,0x1C}, // 0xA9
{0x08,0x08,0x08,0x08,0x38,0x38,0x00,0x00}, // 0xAA
{0x61,0x3F,0x1F,0xCC,0xEE,0xAB,0xB9,0x90}, // 0xAB
{0x61,0x3F,0x1F,0x4C,0x66,0x73,0xD9,0xF8}, // 0xAC
{0x00,0x00,0x60,0xFA,0xFA,0x60,0x00,0x00}, // 0xAD
{0x08,0x1C,0x36,0x22,0x08,0x1C,0x36,0x22}, // 0xAE
{0x22,0x36,0x1C,0x08,0x22,0x36,0x1C,0x08}, // 0xAF
{0xAA,0x00,0x55,0x00,0xAA,0x00,0x55,0x00}, // 0xB0
{0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55}, // 0xB1
{0x55,0xFF,0xAA,0xFF,0x55,0xFF,0xAA,0xFF}, // 0xB2
{0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00}, // 0xB3
{0x10,0x10,0x10,0xFF,0xFF,0x00,0x00,0x00}, // 0xB4
{0x70,0x78,0x2C,0x2E,0x7B,0x71,0x00,0x00}, // 0xB5
{0x72,0x79,0x2D,0x2D,0x79,0x72,0x00,0x00}, // 0xB6
{0x71,0x7B,0x2E,0x2C,0x78,0x70,0x00,0x00}, // 0xB7
{0x1C,0x22,0x5D,0x55,0x55,0x41,0x22,0x1C}, // 0xB8
{0x14,0x14,0xF7,0xF7,0x00,0xFF,0xFF,0x00}, // 0xB9
{0x00,0x00,0xFF,0xFF,0x00,0xFF,0xFF,0x00}, // 0xBA
{0x14,0x14,0xF4,0xF4,0x04,0xFC,0xFC,0x00}, // 0xBB
{0x14,0x14,0x17,0x17,0x10,0x1F,0x1F,0x00}, // 0xBC
{0x18,0x3C,0x24,0xE7,0xE7,0x24,0x24,0x00}, // 0xBD
{0x2B,0x2F,0xFC,0xFC,0x2F,0x2B,0x00,0x00}, // 0xBE
{0x10,0x10,0x10,0xF0,0xF0,0x00,0x00,0x00}, // 0xBF
{0x00,0x00,0x00,0x1F,0x1F,0x10,0x10,0x10}, // 0xC0
{0x10,0x10,0x10,0x1F,0x1F,0x10,0x10,0x10}, // 0xC1
{0x10,0x10,0x10,0xF0,0xF0,0x10,0x10,0x10}, // 0xC2
{0x00,0x00,0x00,0xFF,0xFF,0x10,0x10,0x10}, // 0xC3
{0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10}, // 0xC4
{0x10,0x10,0x10,0xFF,0xFF,0x10,0x10,0x10}, // 0xC5
{0x22,0x77,0x55,0x57,0x7E,0x7B,0x41,0x00}, // 0xC6
{0x72,0x7B,0x2D,0x2F,0x7A,0x73,0x01,0x00}, // 0xC7
{0x00,0x00,0x1F,0x1F,0x10,0x17,0x17,0x14}, // 0xC8
{0x00,0x00,0xFC,0xFC,0x04,0xF4,0xF4,0x14}, // 0xC9
{0x14,0x14,0x17,0x17,0x10,0x17,0x17,0x14}, // 0xCA
{0x14,0x14,0xF4,0xF4,0x04,0xF4,0xF4,0x14}, // 0xCB
{0x00,0x00,0xFF,0xFF,0x00,0xF7,0xF7,0x14}, // 0xCC
{0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14}, // 0xCD
{0x14,0x14,0xF7,0xF7,0x00,0xF7,0xF7,0x14}, // 0xCE
{0x66,0x3C,0x3C,0x24,0x3C,0x3C,0x66,0x00}, // 0xCF
{0x05,0x27,0x72,0x57,0x7D,0x38,0x00,0x00}, // 0xD0
{0x49,0x7F,0x7F,0x49,0x63,0x7F,0x1C,0x00}, // 0xD1
{0x46,0x7D,0x7D,0x55,0x55,0x46,0x00,0x00}, // 0xD2
{0x45,0x7D,0x7C,0x54,0x55,0x45,0x00,0x00}, // 0xD3
{0x44,0x7D,0x7F,0x56,0x54,0x44,0x00,0x00}, // 0xD4
{0x0A,0x0E,0x08,0x00,0x00,0x00,0x00,0x00}, // 0xD5
{0x00,0x44,0x7E,0x7F,0x45,0x00,0x00,0x00}, // 0xD6
{0x02,0x45,0x7D,0x7D,0x45,0x02,0x00,0x00}, // 0xD7
{0x01,0x45,0x7C,0x7C,0x45,0x01,0x00,0x00}, // 0xD8
{0x10,0x10,0x10,0x1F,0x1F,0x00,0x00,0x00}, // 0xD9
{0x00,0x00,0x00,0xF0,0xF0,0x10,0x10,0x10}, // 0xDA
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, // 0xDB
{0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0}, // 0xDC
{0x00,0x00,0x00,0x77,0x77,0x00,0x00,0x00}, // 0xDD
{0x00,0x45,0x7F,0x7E,0x44,0x00,0x00,0x00}, // 0xDE
{0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F}, // 0xDF
{0x38,0x7C,0x46,0x47,0x45,0x7C,0x38,0x00}, // 0xE0
{0xFC,0xFE,0x2A,0x2A,0x3E,0x14,0x00,0x00}, // 0xE1
{0x3A,0x7D,0x45,0x45,0x45,0x7D,0x3A,0x00}, // 0xE2
{0x38,0x7C,0x45,0x47,0x46,0x7C,0x38,0x00}, // 0xE3
{0x32,0x7B,0x49,0x4B,0x7A,0x33,0x01,0x00}, // 0xE4
{0x3A,0x7F,0x45,0x47,0x46,0x7F,0x39,0x00}, // 0xE5
{0x80,0xFE,0x7E,0x20,0x20,0x3E,0x1E,0x00}, // 0xE6
{0x42,0x7E,0x7E,0x54,0x1C,0x08,0x00,0x00}, // 0xE7
{0x41,0x7F,0x7F,0x55,0x14,0x1C,0x08,0x00}, // 0xE8
{0x3C,0x7C,0x42,0x43,0x7D,0x3C,0x00,0x00}, // 0xE9
{0x3A,0x79,0x41,0x41,0x79,0x3A,0x00,0x00}, // 0xEA
{0x3C,0x7D,0x43,0x42,0x7C,0x3C,0x00,0x00}, // 0xEB
{0xB8,0xB8,0xA2,0xA3,0xF9,0x78,0x00,0x00}, // 0xEC
{0x0C,0x5C,0x72,0x73,0x5D,0x0C,0x00,0x00}, // 0xED
{0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00}, // 0xEE
{0x00,0x00,0x02,0x03,0x01,0x00,0x00,0x00}, // 0xEF
{0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00}, // 0xF0
{0x44,0x44,0x5F,0x5F,0x44,0x44,0x00,0x00}, // 0xF1
{0x28,0x28,0x28,0x28,0x28,0x28,0x00,0x00}, // 0xF2
{0x71,0x35,0x1F,0x4C,0x66,0x73,0xD9,0xF8}, // 0xF3
{0x06,0x0F,0x09,0x7F,0x7F,0x01,0x7F,0x7F}, // 0xF4
{0xDA,0xBF,0xA5,0xA5,0xFD,0x59,0x03,0x02}, // 0xF5
{0x08,0x08,0x6B,0x6B,0x08,0x08,0x00,0x00}, // 0xF6
{0x00,0x80,0xC0,0x40,0x00,0x00,0x00,0x00}, // 0xF7
{0x00,0x06,0x0F,0x09,0x0F,0x06,0x00,0x00}, // 0xF8
{0x02,0x02,0x00,0x00,0x02,0x02,0x00,0x00}, // 0xF9
{0x00,0x00,0x00,0x10,0x10,0x00,0x00,0x00}, // 0xFA
{0x00,0x12,0x13,0x1F,0x1F,0x10,0x10,0x00}, // 0xFB
{0x00,0x11,0x15,0x15,0x1F,0x1F,0x0A,0x00}, // 0xFC
{0x00,0x19,0x1D,0x15,0x17,0x12,0x00,0x00}, // 0xFD
{0x00,0x00,0x3C,0x3C,0x3C,0x3C,0x00,0x00}, // 0xFE
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} // 0xFF
};
#endif //FONT_H

View File

@ -0,0 +1,259 @@
/*
* Created: 19.06.2016 11:38:00
* Author: Ulrich
* From: https://www.ulrichradig.de/home/index.php/avr/oled-display-ssd1306
*/
#include "oled_ssd1306.h"
#include "font.h"
static uint8_t oled_x = 0, oled_y = 0, font_size = 0;
const uint8_t ssd1306_init_cmd [] PROGMEM = {
SET_DISPLAY_OFF,
COMMAND_NO_OPERATION,
SET_MEMORY_ADDR_MODE, HORIZONTAL_ADDRESSING_MODE,
SET_PAGE_START,
SET_COM_OUTPUT_REMAPPED,
SET_LOWER_COLUMN,
SET_HIGHER_COLUMN,
SET_DISPLAY_START_LINE,
ENTIRE_DISPLAY_ON,
SET_SEGMENT_REMAP_O2,
SET_DISPLAY_NORMAL,
SET_CONTRAST_CONTROL, 0xFF,
SET_MULTIPLEX_RATIO, 0x3F,
SET_DISPLAY_OFFSET, 0x00,
SET_DISPLAY_CLOCK, 0xF0,
SET_PRECHARGE_PERIOD, 0x22,
SET_COM_PINS, 0x12,
SET_VCOMH_DESELECT, 0x20,
CHARGE_BUMB_SETTING, 0x14,
SET_DISPLAY_ON };
oled_ssd1306::oled_ssd1306(){
}
oled_ssd1306::~oled_ssd1306(){
}
//***************************************************************************************
void oled_ssd1306::i2c_init(void){
I2C_PORT |= (1 << SDA_PIN | 1 << SCL_PIN); //Port Pullup
TWCR = 0;
TWSR = 0;
TWBR = ((F_CPU/SCL_CLOCK)-16)/2;
_delay_ms(50);
}
//***************************************************************************************
uint8_t oled_ssd1306::i2c_start (void){
uint8_t timeout = 0;
TWCR = (1 << TWINT | 1 << TWSTA | 1 << TWEN);
while(!(TWCR & (1<<TWINT))){
if((timeout++) > 100) return 1;
}
TWDR = OLED_I2C_ADDR;
TWCR = (1 << TWINT | 1 << TWEN);
timeout = 0;
while(!(TWCR & (1<<TWINT))){
if((timeout++) > 100) return 1;
}
return 0;
}
//***************************************************************************************
uint8_t oled_ssd1306::i2c_byte (uint8_t byte){
uint8_t timeout = 0;
TWDR = byte;
TWCR = (1 << TWINT | 1 << TWEN);
while(!(TWCR & (1<<TWINT))){
if((timeout++) > 100) return 1;
}
return 0;
}
//***************************************************************************************
void oled_ssd1306::i2c_stop (void){
TWCR = (1 << TWINT | 1 << TWSTO | 1 << TWEN);
TWCR = 0;
}
//***************************************************************************************
void oled_ssd1306::oled_init (void){
i2c_init();
i2c_start();
i2c_byte(COMMAND);
for (uint8_t tmp = 0; tmp< sizeof(ssd1306_init_cmd); tmp++) {
i2c_byte(pgm_read_byte(&ssd1306_init_cmd[tmp]));
}
i2c_stop();
oled_clear_screen();
}
//***************************************************************************************
void oled_ssd1306::oled_clear_screen (void){
oled_gotoxy(0,0);
i2c_start();
i2c_byte(DATA);
for (uint16_t i = 0; i < 128<<4 ; i++) { // 128 * (64 / Byte)
i2c_byte(0);
}
i2c_stop();
oled_gotoxy(0,0);
}
//***************************************************************************************
void oled_ssd1306::oled_gotoxy (uint8_t x, uint8_t y){
oled_x = x;
oled_y = y;
i2c_start();
i2c_byte(COMMAND);
i2c_byte(SET_PAGE_START|y);
i2c_byte(SET_COLUMN_ADDRESS);
i2c_byte(x * 8);
i2c_byte(SET_DISPLAY_START_LINE|0x3F);
i2c_stop();
}
//***************************************************************************************
void oled_ssd1306::oled_font_size (uint8_t byte){
font_size = byte;
}
//***************************************************************************************
void oled_ssd1306::oled_write_char (char c){
if(font_size != 0){
uint8_t tmp = 0;
oled_gotoxy(oled_x,oled_y);
i2c_start();
i2c_byte(DATA);
for (uint8_t count = 0; count < 8; count++){
tmp = pgm_read_byte(&font[(unsigned char)c][count]);
tmp = tmp & 0x0f;
tmp = ((tmp&0x01)*3)+(((tmp&0x02)<<1)*3)+(((tmp&0x04)<<2)*3)+(((tmp&0x08)<<3)*3);
i2c_byte(tmp);
i2c_byte(tmp);
}
i2c_stop();
oled_gotoxy(oled_x,oled_y + 1);
i2c_start();
i2c_byte(DATA);
for (uint8_t count = 0; count < 8; count++){
tmp = pgm_read_byte(&font[(unsigned char)c][count]);
tmp = (tmp & 0xf0)>>4;
tmp = ((tmp&0x01)*3)+(((tmp&0x02)<<1)*3)+(((tmp&0x04)<<2)*3)+(((tmp&0x08)<<3)*3);
i2c_byte(tmp);
i2c_byte(tmp);
}
i2c_stop();
oled_x +=2;
oled_y -=1;
}else{
oled_gotoxy(oled_x,oled_y);
i2c_start();
i2c_byte(DATA);
for (uint8_t count = 0; count < 8; count++){
i2c_byte(pgm_read_byte(&font[(unsigned char)c][count]));
}
i2c_stop();
oled_x +=1;
}
}
//***************************************************************************************
void oled_ssd1306::oled_write_str (char* str){
while (*str) {
oled_write_char(*str++);
}
}
//***************************************************************************************
void oled_ssd1306::oled_write_P (const char *Buffer,...)
{
va_list ap;
va_start (ap, Buffer);
int format_flag;
char str_buffer[10];
char str_null_buffer[10];
char move = 0;
char Base = 0;
int tmp = 0;
char by;
char *ptr;
//Ausgabe der Zeichen
for(;;){
by = pgm_read_byte(Buffer++);
if(by==0) break; // end of format string
if (by == '%'){
by = pgm_read_byte(Buffer++);
if (isdigit(by)>0){
str_null_buffer[0] = by;
str_null_buffer[1] = '\0';
move = atoi(str_null_buffer);
by = pgm_read_byte(Buffer++);
}
switch (by){
case 's':
ptr = va_arg(ap,char *);
while(*ptr) { oled_write_char(*ptr++); }
break;
case 'b':
Base = 2;
goto ConversionLoop;
case 'c':
//Int to char
format_flag = va_arg(ap,int);
oled_write_char (format_flag++);
break;
case 'i':
Base = 10;
goto ConversionLoop;
case 'o':
Base = 8;
goto ConversionLoop;
case 'x':
Base = 16;
//****************************
ConversionLoop:
//****************************
itoa(va_arg(ap,int),str_buffer,Base);
int b=0;
while (str_buffer[b++] != 0){};
b--;
if (b<move){
move -=b;
for (tmp = 0;tmp<move;tmp++){
str_null_buffer[tmp] = '0';
}
//tmp ++;
str_null_buffer[tmp] = '\0';
strcat(str_null_buffer,str_buffer);
strcpy(str_buffer,str_null_buffer);
}
oled_write_str (str_buffer);
move =0;
break;
}
}else{
oled_write_char (by);
}
}
va_end(ap);
}

View File

@ -0,0 +1,108 @@
/*
* Created: 19.06.2016 11:38:00
* Author: Ulrich
* From: https://www.ulrichradig.de/home/index.php/avr/oled-display-ssd1306
*/
#ifndef __oled_H
#define __oled_H
#define ROTATE
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include <util/delay.h>
#define SDA_PIN PC4
#define SCL_PIN PC5
#define I2C_PORT PORTC
#define OLED_I2C_ADDR 0x78
#define SCL_CLOCK 400000UL
class oled_ssd1306 {
private:
void i2c_init(void);
uint8_t i2c_start(void);
uint8_t i2c_byte(uint8_t byte);
void i2c_stop(void);
public:
oled_ssd1306();
~oled_ssd1306();
void oled_write_char(char c);
void oled_write_str(char* str);
void oled_write_P(const char *Buffer, ...);
void oled_init(void);
void oled_clear_screen(void);
void oled_font_size(uint8_t byte);
void oled_gotoxy(uint8_t x, uint8_t y);
};
#define oled_write(format, args...) oled_write_P(PSTR(format) , ## args)
#define COMMAND 0x00
#define DATA 0x40
#define SET_CONTRAST_CONTROL 0x81
#define SET_DISPLAY_ON 0xAF
#define SET_DISPLAY_OFF 0xAE
#define SET_DISPLAY_NORMAL 0xA6
#define SET_DISPLAY_INVERSE 0xA7
#define ENTIRE_DISPLAY_ON 0xA4
#define SET_MEMORY_ADDR_MODE 0x20
#define HORIZONTAL_ADDRESSING_MODE 0x00
#define VERTICAL_ADDRESSING_MODE 0x01
#define PAGE_ADDRESSING_MODE 0x02
#define SET_PAGE_START 0xB0 //~0xB7
#define SET_COLUMN_ADDRESS 0x21
#define SET_PAGE_ADDRESS 0x22
#ifdef ROTATE
#define SET_COM_OUTPUT_NORMAL 0xC8
#define SET_COM_OUTPUT_REMAPPED 0xC0
#endif
#ifndef ROTATE
#define SET_COM_OUTPUT_NORMAL 0xC0
#define SET_COM_OUTPUT_REMAPPED 0xC8
#endif
#define SET_DISPLAY_OFFSET 0xD3
#define SET_DISPLAY_CLOCK 0xD5
#define SET_PRECHARGE_PERIOD 0xD9
#define SET_COM_PINS 0xDA
#define SET_VCOMH_DESELECT 0xDB //0x00,0x20,0x30
#define SET_LOWER_COLUMN 0x00
#define SET_HIGHER_COLUMN 0x10
#define SET_DISPLAY_START_LINE 0x40
#ifdef ROTATE
#define SET_SEGMENT_REMAP_O1 0xA1
#define SET_SEGMENT_REMAP_O2 0xA0
#endif
#ifndef ROTATE
#define SET_SEGMENT_REMAP_O1 0xA0
#define SET_SEGMENT_REMAP_O2 0xA1
#endif
#define SET_MULTIPLEX_RATIO 0xA8
#define COMMAND_NO_OPERATION 0xE3
#define CHARGE_BUMB_SETTING 0x8D
#endif // __oled_H

View File

@ -12,6 +12,7 @@
#include "multiplexer.h"
#include "clock.h"
#include "charger.h"
#include "oled_ssd1306/oled_ssd1306.h"