Skip to content

Commit

Permalink
Added character set and string handling (thanks dmadison and hans-jorg:
Browse files Browse the repository at this point in the history
dmadison/LED-Segment-ASCII#2)

TODO: change it to use PGM instead of SRAM.
  • Loading branch information
libesz committed Jan 26, 2019
1 parent 3fa8804 commit 7d1ebc5
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 3 deletions.
133 changes: 133 additions & 0 deletions AvrCppBaseLib/display/7-Segment-ASCII_SYM.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Project Segmented LED Display - ASCII Library
* @author David Madison
* @link github.com/dmadison/Segmented-LED-Display-ASCII
* @license MIT - Copyright (c) 2017 David Madison
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#include <stdint.h>
#define _DP 0x80
#define _G 0x1
#define _F 0x2
#define _E 0x4
#define _D 0x8
#define _C 0x10
#define _B 0x20
#define _A 0x40

const uint8_t SevenSegmentASCII[96] = {
0 , /* (space) */
_DP |_C |_B , /* ! */
_F |_B , /* " */
_G |_F |_E |_D |_C |_B , /* # */
_G |_F |_D |_C |_A , /* $ */
_DP|_G |_E |_B , /* % */
_G |_C |_B , /* & */
_F , /* ' */
_F |_D |_A , /* ( */
_D |_B |_A , /* ) */
_F |_A , /* * */
_G |_F |_E , /* + */
_E , /* , */
_G , /* - */
_DP , /* . */
_G |_E |_B , /* / */
_F |_E |_D |_C |_B |_A , /* 0 */
_C |_B , /* 1 */
_G |_E |_D |_B |_A , /* 2 */
_G |_D |_C |_B |_A , /* 3 */
_G |_F |_C |_B , /* 4 */
_G |_F |_D |_C |_A , /* 5 */
_G |_F |_E |_D |_C |_A , /* 6 */
_C |_B |_A , /* 7 */
_G |_F |_E |_D |_C |_B |_A , /* 8 */
_G |_F |_D |_C |_B |_A , /* 9 */
_D |_A , /* : */
_D |_C |_A , /* ; */
_G |_F |_A , /* < */
_G |_D , /* = */
_G |_B |_A , /* > */
_DP|_G |_E |_B |_A , /* ? */
_G |_E |_D |_C |_B |_A , /* @ */
_G |_F |_E |_C |_B |_A , /* A */
_G |_F |_E |_D |_C , /* B */
_F |_E |_D |_A , /* C */
_G |_E |_D |_C |_B , /* D */
_G |_F |_E |_D |_A , /* E */
_G |_F |_E |_A , /* F */
_F |_E |_D |_C |_A , /* G */
_G |_F |_E |_C |_B , /* H */
_F |_E , /* I */
_E |_D |_C |_B , /* J */
_G |_F |_E |_C |_A , /* K */
_F |_E |_D , /* L */
_E |_C |_A , /* M */
_F |_E |_C |_B |_A , /* N */
_F |_E |_D |_C |_B |_A , /* O */
_G |_F |_E |_B |_A , /* P */
_G |_F |_D |_B |_A , /* Q */
_F |_E |_B |_A , /* R */
_G |_F |_D |_C |_A , /* S */
_G |_F |_E |_D , /* T */
_F |_E |_D |_C |_B , /* U */
_F |_E |_D |_C |_B , /* V */
_F |_D |_B , /* W */
_G |_F |_E |_C |_B , /* X */
_G |_F |_D |_C |_B , /* Y */
_G |_E |_D |_B |_A , /* Z */
_F |_E |_D |_A , /* [ */
_G |_F |_C , /* \ */
_D |_C |_B |_A , /* ] */
_F |_B |_A , /* ^ */
_D , /* _ */
_B , /* ` */
_G |_E |_D |_C |_B |_A , /* a */
_G |_F |_E |_D |_C , /* b */
_G |_E |_D , /* c */
_G |_E |_D |_C |_B , /* d */
_G |_F |_E |_D |_B |_A , /* e */
_G |_F |_E |_A , /* f */
_G |_F |_D |_C |_B |_A , /* g */
_G |_F |_E |_C , /* h */
_E , /* i */
_D |_C , /* j */
_G |_F |_E |_C |_A , /* k */
_F |_E , /* l */
_E |_C , /* m */
_G |_E |_C , /* n */
_G |_E |_D |_C , /* o */
_G |_F |_E |_B |_A , /* p */
_G |_F |_C |_B |_A , /* q */
_G |_E , /* r */
_G |_F |_D |_C |_A , /* s */
_G |_F |_E |_D , /* t */
_E |_D |_C , /* u */
_E |_D |_C , /* v */
_E |_C , /* w */
_G |_F |_E |_C |_B , /* x */
_G |_F |_D |_C |_B , /* y */
_G |_E |_D |_B |_A , /* z */
_G |_C |_B , /* { */
_F |_E , /* | */
_G |_F |_E , /* } */
_A , /* ~ */
0 , /* (del) */
};
12 changes: 10 additions & 2 deletions AvrCppBaseLib/Max7219.cpp → AvrCppBaseLib/display/Max7219.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "Max7219.h"

const uint8_t g_num_faces[10] = {
// abcdefg
//abcdefg
0b1111110,
0b0110000,
0b1101101,
Expand Down Expand Up @@ -91,10 +91,18 @@ void Max7219::setNumber(int32_t number, uint8_t offset, uint8_t dotPlace) {
} while (i<digitsInUse);
}

void Max7219::setRaw(int8_t data, uint8_t offset) {
void Max7219::setRawChar(int8_t data, uint8_t offset) {
content[offset] = data;
}

void Max7219::setString(char *str, uint8_t startAt) {
uint8_t i = 0;
while(((startAt + i) < 8) && i < strlen(str)) {
content[7-(startAt+i)] = SevenSegmentASCII[str[i]-32];
i++;
}
}

void Max7219::spiSendByte(uint8_t databyte) {
// Copy data into the SPI data register
SPDR = databyte;
Expand Down
5 changes: 4 additions & 1 deletion AvrCppBaseLib/Max7219.h → AvrCppBaseLib/display/Max7219.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "CppStubs.h"
#include "SoftTimer.h"

#include "7-Segment-ASCII_SYM.txt"

class Max7219: public SoftTimerHandler {
uint8_t digitsInUse;
uint8_t SsPin;
Expand All @@ -27,7 +29,8 @@ class Max7219: public SoftTimerHandler {
void applyContent();
void clearDisplay();
void setNumber(int32_t newNumber, uint8_t offset = 0, uint8_t newDotPlace = 9);
void setRaw(int8_t data, uint8_t offset = 0);
void setRawChar(int8_t data, uint8_t offset = 0);
void setString(char *str, uint8_t startAt = 0);
};

#endif /* MAX7219_H_ */

0 comments on commit 7d1ebc5

Please sign in to comment.