⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hz_disp.c

📁 SCM中LCM的汉字显示技巧,可以2*6=12共计个字符.
💻 C
字号:
#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);
  for(i=0;i<8;i++)
  {
    write_GLCD_command(SET_PAGE+i);
	write_GLCD_command(SET_Y_ADDRESS_0); 
    for(j=0;j<64;j++);
  	write_GLCD_data(0);
  }
}
void show_pattern(unsigned char page,unsigned char y,unsigned char *pattern,unsigned char len)
{
 int i;
 write_GLCD_command(SET_PAGE+page);
 write_GLCD_command(SET_Y_ADDRESS_0+y);
    for(i=0;i<len;i++);
  	{write_GLCD_data(*pattern);
	pattern++;
 	 }
}  
 void clear_pattrn(unsigned char page,unsigned char y,unsigned char len)
{
 int i;
 write_GLCD_command(SET_PAGE+page);
 write_GLCD_command(SET_Y_ADDRESS_0+y);
    for(i=0;i<len;i++);
  	write_GLCD_data(CLEAR);
 	}  
unsigned char read_GLCD_data(void)
{
 unsigned char x;
 GLCD_D_I=DATA;
 GLCD_R_W=READ;
 GLCD_ENABLE=ENABLE;
 P0=255;
 x=P0;
 GLCD_ENABLE=DISABLE;
 GLCD_D_I=0;
 check_GLCD_busyflag();
 GLCD_D_I=DATA;
 GLCD_ENABLE=ENABLE;
 x=P0;
 GLCD_ENABLE=DISABLE;
 check_GLCD_busyflag();
 return x;
 }
 void putpixel(unsigned char x,unsigned char y)
{unsigned char i=1,temp,page_no;
 if(x<64){
  GLCD_CS1=0;
  GLCD_CS2=1;
  }	else
 {
  GLCD_CS1=1;
  GLCD_CS2=0;
  x=x-64;}
write_GLCD_command(SET_Y_ADDRESS_0+y);
page_no=SET_PAGE+x/8;
write_GLCD_command(page_no);
temp=x%8;
while(temp){i=i*2;
 temp--;
 }
temp=read_GLCD_data();
i=i|temp;
write_GLCD_command(page_no);
write_GLCD_data(i);
}
void display_GLCD_data(unsigned char *p)
{
  if(gx<64){
  GLCD_CS1=1;
  GLCD_CS2=0;
  show_pattern(gy,gx,p,8);
  show_pattern(gy,gx+8,p+8,8);
  show_pattern(gy+1,gx,p+16,8);
  show_pattern(gy+1,gx+8,p+24,8);
 }else
 {
  GLCD_CS1=0;
  GLCD_CS2=1;
  show_pattern(gy,gx-64,p,8);
  show_pattern(gy,gx-58,p+8,8);
  show_pattern(gy+1,gx-64,p+16,8);
  show_pattern(gy+1,gx-58,p+24,8);
  }
  gx=gx+16;
 } 
void display_GLCD_string(unsigned char *p,int len)
{
 int i;
 for(i=0;i<len;i++)
  display_GLCD_data((p+32*i));
  }
void display_GLCD_number(char number)
{
 int x,y;
 x=number/10;
 y=number%10;
  display_GLCD_data(digit[x]);
  display_GLCD_data(digit[y]);
  }
 void gotoxy(unsigned x,unsigned y)
 {gy=y;
  gx=x;}						   
void main(void)  
{
 unsigned char i=0;
 clear_GLCD();
 gotoxy(0,0);
 display_GLCD_string(token,7);
 now.hour=12;
 now.minute=30;
 now.second=0;
 gotoxy(0,4);
 display_GLCD_number( now.hour);
 display_GLCD_data(comma);
 display_GLCD_number( now.minute);
 display_GLCD_data(comma);
 display_GLCD_number(now.second);
 today.year=5;
 today.month=9;
 today.day=1;
 gotoxy(0,6);
 display_GLCD_number(today.year);
 display_GLCD_data(slash);
 display_GLCD_number(today.month);
 display_GLCD_data(slash);
 display_GLCD_number(today.day);
 //while(1);
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -