2017-11-14 19:07:10 +00:00
|
|
|
/*! \file lcdtext.c
|
|
|
|
\brief LCD font and text drawing functions.
|
|
|
|
*/
|
2017-09-24 20:06:59 +00:00
|
|
|
#include "lcd.h"
|
2017-09-24 20:38:14 +00:00
|
|
|
#include "lcdtext.h"
|
2017-09-24 20:06:59 +00:00
|
|
|
|
|
|
|
/* Digits look like this, and we index them with 0 being the
|
|
|
|
leftmost.
|
|
|
|
|
|
|
|
AAAAA
|
|
|
|
F B
|
|
|
|
F B
|
|
|
|
F B
|
|
|
|
GGGGG
|
|
|
|
E C
|
|
|
|
E C
|
|
|
|
E C
|
|
|
|
DDDDD dp
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2017-11-14 19:07:10 +00:00
|
|
|
|
|
|
|
//! This maps the segments of each digit.
|
2017-09-26 13:15:55 +00:00
|
|
|
const int lcdmap[10][8]={
|
2017-11-14 19:07:10 +00:00
|
|
|
// A, B, C, D, E, F, G, dp digit
|
2017-09-24 23:39:23 +00:00
|
|
|
{0x0b04, 0x0b40, 0x0b20, 0x0b01, 0x0a10, 0x0a20, 0x0b02, 0x0b10}, //0
|
|
|
|
{0x0940, 0x0a04, 0x0a02, 0x0910, 0x0901, 0x0902, 0x0920, 0x0a01}, //1
|
|
|
|
{0x0804, 0x0840, 0x0820, 0x0801, 0x0710, 0x0720, 0x0802, 0x0810}, //2
|
|
|
|
{0x0640, 0x0704, 0x0702, 0x0610, 0x0601, 0x0602, 0x0620, 0x0701}, //3
|
|
|
|
{0x0504, 0x0540, 0x0520, 0x0501, 0x0410, 0x0420, 0x0502, 0x0510}, //4
|
|
|
|
{0x0c02, 0x0404, 0x0402, 0x0310, 0x0302, 0x0304, 0x0340, 0x0401}, //5
|
|
|
|
{0x0204, 0x0220, 0x0210, 0x0201, 0x0110, 0x0120, 0x0202, 0x0301}, //6
|
2017-10-02 14:39:50 +00:00
|
|
|
{0x0040, 0x0104, 0x0102, 0x0010, 0x0001, 0x0002, 0x0020, 0x0240}, //7
|
2017-09-24 20:06:59 +00:00
|
|
|
};
|
|
|
|
|
2017-09-26 13:15:55 +00:00
|
|
|
//These are the fragments of the day of the week: 0x0904, 0x0a40, 0x0c01
|
|
|
|
//0x0c10 is beyond the screen.
|
2017-10-02 14:39:50 +00:00
|
|
|
|
|
|
|
//0x0240 seems not to be wired to any visible segment, but we use it
|
|
|
|
//as the rightmost decimal point because we don't seem to have that
|
|
|
|
//cell.
|
2017-09-26 13:15:55 +00:00
|
|
|
|
2017-11-14 19:07:10 +00:00
|
|
|
//! Bit flags for each of the eight segments.
|
2017-09-26 13:15:55 +00:00
|
|
|
enum lcdmappos {A=1, B=2, C=4, D=8, E=0x10, F=0x20, G=0x40, DP=0x80};
|
2017-11-14 19:07:10 +00:00
|
|
|
//! Font for numbers.
|
2017-09-24 23:39:23 +00:00
|
|
|
const int numfont[]={
|
2017-09-24 20:06:59 +00:00
|
|
|
A|B|C|D|E|F, //0
|
|
|
|
B|C, //1
|
|
|
|
A|B|G|E|D, //2
|
|
|
|
A|B|G|C|D, //3
|
|
|
|
F|G|B|C, //4
|
|
|
|
A|F|G|C|D, //5
|
|
|
|
A|F|G|E|C|D, //6
|
|
|
|
A|B|C, //7
|
|
|
|
A|B|C|D|E|F|G, //8
|
|
|
|
A|B|G|F|C|D, //9
|
|
|
|
A|F|B|G|E|C, //A
|
|
|
|
F|E|G|C|D, //B
|
|
|
|
A|F|E|D, //C
|
|
|
|
E|G|C|D|B, //D
|
|
|
|
A|F|E|G|D, //E
|
|
|
|
A|G|F|E //F
|
|
|
|
};
|
2017-11-14 19:07:10 +00:00
|
|
|
//! Font for letters.
|
2017-10-03 18:32:20 +00:00
|
|
|
const int letterfont[]={
|
|
|
|
/* This font begins at 0x41 hex in the ASCII table, rendering
|
|
|
|
letters as best they can be on the 7-segment display.
|
|
|
|
*/
|
|
|
|
A|F|B|G|E|C, //A
|
|
|
|
F|E|G|C|D, //B
|
|
|
|
A|F|E|D, //C
|
|
|
|
E|G|C|D|B, //D
|
|
|
|
A|F|E|G|D, //E
|
|
|
|
A|G|F|E, //F
|
2018-02-07 15:18:30 +00:00
|
|
|
A|F|G|E|C|D, //G
|
2017-10-03 18:32:20 +00:00
|
|
|
F|G|E|C, //h
|
|
|
|
F|E, //I, distinguished from a 1 by being on the left side.
|
|
|
|
E|B|C|D, //J
|
|
|
|
F|E|B|C|G|DP, //K, distinguished from an X by the DP.
|
|
|
|
F|E|D, //L
|
2018-01-31 04:34:27 +00:00
|
|
|
A|E|C, //M (Less nerdy than mu, but more readable.)
|
2017-10-03 18:32:20 +00:00
|
|
|
E|G|C, //n
|
|
|
|
A|B|C|D|E|F, //O
|
|
|
|
F|A|B|G|E, //P
|
|
|
|
F|A|B|C|D|E|DP,//Q
|
2017-11-13 01:58:39 +00:00
|
|
|
E|G, //R
|
2017-10-03 18:32:20 +00:00
|
|
|
A|F|G|C|D, //S (Looks like a 5.)
|
|
|
|
F|E|G, //T
|
|
|
|
F|E|D|C|B, //U
|
|
|
|
F|E|D|C|B, //V (Same as U. Blame Rome.)
|
|
|
|
F|E|D|C|B, //W (Same as U and V. Blame Germany.)
|
|
|
|
F|G|E|B|C, //X
|
|
|
|
F|G|B|E, //Y
|
|
|
|
A|B|G|E|D //Z
|
|
|
|
};
|
2017-09-24 20:06:59 +00:00
|
|
|
|
2017-11-14 19:07:10 +00:00
|
|
|
//! Sets a pixel.
|
2017-09-24 20:06:59 +00:00
|
|
|
#define DRAWPOINT(todraw) lcdm[todraw>>8]|=todraw&0xFF
|
2017-11-14 19:07:10 +00:00
|
|
|
//! Clears a pixel.
|
2017-09-26 13:27:38 +00:00
|
|
|
#define CLEARPOINT(todraw) lcdm[todraw>>8]&=~(todraw&0xFF)
|
|
|
|
|
2017-10-02 14:39:50 +00:00
|
|
|
|
2017-09-24 20:38:14 +00:00
|
|
|
//! Draws one LCD digit.
|
2017-09-24 20:06:59 +00:00
|
|
|
void lcd_digit(int pos, int digit){
|
|
|
|
int segments=numfont[digit];
|
2017-09-24 20:38:14 +00:00
|
|
|
int bit;
|
2017-09-24 20:06:59 +00:00
|
|
|
for(bit=0;bit<8;bit++){
|
2017-09-26 13:27:38 +00:00
|
|
|
if(segments&(1<<bit))
|
2017-09-26 13:15:55 +00:00
|
|
|
DRAWPOINT(lcdmap[pos][bit]);
|
2017-09-26 13:27:38 +00:00
|
|
|
else
|
|
|
|
CLEARPOINT(lcdmap[pos][bit]);
|
2017-09-24 20:06:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-16 19:23:52 +00:00
|
|
|
|
2017-10-03 18:32:20 +00:00
|
|
|
//! Draws one LCD character
|
|
|
|
void lcd_char(int pos, char c){
|
|
|
|
int segments;//=numfont[digit];
|
|
|
|
int bit;
|
|
|
|
|
|
|
|
//Numbers handled by another function until we unify the font.
|
|
|
|
if(c>='0' && c<='9'){
|
|
|
|
lcd_digit(pos, c&0x0F);
|
|
|
|
return;
|
2017-11-13 02:14:08 +00:00
|
|
|
}else if(c==' '){
|
|
|
|
lcd_cleardigit(pos);
|
|
|
|
return;
|
2017-12-03 03:49:33 +00:00
|
|
|
}else if(c=='.'){
|
|
|
|
lcd_cleardigit(pos);
|
|
|
|
setperiod(pos,1);
|
|
|
|
return;
|
2017-10-03 18:32:20 +00:00
|
|
|
}
|
2017-12-03 03:49:33 +00:00
|
|
|
|
2017-10-03 18:32:20 +00:00
|
|
|
c&=~0x20;
|
|
|
|
segments=letterfont[c-'A'];
|
|
|
|
|
|
|
|
for(bit=0;bit<8;bit++){
|
|
|
|
if(segments&(1<<bit))
|
|
|
|
DRAWPOINT(lcdmap[pos][bit]);
|
|
|
|
else
|
|
|
|
CLEARPOINT(lcdmap[pos][bit]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-14 19:07:10 +00:00
|
|
|
//! Clears one LCD digit.
|
2017-09-27 23:26:17 +00:00
|
|
|
void lcd_cleardigit(int pos){
|
2017-09-27 23:09:17 +00:00
|
|
|
int bit;
|
|
|
|
for(bit=0;bit<8;bit++)
|
|
|
|
CLEARPOINT(lcdmap[pos][bit]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-03 18:32:20 +00:00
|
|
|
//! Draws a string to the LCD.
|
2017-11-16 02:33:13 +00:00
|
|
|
void lcd_string(const char *str){
|
2017-10-03 18:32:20 +00:00
|
|
|
int i=7;//LCD position.
|
|
|
|
while(i>=0 && *str){
|
|
|
|
lcd_char(i--, *str++);
|
|
|
|
}
|
|
|
|
}
|
2017-09-24 20:06:59 +00:00
|
|
|
|
2017-09-24 20:21:15 +00:00
|
|
|
//! Draws a decimal number on the screen.
|
|
|
|
void lcd_number(long num){
|
2017-09-26 16:59:02 +00:00
|
|
|
static long bcd=0;
|
|
|
|
static long oldnum=0;
|
2017-09-24 20:21:15 +00:00
|
|
|
int i;
|
2017-09-26 16:59:02 +00:00
|
|
|
|
|
|
|
/* This conversion takes too long at 32kHz, so we cache the last
|
|
|
|
value for rendering. */
|
|
|
|
if(oldnum==num){
|
|
|
|
lcd_hex(bcd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise we convert it with expensive divisions. */
|
|
|
|
bcd=0;
|
2017-09-27 19:22:41 +00:00
|
|
|
oldnum=num;
|
2017-09-26 16:59:02 +00:00
|
|
|
for(i=0;i<8 && num;i++){
|
2017-09-24 20:21:15 +00:00
|
|
|
bcd|=((num%10)<<(4*i));
|
|
|
|
num/=10;
|
|
|
|
}
|
2017-09-26 16:59:02 +00:00
|
|
|
|
2017-09-24 20:21:15 +00:00
|
|
|
lcd_hex(bcd);
|
|
|
|
}
|
|
|
|
|
2017-09-24 20:06:59 +00:00
|
|
|
//! Draws hex on the screen.
|
|
|
|
void lcd_hex(long num){
|
|
|
|
/* So in an ideal world, we'd have characters arranged nicely into
|
|
|
|
LCDM[] bytes as some development tools do, but in the real world,
|
|
|
|
we're pretty much stuck with them as they are physically
|
|
|
|
arranged.
|
|
|
|
|
|
|
|
This function takes a buffer of eight hex characters and displays
|
|
|
|
them on the screen.
|
|
|
|
*/
|
|
|
|
int i;
|
2017-09-26 17:25:50 +00:00
|
|
|
|
2017-10-16 19:23:52 +00:00
|
|
|
|
|
|
|
for(i=0;i<8;i++)
|
2017-09-24 20:06:59 +00:00
|
|
|
lcd_digit(i,(num>>(4*i))&0xf);
|
|
|
|
}
|
|
|
|
|
2017-10-16 19:23:52 +00:00
|
|
|
//! Activates a period, or turns it off.
|
|
|
|
void setperiod(int digit, int on){
|
|
|
|
if(on) //On
|
|
|
|
DRAWPOINT(lcdmap[digit][7]);
|
|
|
|
else //Off
|
|
|
|
CLEARPOINT(lcdmap[digit][7]);
|
|
|
|
}
|
2017-09-24 20:06:59 +00:00
|
|
|
|
|
|
|
//! Activates the colon. 2 for invert.
|
2017-09-24 20:38:14 +00:00
|
|
|
void setcolon(int on){
|
2017-09-24 20:06:59 +00:00
|
|
|
if(on==2) //Blink
|
|
|
|
lcdm[3]^=0x20;
|
|
|
|
else if(on==1) //On
|
|
|
|
lcdm[3]|=0x20;
|
|
|
|
else //Off
|
|
|
|
lcdm[3]&=~0x20;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Activates the am. 2 for invert.
|
2017-09-24 20:38:14 +00:00
|
|
|
void setam(int on){
|
2017-09-24 20:06:59 +00:00
|
|
|
if(on==2) //Blink
|
|
|
|
lcdm[0]^=0x04;
|
|
|
|
else if(on==1) //On
|
|
|
|
lcdm[0]|=0x04;
|
|
|
|
else //Off
|
|
|
|
lcdm[0]&=~0x04;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Activates the pm. 2 for invert.
|
2017-09-24 20:38:14 +00:00
|
|
|
void setpm(int on){
|
2017-09-24 20:06:59 +00:00
|
|
|
if(on==2) //Blink
|
|
|
|
lcdm[1]^=0x40;
|
|
|
|
else if(on==1) //On
|
|
|
|
lcdm[1]|=0x40;
|
|
|
|
else //Off
|
|
|
|
lcdm[1]&=~0x40;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Activates the mult sign. 2 for invert.
|
2017-09-24 20:38:14 +00:00
|
|
|
void setmult(int on){
|
2017-09-24 20:06:59 +00:00
|
|
|
if(on==2) //Blink
|
|
|
|
lcdm[4]^=0x40;
|
|
|
|
else if(on==1) //On
|
|
|
|
lcdm[4]|=0x40;
|
|
|
|
else //Off
|
|
|
|
lcdm[4]&=~0x40;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Activates the minus sign. 2 for invert.
|
2017-09-24 20:38:14 +00:00
|
|
|
void setminus(int on){
|
2017-09-24 20:06:59 +00:00
|
|
|
if(on==2) //Blink
|
|
|
|
lcdm[6]^=0x04;
|
|
|
|
else if(on==1) //On
|
|
|
|
lcdm[6]|=0x04;
|
|
|
|
else //Off
|
|
|
|
lcdm[6]&=~0x04;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Activates the plus sign. 2 for invert.
|
2017-09-24 20:38:14 +00:00
|
|
|
void setplus(int on){
|
2017-09-24 20:06:59 +00:00
|
|
|
if(on==2) //Blink
|
|
|
|
lcdm[7]^=0x40;
|
|
|
|
else if(on==1) //On
|
|
|
|
lcdm[7]|=0x40;
|
|
|
|
else //Off
|
|
|
|
lcdm[7]&=~0x40;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Activates the divide sign. 2 for invert.
|
2017-09-24 20:38:14 +00:00
|
|
|
void setdivide(int on){
|
2017-09-24 20:06:59 +00:00
|
|
|
if(on==2) //Blink
|
|
|
|
lcdm[0xc]^=0x04;
|
|
|
|
else if(on==1) //On
|
|
|
|
lcdm[0xc]|=0x04;
|
|
|
|
else //Off
|
|
|
|
lcdm[0xc]&=~0x04;
|
|
|
|
}
|
|
|
|
|
|
|
|
|