本帖最后由 52mcu 于 2009-10-9 22:10 编辑
为更加易于使用 最近对“八段显示码发生器(v1.0)” 升级至版本(v1.01)
改进如下:
1、扩充了默认的字符集 使之包含全亮符(ON)和全灭符(OFF)
2、加入了非数字字符的索引。使得可以用如下代码方便的显示数字和非数字字符
//显示数字字符‘4’
POART = CharCode['4'-0x30]
//显示非数字字符‘A’
POART = CharCode[GetChIndex('A')]
3、修正了一个内部变量bug
4、八段显示码发生器(v1.01)的输出结果如下:
typedef struct
{
char Character;
unsigned char Index;
}TCharIndex;
//示例代码,即插即用 sample code
//#define LENGTH(a) (sizeof(a)/sizeof((a)[0]))
//查找非数字字符在段码值数组中的索引
unsigned char GetChIndex(char Character)
{
unsigned char i;
for(i=0;i<LENGTH(CharIndex);i++) {
if(Character == CharIndex.Character)
return CharIndex.Index;
}
return LENGTH(CharCode)-1;
}
//显示数字字符‘4’
POART = CharCode['4'-0x30]
//显示非数字字符‘A’
POART = CharCode[GetChIndex('A')]
//D7 D6 D5 D4 D3 D2 D1 D0
//A B C D E F G DP LED段码值数组 (共阴高电平点亮)
//0 1 2 3 4 5 6 7 8 9
unsigned char const CharCode[]={0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE4,0xFE,0xF6
//A b C d E F g H i J
,0xEE,0x3E,0x9C,0x7A,0x9E,0x8E,0xF6,0x6E,0x08,0x78
//L o p q r t U v y c
,0x1C,0x3A,0xCE,0xE6,0x0A,0x22,0x7C,0x38,0x4E,0x1A
//h T - _ . ON OFF
,0x2E,0x8C,0x02,0x10,0x01,0xFF,0x00}
TCharIndex const CharIndex[] = {{'A',10},{'b',11},{'C',12},{'d',13},{'E',14},{'F',15},{'g',16},{'H',17},{'i',18},{'J',19},{'L',20},{'o',21},{'p',22},{'q',23},{'r',24},{'t',25},{'U',26},{'v',27},{'y',28},{'c',29},{'h',30},{'T',31},{'-',32},{'_',33},{'.',34}} |