#include <REGX51.H>
#include <absacc.h> //解析XBYTE 宏定义
#define GLCD_OFF 62 //03eh
#define GLCD_ON 63 //03fh
#define GLCD_START_LINE_0 192 //0c0h means display on lcm from 0 sites.
#define SET_PAGE 184 //0b8h means page numbers are set as000 (x is),so,all operation on lcm armed this page.
#define SET_Y_ADDRESS_0 64 //040h
#define CLEAR 0
#define ENABLE 1
#define DISABLE 0
#define READ 1
#define WRITE 0
#define COMMAND 0
#define DATA 1
#define GLCD_RESET P2_2
#define GLCD_CS2 P2_3
#define GLCD_CS1 P2_4
#define GLCD_D_I P2_5
#define GLCD_R_W P2_6
#define GLCD_ENABLE P2_7
typedef struct{
char hour;
char minute;
char second;
} time;
typedef struct{
char year;
char month;
char day;
} date;
time now;
date today;
unsigned char gx,gy;
static unsigned timer0_tick;
char code int2char[]="0123456789";
char code monthday[]={31,28,31,30,31,30,31,31,30,31,30,31};
char code weekday[7][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
unsigned char code digit[10][4][8]=
//0
{{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//1
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//2
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//3
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//4
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//5
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//6
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//7
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//8
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//9
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}}};
unsigned char code slash[4][8]=
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}};
unsigned char code comma[4][8]=
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}};
unsigned char code space[4][8]=
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}};
//年
unsigned char code yearp[4][8]=
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}};
//星
unsigned char code weekp[2][4][8]=
{{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//期
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}}};
unsigned char code weekdayp[7][4][8]=
{{
//一
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//二
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//三
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//四
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//五
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//六
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//日
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}}};
//月
unsigned char code monthp[4][8]=
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}};
unsigned char code token[7][4][8]=
{{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//现
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//在
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//时
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//间
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//是
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}},
//:
{
{0x08,0x00,0x0F,0xFC,0x10,0x80,0x10,0x80},
{0x20,0x80,0x4F,0xF8,0x88,0x80,0x08,0x80},
{0x08,0x80,0x08,0x80,0xFF,0xFE,0x00,0x80},
{0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80}}};
void delay(void){
unsigned char i,j;
for (i=0;i<255;i++)
for(j=0;j<255;j++)
;
}
void check_GLCD_busyflag(void)
{
unsigned char x;
GLCD_R_W=READ;
GLCD_D_I=COMMAND;
GLCD_ENABLE=ENABLE;
P0=255;
do{
x=P0 && 128;}while(x);
GLCD_ENABLE=DISABLE;
GLCD_D_I=1;
GLCD_R_W=1;
}
void write_GLCD_command(unsigned command)
{
GLCD_R_W=WRITE;
GLCD_D_I= COMMAND;
GLCD_ENABLE=ENABLE;
P0=command ;
GLCD_ENABLE=DISABLE;
GLCD_D_I=1;
GLCD_R_W=1;
check_GLCD_busyflag();}
void write_GLCD_data(unsigned GLCDdata)
{
GLCD_R_W=WRITE;
GLCD_D_I= DATA;
GLCD_ENABLE=ENABLE;
P0=GLCDdata;
GLCD_ENABLE=DISABLE;
GLCD_D_I=0;
GLCD_R_W=1;
check_GLCD_busyflag();}
void clear_GLCD()
{
int i,j;
GLCD_RESET=0;
for(i=0;i<2;i++);
GLCD_RESET=1;
GLCD_CS1=1;
GLCD_CS2=1;
write_GLCD_command(GLCD_START_LINE_0);