程序如下:
- #include<reg52.h> //52头文件
- #define uint unsigned int
- #define uchar unsigned char
- sbit rw=P2^5; //读写选择端
- sbit rs=P2^6; //数据命令选择端
- sbit en=P2^7; //使能端
- sbit psb=P3^2; //串口选择端
- uchar num,hours,minutes,secondsq,h1,h2,m1,m2,s1,s2;
- uchar code table0[32][2]={
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x07,0xE0,
- 0x0C,0x38,
- 0x1C,0x18,
- 0x38,0x1C,
- 0x38,0x1E,
- 0x78,0x1E,
- 0x78,0x0E,
- 0x78,0x0E,
- 0x78,0x0F,
- 0xF0,0x0F,
- 0xF0,0x0F,
- 0xF0,0x0F,
- 0xF0,0x0F,
- 0x70,0x0F,
- 0x78,0x0F,
- 0x78,0x0E,
- 0x78,0x1E,
- 0x38,0x1E,
- 0x38,0x1C,
- 0x1C,0x1C,
- 0x1C,0x38,
- 0x0F,0x70,
- 0x03,0xC0,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- };
- uchar code table1[32][2]={
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x01,0xC0,
- 0x03,0xC0,
- 0x0F,0xC0,
- 0x1F,0xC0,
- 0x3B,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x03,0xC0,
- 0x1F,0xF8,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- };
- uchar code table2[32][2]={
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x0F,0xF0,
- 0x1F,0xFC,
- 0x38,0x3E,
- 0x38,0x1E,
- 0x70,0x1E,
- 0x70,0x1E,
- 0x00,0x1E,
- 0x00,0x1E,
- 0x00,0x1E,
- 0x00,0x3C,
- 0x00,0x38,
- 0x00,0x70,
- 0x00,0xE0,
- 0x01,0xC0,
- 0x03,0x80,
- 0x07,0x00,
- 0x0E,0x00,
- 0x1C,0x03,
- 0x38,0x03,
- 0x38,0x07,
- 0x7F,0xFF,
- 0xFF,0xFF,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- };
- uchar code table3[32][2]={
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x03,0xF0,
- 0x0F,0xF8,
- 0x1E,0x7C,
- 0x18,0x3C,
- 0x30,0x3C,
- 0x00,0x3C,
- 0x00,0x38,
- 0x00,0x70,
- 0x00,0xE0,
- 0x01,0xF8,
- 0x03,0xFC,
- 0x06,0x3E,
- 0x00,0x1F,
- 0x00,0x0F,
- 0x00,0x0F,
- 0x00,0x0F,
- 0x00,0x0F,
- 0x00,0x0F,
- 0x00,0x0E,
- 0x00,0x1C,
- 0x70,0x3C,
- 0x7C,0x70,
- 0x3F,0xE0,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- };
- uchar code table4[32][2]={
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x38,
- 0x00,0x38,
- 0x00,0x78,
- 0x00,0xF8,
- 0x00,0xF8,
- 0x01,0xF8,
- 0x03,0xF8,
- 0x07,0x78,
- 0x06,0x78,
- 0x0E,0x78,
- 0x1C,0x78,
- 0x18,0x78,
- 0x38,0x78,
- 0x70,0x78,
- 0x60,0x78,
- 0xFF,0xFF,
- 0xFF,0xFF,
- 0x00,0x78,
- 0x00,0x78,
- 0x00,0x78,
- 0x00,0x78,
- 0x00,0x78,
- 0x00,0x78,
- 0x00,0x78,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- };
- uchar code table5[32][2]={
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x0C,
- 0x0F,0xFC,
- 0x0F,0xFC,
- 0x0C,0x00,
- 0x0C,0x00,
- 0x1C,0x00,
- 0x1C,0x00,
- 0x1F,0xE0,
- 0x1F,0xF8,
- 0x1F,0xFC,
- 0x1C,0x3C,
- 0x00,0x1E,
- 0x00,0x1E,
- 0x00,0x0E,
- 0x00,0x0F,
- 0x00,0x0F,
- 0x00,0x0E,
- 0x00,0x0E,
- 0x00,0x1E,
- 0x38,0x1C,
- 0x7C,0x78,
- 0x1F,0xE0,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- };
- uchar code table6[32][2]={
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x0C,
- 0x00,0x3C,
- 0x00,0xF0,
- 0x01,0xC0,
- 0x07,0x80,
- 0x0F,0x00,
- 0x0F,0x00,
- 0x1E,0x00,
- 0x3E,0x00,
- 0x3C,0x00,
- 0x3F,0xF0,
- 0x78,0x7C,
- 0x78,0x3C,
- 0x78,0x1E,
- 0x78,0x1E,
- 0x78,0x1E,
- 0x78,0x1E,
- 0x78,0x1E,
- 0x78,0x1E,
- 0x3C,0x1E,
- 0x3C,0x1C,
- 0x1E,0x3C,
- 0x0F,0x78,
- 0x03,0xC0,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- };
- uchar code table7[32][2]={
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x7F,0xFF,
- 0x7F,0xFE,
- 0x60,0x0E,
- 0x60,0x0C,
- 0x00,0x1C,
- 0x00,0x1C,
- 0x00,0x18,
- 0x00,0x38,
- 0x00,0x38,
- 0x00,0x70,
- 0x00,0x70,
- 0x00,0x60,
- 0x00,0xE0,
- 0x00,0xE0,
- 0x00,0xC0,
- 0x01,0xC0,
- 0x01,0xC0,
- 0x01,0x80,
- 0x03,0x80,
- 0x03,0x80,
- 0x03,0x00,
- 0x03,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- };
- uchar code table8[32][2]={
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x07,0xF0,
- 0x0C,0x3C,
- 0x1C,0x1C,
- 0x38,0x1E,
- 0x38,0x1E,
- 0x38,0x1E,
- 0x38,0x1E,
- 0x3C,0x1C,
- 0x1F,0x38,
- 0x0F,0xF0,
- 0x07,0xF0,
- 0x07,0xF8,
- 0x1E,0x7C,
- 0x3C,0x1E,
- 0x3C,0x0F,
- 0x38,0x0F,
- 0x38,0x0F,
- 0x38,0x0F,
- 0x38,0x0E,
- 0x3C,0x0E,
- 0x1C,0x1C,
- 0x0F,0x78,
- 0x01,0xE0,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- };
- uchar code table9[32][2]={
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x03,0xC0,
- 0x0E,0xF0,
- 0x3C,0x38,
- 0x38,0x3C,
- 0x78,0x1C,
- 0x78,0x1E,
- 0x78,0x1E,
- 0x78,0x1E,
- 0x78,0x1E,
- 0x78,0x1E,
- 0x78,0x1E,
- 0x3C,0x1E,
- 0x1E,0x1E,
- 0x0F,0xDE,
- 0x00,0x3C,
- 0x00,0x3C,
- 0x00,0x78,
- 0x00,0x78,
- 0x00,0xF0,
- 0x01,0xE0,
- 0x03,0xC0,
- 0x0F,0x00,
- 0x3C,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- };
- uchar code table10[32][2]={
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x01,0x00,
- 0x03,0x80,
- 0x07,0xC0,
- 0x0E,0xE0,
- 0x07,0xC0,
- 0x03,0x80,
- 0x01,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x01,0x00,
- 0x03,0x80,
- 0x07,0xC0,
- 0x0E,0xE0,
- 0x07,0xC0,
- 0x03,0x80,
- 0x01,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- 0x00,0x00,
- };
- uchar code table11[16][16]={
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- void delay(int z) //0.1毫秒延时函数
- {
- int x,y;
- for(x=z;x>0;x--)
- for(y=11;y>0;y--);
- }
- //void delayms(int z)
- //{
- // int x,y;
- // for(x=z;x>0;x--)
- // for(y=110;y>0;y--);
- //}
- void w_cmd(uchar cmd) //写命令
- {
- rs=0;
- rw=0;
- en=0;
- delay(1);
- P0=cmd;
- delay(5);
- en=1;
- delay(5);
- en=0;
- delay(5);
- }
- void w_date(uchar date) //写数据
- {
- rs=1;
- rw=0;
- en=0;
- P0=date;
- delay(5);
- en=1;
- delay(5);
- en=0;
- delay(5);
- }
- void lcd_init() //lcd初始化
- {
- psb=1; //并行方式
- w_cmd(0x30); //基本指令
- delay(1);
- w_cmd(0x0c); //开整体显示
- delay(1);
- w_cmd(0x01); //清除LCD显示内容
- delay(50);
- }
- void suspend() //中断初始化
- {
- TMOD=0x01; //设置定时器0为工作方式1
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256; //赋初值
- EA=1; //开总中断
- ET0=1; //开定时器0中断
- TR0=1; //启动定时器
- }
- void lcd_show(uchar a[32][2],c,d)
- {
- uchar i,j;
- w_cmd(0x36);
- delay(1);
- for(i=0;i<16;i++)
- {
- w_cmd(0x90+i);
- delay(1);
- w_cmd(c);
- delay(1);
- for(j=0;j<2;j++)
- {
- w_date(a[i][j]);
- }
- }
- for(i=0;i<16;i++)
- {
- w_cmd(0x80+i);
- delay(1);
- w_cmd(d);
- delay(1);
- for(j=0;j<2;j++)
- {
- w_date(a[i+16][j]);
- }
- }
- w_cmd(0x30);
- }
- void lcd_show1()//显示空白
- {
- uchar i,j;
- w_cmd(0x36);
- delay(1);
- for(i=0;i<16;i++)
- {
- w_cmd(0x80+i);
- delay(1);
- w_cmd(0x80);
- delay(1);
- for(j=0;j<16;j++)
- {
- w_date(table11[i][j]);
- }
- }
- for(i=0;i<16;i++)
- {
- w_cmd(0x90+i);
- delay(1);
- w_cmd(0x98);
- delay(3);
- for(j=0;j<16;j++)
- {
- w_date(table11[i][j]);
- }
- }
- w_cmd(0x30);
- }
- void lcd_h1()
- {
- h1=hours/10;
- switch(h1)
- {
- case 0: {lcd_show(table0,0x90,0x88);break;}
- case 1: {lcd_show(table1,0x90,0x88);break;}
- case 2: {lcd_show(table2,0x90,0x88);break;}
- case 3: {lcd_show(table3,0x90,0x88);break;}
- case 4: {lcd_show(table4,0x90,0x88);break;}
- case 5: {lcd_show(table5,0x90,0x88);break;}
- case 6: {lcd_show(table6,0x90,0x88);break;}
- case 7: {lcd_show(table7,0x90,0x88);break;}
- case 8: {lcd_show(table8,0x90,0x88);break;}
- case 9: {lcd_show(table9,0x90,0x88);break;}
- }
- }
- void lcd_h2()
- {
- h2=hours%10;
- switch(h2)
- {
- case 0: {lcd_show(table0,0x91,0x89);break;}
- case 1: {lcd_show(table1,0x91,0x89);break;}
- case 2: {lcd_show(table2,0x91,0x89);break;}
- case 3: {lcd_show(table3,0x91,0x89);break;}
- case 4: {lcd_show(table4,0x91,0x89);break;}
- case 5: {lcd_show(table5,0x91,0x89);break;}
- case 6: {lcd_show(table6,0x91,0x89);break;}
- case 7: {lcd_show(table7,0x91,0x89);break;}
- case 8: {lcd_show(table8,0x91,0x89);break;}
- case 9: {lcd_show(table9,0x91,0x89);break;}
- }
- }
- void lcd_m1()
- {
- m1=minutes/10;
- switch(m1)
- {
- case 0: {lcd_show(table0,0x93,0x8b);break;}
- case 1: {lcd_show(table1,0x93,0x8b);break;}
- case 2: {lcd_show(table2,0x93,0x8b);break;}
- case 3: {lcd_show(table3,0x93,0x8b);break;}
- case 4: {lcd_show(table4,0x93,0x8b);break;}
- case 5: {lcd_show(table5,0x93,0x8b);break;}
- case 6: {lcd_show(table6,0x93,0x8b);break;}
- case 7: {lcd_show(table7,0x93,0x8b);break;}
- case 8: {lcd_show(table8,0x93,0x8b);break;}
- case 9: {lcd_show(table9,0x93,0x8b);break;}
- }
- }
- void lcd_m2()
- {
- m2=minutes%10;
- switch(m2)
- {
- case 0: {lcd_show(table0,0x94,0x8c);break;}
- case 1: {lcd_show(table1,0x94,0x8c);break;}
- case 2: {lcd_show(table2,0x94,0x8c);break;}
- case 3: {lcd_show(table3,0x94,0x8c);break;}
- case 4: {lcd_show(table4,0x94,0x8c);break;}
- case 5: {lcd_show(table5,0x94,0x8c);break;}
- case 6: {lcd_show(table6,0x94,0x8c);break;}
- case 7: {lcd_show(table7,0x94,0x8c);break;}
- case 8: {lcd_show(table8,0x94,0x8c);break;}
- case 9: {lcd_show(table9,0x94,0x8c);break;}
- }
- }
- void lcd_s1()
- {
- s1=secondsq/10;
- switch(s1)
- {
- case 0: {lcd_show(table0,0x96,0x8e);break;}
- case 1: {lcd_show(table1,0x96,0x8e);break;}
- case 2: {lcd_show(table2,0x96,0x8e);break;}
- case 3: {lcd_show(table3,0x96,0x8e);break;}
- case 4: {lcd_show(table4,0x96,0x8e);break;}
- case 5: {lcd_show(table5,0x96,0x8e);break;}
- case 6: {lcd_show(table6,0x96,0x8e);break;}
- case 7: {lcd_show(table7,0x96,0x8e);break;}
- case 8: {lcd_show(table8,0x96,0x8e);break;}
- case 9: {lcd_show(table9,0x96,0x8e);break;}
- }
- }
- void lcd_s2()
- {
- s2=secondsq%10;
- switch(s2)
- {
- case 0: {lcd_show(table0,0x97,0x8f);break;}
- case 1: {lcd_show(table1,0x97,0x8f);break;}
- case 2: {lcd_show(table2,0x97,0x8f);break;}
- case 3: {lcd_show(table3,0x97,0x8f);break;}
- case 4: {lcd_show(table4,0x97,0x8f);break;}
- case 5: {lcd_show(table5,0x97,0x8f);break;}
- case 6: {lcd_show(table6,0x97,0x8f);break;}
- case 7: {lcd_show(table7,0x97,0x8f);break;}
- case 8: {lcd_show(table8,0x97,0x8f);break;}
- case 9: {lcd_show(table9,0x97,0x8f);break;}
- }
- }
- void T0_time() interrupt 1 //选用定时器0方式1
- {
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256; //赋初值
- num++;
- if(num==20) //20次50ms为1秒
- {
- secondsq++; //秒自增
- num=0; //中断次数清零
- if(secondsq==60)
- {
- minutes++; //分钟自增
- secondsq=0; //秒清零
- if(minutes==60)
- {
- hours++; //时钟自增
- minutes=0; //分钟清零
- if(hours==24)
- {
- hours=0; //时钟自增
- }
- }
- }
- }
- }
- void main()
- {
- lcd_init();//显示初始化
- suspend();//中断初始化
- lcd_show1();//显示空白
- lcd_show(table10,0x92,0x8a);
- lcd_show(table10,0x95,0x8d);//显示冒号
- while(1)
- {
- lcd_h1();
- lcd_h2();
- lcd_m1();
- lcd_m2();
- lcd_s1();
- lcd_s2();
- }
- }
复制代码
但是随时间的增加
这是什么原因,找了好久没找到
感谢大神的回复!!!
|