#include"reg52.h"
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
#define nop _nop_()
#define dispon 0x3f
#define dispoff 0x3e
#define lieadr 0x40
#define pageadr 0xb8
#define starline 0xc0
sbit res=P2^2;
sbit di= P2^5;
sbit rw= P2^7;
sbit en= P2^6;
sbit cs1=P2^4;
sbit cs2=P2^3;
sbit DS1302_RST=P3^5;
sbit DS1302_CLK=P3^3;
sbit DS1302_IO=P3^4;
/////////////////////////////////////////////////////////////////////////////////////////////////////
unsigned char code hanzi[]={
/*-- 文字: 中 --*/
/*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 9--*/
0x00,0x00,0xFC,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00,
0x00,0x00,0x07,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x07,0x00,0x00,0x00,
/*-- 文字: 国 --*/
/*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 10--*/
0x00,0xFE,0x02,0x0A,0x8A,0x8A,0x8A,0xFA,0x8A,0x8A,0x8A,0x0A,0x02,0xFE,0x00,0x00,
0x00,0xFF,0x40,0x48,0x48,0x48,0x48,0x4F,0x48,0x49,0x4E,0x48,0x40,0xFF,0x00,0x00,
/*-- 文字: 深 --*/
/*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 11--*/
0x10,0x61,0x06,0xE0,0x00,0x26,0x22,0x1A,0x02,0xC2,0x0A,0x12,0x32,0x06,0x02,0x00,
0x04,0xFC,0x03,0x20,0x20,0x11,0x11,0x09,0x05,0xFF,0x05,0x09,0x19,0x31,0x10,0x00,
/*-- 文字: 圳 --*/
/*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 12--*/
0x10,0x10,0x10,0xFE,0x10,0x10,0xFE,0x00,0x00,0xFC,0x00,0x00,0x00,0xFE,0x00,0x00,
0x08,0x08,0x04,0x47,0x24,0x18,0x07,0x00,0x00,0x1F,0x00,0x00,0x00,0x7F,0x00,0x00,
};
uchar code shuzi[]={
/*-- 文字: 0 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --0*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
/*-- 文字: 1 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --1*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
/*-- 文字: 2 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --2*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
/*-- 文字: 3 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --3*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 4 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --4*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*-- 文字: 5 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --5*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 6 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --6*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,
/*-- 文字: 7 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --7*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
/*-- 文字: 8 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --8*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
};
/////////////////////////////////////////////////////////////////////////////////////////////////////
/***********************************************
***********************************************/
void dely(unsigned int use)
{
int i;
for(;use>0;use--)
{
i--;
}
}
/***********************************************
***********************************************/
void delay(unsigned int useconds)
{
int i;
for(;useconds>0;useconds--)
{
for(i=120;i>0;i--);
}
}
void wrlie(uchar lie);
void wrpage(uchar pagecn);
void wrst(uchar lin);
void clrlcd();
void disp_hanzi(uchar han,uchar pagecn,uchar liecn);
void disp_shuzi1(uchar han,uchar pagecn,uchar liecn);
void wrchar(uchar ai);
void wrdate(uchar dat);
void lcdinit(void);
void wrcom(uchar comm);
void dispshuzi0(uchar ix,uchar lie,uchar page);
void dispday(void);
void dispzgsz(void);
void dispshuzi(uchar shu,uchar pagecn,uchar liecn);
/*888888888888888888888888888888888888888888888888
***********************************************/
void main(void)
{
uint ij;
lcdinit();
clrlcd();
delay(1000);
////////////////////////////////////////////////////////
delay(250);
dispzgsz();
////////////////////////////////////////////////////////
while(1)
{
delay(100);
ij++;
if(ij==200)
{
ij=0;
dispzgsz();
}
cs1=1;cs2=0;
wrpage(4);
wrlie(20);
dispshuzi(ij,4,10);
}
}
///////////////////////////////////////////////////
void dispzgsz(void)
{
uchar ik;
cs1=1,cs2=0;
disp_hanzi(0, 0x04,ik+32);
disp_hanzi(1,0x04,ik+48);
cs1=0,cs2=1;
disp_hanzi(2,0x04, ik+0);
disp_hanzi(3,0x04,ik+16);
ik++;
}
/**********************************
**********************************/
void lcdinit(void)
{
res=0;
nop;
nop;
nop;
nop;
nop;
nop;
res=1;
nop;
nop;
nop;
nop;
nop;
nop;
cs1=1,cs2=0;
wrcom(dispoff);
wrcom(lieadr);
wrcom(pageadr);
wrcom(starline);
wrcom(dispon);
dely(6);
cs1=0;cs2=1;
wrcom(dispoff);
wrcom(lieadr);
wrcom(pageadr);
wrcom(starline);
wrcom(dispon);
dely(6);
}
/***********************************************
***********************************************/
void wrdate(uchar dat)
{
rw=0;
nop;
di=1;
nop;
nop;
nop;
nop;
nop;
P0=dat;
nop;
nop;
en=1;
nop;
nop;
nop;
nop;
nop;
en=0;
nop;
nop;
nop;
nop;
nop;
}
/**********************************
**********************************/
void wrcom(uchar comm)
{
di=0;
nop;
nop;
nop;
nop;
nop;
rw=0;
nop;
nop;
nop;
nop;
nop;
//P1=comm;
P0=comm;
nop;
nop;
en=1;
nop;
nop;
nop;
nop;
nop;
nop;
en=0;
nop;
nop;
nop;
nop;
}
/***********************************************
***********************************************/
void wrpage(uchar pagecnt)
{
uchar b;
b=pageadr|pagecnt;
wrcom(b);
}
/***********************************************
***********************************************/
void wrlie( uchar lie)
{
uchar a;
a=lieadr|lie;
wrcom(a);
}
/***********************************************/
void dispshuzi(uchar shu,uchar pagecn,uchar liecn)
{
uchar i,j;
int ig;
ig=shu*16;
wrlie(liecn);
wrpage(pagecn);
for(j=0;j<2;j++)
{
for(i=0;i<8;i++)
{
wrdate(shuzi[ig]);
ig++;
}
wrlie(liecn);
wrpage(pagecn+1);
}
}
/***************************************
显示16×16的汉字
***************************************/
void disp_hanzi(uchar han,uchar pagecn,uchar liecn)
{
uchar j,*pi;
int ii;
pi=&hanzi[0];
ii=han*32;
wrlie(liecn);
wrpage(pagecn);
for(j=0;j<16;j++)
{
wrdate(hanzi[ii]);
ii++;
}
wrlie(liecn);
wrpage(pagecn+1);
for(j=0;j<16;j++)
{
wrdate(hanzi[ii]);
ii++;
}
}
/***************************************
显示8×16 的数字
***************************************/
/***************************************
清除LCD屏幕
***************************************/
void clrlcd(void)
{
uchar i,j;
cs1=1,cs2=0;
wrlie(0X00);
for(j=0;j<8;j++)
{
wrpage(j);
wrlie(0X00);
for(i=0;i<64;i++)
{ wrdate(0x00);}
}
cs1=0;cs2=1;
wrlie(00);
for(j=0;j<8;j++)
{
wrpage(j);
wrlie(00);
for(i=0;i<64;i++)
{ wrdate(0x00);}
}
} |