📄 sblcd.h
字号:
// SoftBaugh LCD driver
// (C) 2003 Anakron Canada Inc. / Kent Johansen
// Special symbols - port and bit
#define LCD_Antenna1 0x91,0x10
#define LCD_Antenna 0x91,0x20
#define LCD_Antenna3 0x91,0x40
#define LCD_Antenna2 0x91,0x80
#define LCD_BatteryEnds 0x92,0x01
#define LCD_Battery3 0x92,0x02
#define LCD_Battery2 0x92,0x04
#define LCD_Battery1 0x92,0x08
#define LCD_ArrowLeft 0x92,0x10
#define LCD_ArrowUp 0x92,0x20
#define LCD_ArrowRight 0x92,0x40
#define LCD_ArrowDown 0x92,0x80
#define LCD_Minus 0xA4,0x10
#define LCD_Plus 0xA4,0x80
// Decimal points after 1,2,3 digit on 4 digit bank
#define LCD_DP1 0x96,0x08
#define LCD_DP2 0x95,0x08
#define LCD_DP3 0x93,0x80
#define LCD_CLOCKCOLON 0x94,0x80
// Port 2.7 must be 1 to show these and segments of the last starburst
#define LCD_SoftBaugh 0x98,0x80
// Port 2.7 must be 0 to access the progress bar
#define LCD_PL 0x97,0x80
#define LCD_P0 0x97,0x40
#define LCD_P1 0x97,0x20
#define LCD_P2 0x97,0x10
#define LCD_P3 0x97,0x01
#define LCD_P4 0x97,0x02
#define LCD_P5 0x97,0x04
#define LCD_P6 0x97,0x08
#define LCD_P7 0x98,0x80
#define LCD_P8 0x98,0x40
#define LCD_P9 0x98,0x20
#define LCD_PR 0x98,0x10
// Starburst segment definitions.
#define _N 0x0001
#define _M 0x0002
#define _K 0x0004
#define _J 0x0008
#define _D 0x0010
#define _C 0x0020
#define _B 0x0040
#define _A 0x0080
#define _P 0x0100
#define _Q 0x0200
#define _G 0x0400
#define _H 0x0800
#define _E 0x2000
#define _F 0x4000
static const unsigned starburst_segments[] =
{
/* */ 0,
/*!*/ _F | _E, // Lame
/*"*/ _H | _K,
/*#*/ _J | _B | _P | _C | _G | _M,
/*$*/ _A | _F | _G | _M | _C | _D | _J | _P,
/*%*/ 0, // No good idea
/*&*/ 0, // No good idea
/*'*/ _K,
/*(*/ _A | _F | _E | _D,
/*)*/ _A | _B | _C | _D,
/***/ _H | _J | _K | _G | _M | _Q | _P | _N,
/*+*/ _J | _G | _M | _P,
/*,*/ 0, // No good idea
/*-*/ _G | _M,
/*.*/ 0, // Should use decimal point, but...
/*slash */ _K | _Q,
/*0*/ _A | _B | _C | _D | _E | _F | _Q | _K,
/*1*/ _C | _B,
/*2*/ _A | _B | _M | _G | _E | _D,
/*3*/ _A | _B | _M | _G | _C | _D,
/*4*/ _F | _G | _M | _B | _C,
/*5*/ _A | _F | _G | _M | _C | _D,
/*6*/ _A | _F | _E | _D | _C | _M | _G,
/*7*/ _F | _A | _B | _C,
/*8*/ _A | _B | _C | _D | _E | _F | _G | _M,
/*9*/ _A | _F | _G | _M | _B | _C | _D,
/*:*/ 0, // No good idea
/*;*/ 0, // No good idea
/*<*/ _K | _N,
/*=*/ _G | _M | _D,
/*>*/ _H | _Q,
/*?*/ _A | _B | _M | _G | _E,
/*@*/ 0, // No good idea
/*A*/ _E | _F | _A | _B | _C | _G | _M,
/*B*/ _A | _B | _C | _D | _J | _P | _M,
/*C*/ _A | _F | _E | _D,
/*D*/ _A | _B | _C | _D | _J | _P,
/*E*/ _A | _F | _E | _D | _G | _M,
/*F*/ _A | _F | _E | _G | _M,
/*G*/ _A | _F | _E | _D | _C | _M,
/*H*/ _F | _E | _G | _M | _B | _C,
/*I*/ _A | _J | _P | _D,
/*J*/ _B | _C | _D | _E,
/*K*/ _F | _E | _G | _K | _N,
/*L*/ _F | _E | _D,
/*M*/ _E | _F | _H | _K | _B | _C,
/*N*/ _E | _F | _H | _N | _C | _B,
/*O*/ _A | _B | _C | _D | _E | _F,
/*P*/ _E | _F | _A | _B | _G | _M,
/*Q*/ _A | _B | _C | _D | _E | _F | _N,
/*R*/ _E | _F | _A | _B | _G | _M | _N,
/*S*/ _A | _F | _G | _M | _C | _D,
/*T*/ _A | _J | _P,
/*U*/ _F | _E | _D | _C | _B,
/*V*/ _F | _E | _Q | _K,
/*W*/ _F | _E | _Q | _N | _C | _B,
/*X*/ _H | _K | _Q | _N,
/*Y*/ _H | _K | _P,
/*Z*/ _A | _K | _Q | _D
};
// 7 segment chars for segment 8,9
#define LCD8a_A 0x01
#define LCD8a_B 0x02
#define LCD8a_C 0x04
#define LCD8a_DP 0x08
#define LCD8a_F 0x10
#define LCD8a_G 0x20
#define LCD8a_E 0x40
#define LCD8a_D 0x80
// 7 segment chars for segment 10,11
#define LCD8b_B 0x01
#define LCD8b_G 0x02
#define LCD8b_C 0x04
#define LCD8b_D 0x08
#define LCD8b_A 0x10
#define LCD8b_F 0x20
#define LCD8b_E 0x40
#define LCD8b_DP 0x80
static const unsigned char digit_segments_a[] =
{
/* 0 - 0*/ LCD8a_A | LCD8a_B | LCD8a_C | LCD8a_D | LCD8a_E | LCD8a_F ,
/* 1 - 1*/ LCD8a_C | LCD8a_B,
/* 2 - 2*/ LCD8a_A | LCD8a_B | LCD8a_G | LCD8a_E | LCD8a_D,
/* 3 - 3*/ LCD8a_A | LCD8a_B | LCD8a_G | LCD8a_C | LCD8a_D,
/* 4 - 4*/ LCD8a_F | LCD8a_G | LCD8a_B | LCD8a_C,
/* 5 - 5*/ LCD8a_A | LCD8a_F | LCD8a_G | LCD8a_C | LCD8a_D,
/* 6 - 6*/ LCD8a_A | LCD8a_F | LCD8a_E | LCD8a_D | LCD8a_C | LCD8a_G,
/* 7 - 7*/ LCD8a_F | LCD8a_A | LCD8a_B | LCD8a_C,
/* 8 - 8*/ LCD8a_A | LCD8a_B | LCD8a_C | LCD8a_D | LCD8a_E | LCD8a_F | LCD8a_G,
/* 9 - 9*/ LCD8a_A | LCD8a_F | LCD8a_G | LCD8a_B | LCD8a_C | LCD8a_D,
/*10 - -*/ LCD8a_G,
/*11 - deg*/ LCD8a_A | LCD8a_B | LCD8a_G | LCD8a_F,
/*12 - F*/ LCD8a_E | LCD8a_F | LCD8a_A,
/*13 - C*/ LCD8a_A | LCD8a_F | LCD8a_E | LCD8a_D,
};
static const unsigned char digit_segments_b[] =
{
/* 0 - 0*/ LCD8b_A | LCD8b_B | LCD8b_C | LCD8b_D | LCD8b_E | LCD8b_F ,
/* 1 - 1*/ LCD8b_C | LCD8b_B,
/* 2 - 2*/ LCD8b_A | LCD8b_B | LCD8b_G | LCD8b_E | LCD8b_D,
/* 3 - 3*/ LCD8b_A | LCD8b_B | LCD8b_G | LCD8b_C | LCD8b_D,
/* 4 - 4*/ LCD8b_F | LCD8b_G | LCD8b_B | LCD8b_C,
/* 5 - 5*/ LCD8b_A | LCD8b_F | LCD8b_G | LCD8b_C | LCD8b_D,
/* 6 - 6*/ LCD8b_A | LCD8b_F | LCD8b_E | LCD8b_D | LCD8b_C | LCD8b_G,
/* 7 - 7*/ LCD8b_F | LCD8b_A | LCD8b_B | LCD8b_C,
/* 8 - 8*/ LCD8b_A | LCD8b_B | LCD8b_C | LCD8b_D | LCD8b_E | LCD8b_F | LCD8b_G,
/* 9 - 9*/ LCD8b_A | LCD8b_F | LCD8b_G | LCD8b_B | LCD8b_C | LCD8b_D,
/*10 - -*/ LCD8b_G,
/*11 - deg*/ LCD8b_A | LCD8b_B | LCD8b_G | LCD8b_F,
/*12 - F*/ LCD8b_E | LCD8b_F | LCD8b_A,
/*13 - C*/ LCD8b_A | LCD8b_F | LCD8b_E | LCD8b_D,
};
// LCD variables
char LCD_buf[10]; // Buffer for LCD conversion. Used by display char etc routines.
static void sblcd_init(void)
{
// P2SEL = 0xff;
// P3SEL = 0xff;
P4SEL = 0xff;
P5SEL = 0xff;
// Setup LCD
LCDCTL = LCDSG0_7 | LCD4MUX | LCDSON | LCDON;
// Clear display.
memset(LCDMEM, 0, 20);
}
static void sblcd_set_contrast(int contrast)
{
if (contrast) ;
P2DIR &=0xF0;
P3DIR &=0x0F;
P3DIR |=0x80;
}
// Starburst segments
static void sblcd_display_char(int position, char c)
// Displays char. Position starts with 1
{
unsigned char *base = (unsigned char *)0x97+14 - position*2;
unsigned digits = starburst_segments[c-' '];
base[0] = digits;
base[1] = (digits>>8);
}
static void sblcd_display_starburst(int position, unsigned pattern) {
// Position starts with 1
// AAAAA
// FHJKB
// GG MM
// EQPNC
// DDDDD
unsigned char *base = (unsigned char *)0x97+14 - position*2;
base[0] = pattern;
base[1] = (pattern>>8);
}
static void sblcd_msg(char pos,char* msg) {
// Displays message on 7 segment display. Pos 1 is first.
int i;
for (i=0;i<7;i++) {
if (msg[i]==0x00 || pos>7) return;
sblcd_display_char(pos++,msg[i]);
}
}
static void sblcd_display_dpt(int position,int on) {
// Displays decimal point before position
unsigned char *base = (unsigned char *)0x97+14 - position*2;
if (on) base[1] |= 0x10; else base[0] &= ~0x10;
}
static void sblcd_display_colon(int position,int on) {
// Displays decimal point before position
unsigned char *base = (unsigned char *)0x97+14 - position*2;
if (on) base[1] |= 0x80; else base[0] &= ~0x80;
}
// 4 digit segment
static void sblcd_display_7seg(int position,char pattern)
// Position starts with 1
// 1,2 uses LCD8a_X
// 3,4 uses LCD8b_X
// AAA
// F B
// GGG
// E C
// DDD
{
unsigned char *base = (unsigned char *)0x97 - position;
base[0] = pattern;
}
static void sblcd_display_digit(int position,char c)
// Position starts with 1
{
unsigned char *base = (unsigned char *)0x97 - position;
unsigned digitsa = digit_segments_a[c];
unsigned digitsb = digit_segments_b[c];
if (position<3) base[0] = digitsa; else base[0]=digitsb;
}
static void sblcd_show(unsigned int port,char mask) {
// Call with the specially defined symbols to show them
*((char *)port) |= mask;
}
static void sblcd_hide(unsigned int port,char mask) {
// Call with the specially defined symbols to show them
*((char *)port) &= ~mask;
}
// Char type display routines
static void sblcd_display_digits(int position) { // sends LCD_buf to 4 digit display
if (!LCD_buf[0]) return; sblcd_display_digit(position++,LCD_buf[0]-'0');
if (!LCD_buf[1]) return; sblcd_display_digit(position++,LCD_buf[1]-'0');
if (!LCD_buf[2]) return; sblcd_display_digit(position++,LCD_buf[2]-'0');
if (!LCD_buf[3]) return; sblcd_display_digit(position ,LCD_buf[3]-'0');
}
static void sblcd_display_chars(int position) { // sends LCD_buf to 7 char display
if (!LCD_buf[0]) return; sblcd_display_char(position++,LCD_buf[0]);
if (!LCD_buf[1]) return; sblcd_display_char(position++,LCD_buf[1]);
if (!LCD_buf[2]) return; sblcd_display_char(position++,LCD_buf[2]);
if (!LCD_buf[3]) return; sblcd_display_char(position++,LCD_buf[3]);
if (!LCD_buf[4]) return; sblcd_display_char(position++,LCD_buf[4]);
if (!LCD_buf[5]) return; sblcd_display_char(position++,LCD_buf[5]);
if (!LCD_buf[6]) return; sblcd_display_char(position ,LCD_buf[6]);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -