/***********************************************
* Author: hoodlum1980
* Descri: A LCD-Style Clock in Character Mode
***********************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
void PrintVer(int,int,char*);/* 打印垂直笔划 */
void PrintHor(int,int,char*);/* 打印水平笔划 */
void PrintNumbers(int,char*);/* 打印一组数字 */
/*LCD的字型码*/
/* -0-
1 2
-3-
4 5
-6- */
int LCDCODES[][7]=
{ /* char asiic figure */
{1,1,1,0,1,1,1},/* '0' 0x30 0 */
{0,0,1,0,0,1,0},/* '1' 0x31 1 */
{1,0,1,1,1,0,1},/* '2' 0x32 2 */
{1,0,1,1,0,1,1},/* '3' 0x33 3 */
{0,1,1,1,0,1,0},/* '4' 0x34 4 */
{1,1,0,1,0,1,1},/* '5' 0x35 5 */
{1,1,0,1,1,1,1},/* '6' 0x36 6 */
{1,0,1,0,0,1,0},/* '7' 0x37 7 */
{1,1,1,1,1,1,1},/* '8' 0x38 8 */
{1,1,1,1,0,1,1},/* '9' 0x39 9 */
{0,0,0,1,0,0,0},/* ':' 0x3A - */
{0,0,0,0,0,0,0} /* ';' 0x3B */
};
char c_ver='$'; /* 组成垂直笔划的字符 */
char c_hor='='; /* 组成水平笔划的字符 */
/* 两个相邻字母中间隔了一个空列 ,因此平均每个字母占据n+3列,最后一列为间隔 */
/* 打印竖直笔画,n-笔画长度,section=1或者4,numbers-数字字符串 */
void PrintVer(int n,int section,char *numbers)
{
char *line;
int i,len=(n+3)*strlen(numbers);
line=(char*)malloc(len+1);
if(line==NULL)
return;
memset(line,' ',len);
for(i=0;i<strlen(numbers);i++)
{
if(LCDCODES[*(numbers+i)-'0'][section])
*(line+(n+3)*i)=c_ver;
if(LCDCODES[*(numbers+i)-'0'][section+1])
*(line+(n+3)*i+(n+1))=c_ver;
}
/*检查最后一个字符,如果没有笔画,要使/0前移2格!*/
line[len-1]='/0';
/*打印n行*/
for(i=0;i<n;i++)
printf("%s/n",line);
free(line);
}
/*打印水平笔画,n-笔画长度,section=0,3,or 6,numbers-数字字符串*/
void PrintHor(int n,int section,char *numbers)
{
char *line;
int i,len=(n+3)*strlen(numbers);
line=(char*)malloc(len+1);
if(line==NULL)
return;
memset(line,' ',len);
for(i=0;i<strlen(numbers);i++)
{
if(LCDCODES[*(numbers+i)-'0'][section])
memset((line+(n+3)*i+1),c_hor,n);
}
/*注意最后一个数字后面无需空格了!所以多缩进一个位置*/
line[len-1]='/0';
/*打印1行*/
printf("%s/n",line);
free(line);
}
/* Print A set of Numbers : "23456" e.g. */
void PrintNumbers(int n,char *numbers)
{
PrintHor(n,0,numbers); /* ---- */
PrintVer(n,1,numbers); /* | | */
PrintHor(n,3,numbers); /* ---- */
PrintVer(n,4,numbers); /* | | */
PrintHor(n,6,numbers); /* ---- */
}
/*用LCD样式显示当前的Bios时间*/
int main()
{
char buffer[10];
int n=2, lastSec=-1; /* n: 笔画长度; lastSec: 缓存的秒; */
struct time curTime; /* curTime: 当前bios时间; */
textbackground(BLACK);
textcolor(WHITE);
clrscr();
while(!kbhit())
{
gettime(&curTime);
if(curTime.ti_sec!=lastSec)
{
/* %2d:正数表示右对齐, 0表示补零,仅右对齐时有效 */
sprintf(buffer,"%2d:%02d:%02d", curTime.ti_hour, curTime.ti_min, curTime.ti_sec);
gotoxy(1,2);
PrintNumbers(n,buffer);
lastSec=curTime.ti_sec;
}
delay(200);
}
}
* Author: hoodlum1980
* Descri: A LCD-Style Clock in Character Mode
***********************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
void PrintVer(int,int,char*);/* 打印垂直笔划 */
void PrintHor(int,int,char*);/* 打印水平笔划 */
void PrintNumbers(int,char*);/* 打印一组数字 */
/*LCD的字型码*/
/* -0-
1 2
-3-
4 5
-6- */
int LCDCODES[][7]=
{ /* char asiic figure */
{1,1,1,0,1,1,1},/* '0' 0x30 0 */
{0,0,1,0,0,1,0},/* '1' 0x31 1 */
{1,0,1,1,1,0,1},/* '2' 0x32 2 */
{1,0,1,1,0,1,1},/* '3' 0x33 3 */
{0,1,1,1,0,1,0},/* '4' 0x34 4 */
{1,1,0,1,0,1,1},/* '5' 0x35 5 */
{1,1,0,1,1,1,1},/* '6' 0x36 6 */
{1,0,1,0,0,1,0},/* '7' 0x37 7 */
{1,1,1,1,1,1,1},/* '8' 0x38 8 */
{1,1,1,1,0,1,1},/* '9' 0x39 9 */
{0,0,0,1,0,0,0},/* ':' 0x3A - */
{0,0,0,0,0,0,0} /* ';' 0x3B */
};
char c_ver='$'; /* 组成垂直笔划的字符 */
char c_hor='='; /* 组成水平笔划的字符 */
/* 两个相邻字母中间隔了一个空列 ,因此平均每个字母占据n+3列,最后一列为间隔 */
/* 打印竖直笔画,n-笔画长度,section=1或者4,numbers-数字字符串 */
void PrintVer(int n,int section,char *numbers)
{
char *line;
int i,len=(n+3)*strlen(numbers);
line=(char*)malloc(len+1);
if(line==NULL)
return;
memset(line,' ',len);
for(i=0;i<strlen(numbers);i++)
{
if(LCDCODES[*(numbers+i)-'0'][section])
*(line+(n+3)*i)=c_ver;
if(LCDCODES[*(numbers+i)-'0'][section+1])
*(line+(n+3)*i+(n+1))=c_ver;
}
/*检查最后一个字符,如果没有笔画,要使/0前移2格!*/
line[len-1]='/0';
/*打印n行*/
for(i=0;i<n;i++)
printf("%s/n",line);
free(line);
}
/*打印水平笔画,n-笔画长度,section=0,3,or 6,numbers-数字字符串*/
void PrintHor(int n,int section,char *numbers)
{
char *line;
int i,len=(n+3)*strlen(numbers);
line=(char*)malloc(len+1);
if(line==NULL)
return;
memset(line,' ',len);
for(i=0;i<strlen(numbers);i++)
{
if(LCDCODES[*(numbers+i)-'0'][section])
memset((line+(n+3)*i+1),c_hor,n);
}
/*注意最后一个数字后面无需空格了!所以多缩进一个位置*/
line[len-1]='/0';
/*打印1行*/
printf("%s/n",line);
free(line);
}
/* Print A set of Numbers : "23456" e.g. */
void PrintNumbers(int n,char *numbers)
{
PrintHor(n,0,numbers); /* ---- */
PrintVer(n,1,numbers); /* | | */
PrintHor(n,3,numbers); /* ---- */
PrintVer(n,4,numbers); /* | | */
PrintHor(n,6,numbers); /* ---- */
}
/*用LCD样式显示当前的Bios时间*/
int main()
{
char buffer[10];
int n=2, lastSec=-1; /* n: 笔画长度; lastSec: 缓存的秒; */
struct time curTime; /* curTime: 当前bios时间; */
textbackground(BLACK);
textcolor(WHITE);
clrscr();
while(!kbhit())
{
gettime(&curTime);
if(curTime.ti_sec!=lastSec)
{
/* %2d:正数表示右对齐, 0表示补零,仅右对齐时有效 */
sprintf(buffer,"%2d:%02d:%02d", curTime.ti_hour, curTime.ti_min, curTime.ti_sec);
gotoxy(1,2);
PrintNumbers(n,buffer);
lastSec=curTime.ti_sec;
}
delay(200);
}
}