#include<reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define LCD_Data_Port P0
sbit LCD12864_RS = P2^4; //定义端口 计算机加32
sbit LCD12864_RW = P2^5;
sbit LCD12864_EN = P2^6;
sbit led = P3^7;
uchar jj,num1,x1,miao,miao1,miao2,fen,fen1,fen2,shi,shi1,shi2;
uchar *q1,*q2,*q3,*q4,*q5,*q6;
/*================ 显示模式2数字及温度符号图片(宽度x高度=16*32)=====================*/
uchar code num1632[11][64]=
{
{// 图片数字0
0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x40,0x02,0x00,0x00,
0x40,0x02,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
{// 图片数字1
0x00,0x00,0x00,0x20,0x00,0x60,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,
0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0x60,0x00,0x20,0x00,0x00,0x00,0x20,
0x00,0x60,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,
0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0x60,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00},
{// 图片数字2
0x00,0x00,0x3F,0xFC,0x1F,0xFA,0x0F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x1F,0xFA,0x3F,0xFC,
0x5F,0xF8,0x60,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,
0x70,0x00,0x70,0x00,0x70,0x00,0x6F,0xF8,0x5F,0xFC,0x3F,0xFE,0x00,0x00,0x00,0x00},
{// 图片数字3
0x00,0x00,0x7F,0xFC,0x3F,0xFA,0x1F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x1F,0xFA,0x3F,0xFC,
0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
0x00,0x0E,0x00,0x0E,0x00,0x0E,0x1F,0xF6,0x3F,0xFA,0x7F,0xFC,0x00,0x00,0x00,0x00},
{// 图片数字4
0x00,0x00,0x40,0x02,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC,
0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00,0x00,0x00},
{// 图片数字5
0x00,0x00,0x3F,0xFC,0x5F,0xF8,0x6F,0xF0,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,
0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x60,0x00,0x5F,0xF8,0x3F,0xFC,
0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
0x00,0x0E,0x00,0x0E,0x00,0x0E,0x0F,0xF6,0x1F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
{// 图片数字6
0x00,0x00,0x3F,0xFC,0x5F,0xF8,0x6F,0xF0,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,
0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x60,0x00,0x5F,0xF8,0x3F,0xFC,
0x5F,0xFA,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
{// 图片数字7
0x00,0x00,0x7F,0xFC,0x3F,0xFA,0x1F,0xF6,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00,
0x00,0x02,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x06,0x00,0x02,0x00,0x00,0x00,0x00},
{// 图片数字8
0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC,
0x5F,0xFA,0x60,0x06,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
0x70,0x0E,0x70,0x0E,0x70,0x0E,0x6F,0xF6,0x5F,0xFA,0x3F,0xFC,0x00,0x00,0x00,0x00},
{// 图片数字9
0x00,0x00,0x3F,0xFC,0x5F,0xFA,0x6F,0xF6,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,
0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x70,0x0E,0x60,0x06,0x5F,0xFA,0x3F,0xFC,
0x1F,0xFA,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,
0x00,0x0E,0x00,0x0E,0x00,0x0E,0x1F,0xF6,0x3F,0xFA,0x7F,0xFC,0x00,0x00,0x00,0x00},
{// 图片":"
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x07,0xE0,
0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0,
0x07,0xE0,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};
#define delayNOP() {_nop_();_nop_();_nop_();_nop_();} //短延时
void delay(uint ms)
{
uchar j;
while(ms--)
{
for(j=110;j>0;j--);
}
}
uchar busy_12864()
{
uchar result;
LCD12864_RS = 0;
LCD12864_RW = 1;
LCD12864_EN = 0;
LCD12864_EN = 1;
delayNOP();
result=LCD_Data_Port&0x80;
LCD12864_EN =0;
return(result);
}
void write_12864_cmd(uchar cmd)
{
while(busy_12864());
LCD12864_RS = 0;
LCD12864_RW = 0;
LCD12864_EN = 0;
LCD_Data_Port=cmd;
// delayNOP();
LCD12864_EN = 1;
// delayNOP();
LCD12864_EN = 0;
}
void write_12864_data(uchar dat)
{
while(busy_12864());
LCD12864_RS = 1;
LCD12864_RW = 0;
LCD12864_EN = 0;
LCD_Data_Port=dat;
// delayNOP();
LCD12864_EN = 1;
// delayNOP();
LCD12864_EN = 0;
}
void Clean_12864(void)
{
write_12864_cmd(0x30);
write_12864_cmd(0x01);
delay(1);
}
void write1616GDRAM(uchar x,uchar y,uchar sign,uchar *bmp)
{
uchar i,j,basex;
write_12864_cmd(0x36);
if(y==1||y==2)
{
basex=0x80;
y=(y-1)*16;
}
if(y==3||y==4)
{
y=(y-3)*16;
}
for(i=0;i<16;i++) //
{
write_12864_cmd(0x80+y+i);
write_12864_cmd(basex+x-1);
for(j=0;j<2;j++)
{
if(sign==1)
write_12864_data(~(*bmp++));
else
write_12864_data(*bmp++);
}
}
write_12864_cmd(0x36);
}
void write1632GDRAM(uchar x,uchar y,uchar *bmp)
{
uchar i,j,basex,basey;
switch(y)
{
case 1: basex=0x80; break;
case 2: basex=0x80; break;
case 3: basex=0x88; break;
default: return;
}
basey=basex+x-1;
write_12864_cmd(0x36);
if(y==1||y==3)
{
for(i=0;i<32;i++)
{
write_12864_cmd(0x80+i);
write_12864_cmd(basey);
write_12864_data(*bmp++);
}
}
if(y==2)
{
for(i=0;i<16;i++)
{
write_12864_cmd(0x90+i);
write_12864_cmd(basey);
for(j=0;j<2;j++)
write_12864_data(*bmp++);
}
for(i=0;i<16;i++)
{
write_12864_cmd(0x80+i);
write_12864_cmd(basey+8);
for(j=0;j<2;j++)
write_12864_data(*bmp++);
}
}
write_12864_cmd(0x36);
}
void setwordbkcolor(uchar x,uchar y,uchar wide,uchar bkcor)
{
uchar i,j,basex,color;
if(bkcor==1) color=0xff;
if(bkcor==0) color=0x00;
write_12864_cmd(0x36);
if(y==1||y==2)
{
basex=0x80;
y=(y-1)*16;
}
if(y==3||y==4)
{
basex=0x88;
y=(y-3)*16;
}
for(i=0;i<wide;i++) //
{
write_12864_cmd(0x80+y+i);
write_12864_cmd(basex+x-1);
for(j=0;j<2;j++)
write_12864_data(color);
}
write_12864_cmd(0x36);
}
void setrowbkcolor(uchar row,uchar bkcor)
{
uchar i,j,basex,basey,color;
if(bkcor==1) color=0xff;
if(bkcor==0) color=0x00;
write_12864_cmd(0x36);
if(row==1||row==2)
{
basex=0x80;
}
if(row==3||row==4)
{
basex=0x88;
row=row-2;
}
basey=0x80+(row-1)*16;
for(i=0;i<16;i++)
{
write_12864_cmd(basey+i);
write_12864_cmd(basex);
for(j=0;j<16;j++)
write_12864_data(color);
}
write_12864_cmd(0x36);
}
void init_12864()
{
delay(500);
// LCD12864_PSB = 1;
write_12864_cmd(0x30);
write_12864_cmd(0x30);
write_12864_cmd(0x0C);
write_12864_cmd(0x06);
Clean_12864();
}
void init()
{
led=1;
P0=0x00;
led=0;
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void zcsh()
{
shi=9;
fen=26;
EA=0;
q1= num1632[1];
init();
init_12864();
Clean_12864_GDRAM();
q1 = num1632[10];
write1632GDRAM(6,3,q1);
write1632GDRAM(3,3,q1);
EA=1;
}
void main()
{
zcsh();
while(1)
{
x1=1;
miao1=miao/10;
miao2=miao%10;
fen1=fen/10;
fen2=fen%10;
shi1=shi/10;
shi2=shi%10;
q1 = num1632[0];
q2 = num1632[0];
q3 = num1632[0];
q4 = num1632[0];
q5 = num1632[0];
q6 = num1632[0];
q1=q1+64*miao2;
q2=q2+64*miao1;
q3=q3+64*fen2;
q4=q4+64*fen1;
q5=q5+64*shi2;
q6=q6+64*shi1;
write1632GDRAM(8,3,q1);
write1632GDRAM(7,3,q2);
write1632GDRAM(5,3,q3);
write1632GDRAM(4,3,q4);
write1632GDRAM(2,3,q5);
write1632GDRAM(1,3,q6);
while(x1);
}
}
void t0t() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num1++;
if(num1==20)
{
num1=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
}
}
x1=0;
}
}
转载
|