"); //-->
//使用时请在代码中声明代码来源
#include <reg52.h>
#include <math.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define x1 0x80
#define x2 0x88
#define y 0x80
#define comm 0
#define dat 1
//口定义
sbit cs = P0^0;
sbit std = P0^1;
sbit sclk = P0^2;
sbit psb = P0^3; //H=并口; L=串口;
sbit rst = P3^7; //Reset Signal 低电平有效
//全局变量定义
bit timeflag = 0; //时间标示
unsigned int timecounter = 0;
unsigned char second = 50; //秒钟
unsigned char minute = 58; //分钟
unsigned char hour = 22; //小时
uchar code tab1[]={
//"本系列中文模块内"
//"任意位置反白显示"
//"置二级字库,可在"
//"使用更方便更灵活"
" 烟台大学 "
"学院:计算机学院"
" 04级毕业设计 "
"专业: 自动化 "
};
uchar code tab31[]={
" 鸣谢 "
"计算机学院实验室"
"烟台大学创新实验"
"指导教师:王培进"
};
uchar code tab2[]={
" 设计题目 "
"设计者:张发忠 "
"家庭安全防盗系统"
"Tel:013954534215"
};
//函数调用申明
void Time(void);
void wr_lcd (uchar dat_comm,uchar content);
void delay (uint us);
void init_lcd (void);
void chn_disp (uchar code *chn);
void lat_disp (uchar data1,uchar data2);
void con_disp (uchar data1,uchar data2,uchar x0,uchar y0,uchar xl,uchar yl);
void wr_lcd (uchar dat_comm,uchar content);
void delay1 (uint ms);
void clrram (void);
void TimeDisplay(void);
void LogOnScreen(void);
//unsigned char HexToDec(unsigned char hex);
//初始化串口:串口工作方式1,允许接受REN=1,波特率=1200
/*void initialize_UART()
{
P1=0xFF;
TMOD=0x20;
//下面已修改为适合12MHz晶振,11.0592改成E8
TH1=0xf7;//0xe6;
TL1=0xf7;//0xe6;
SCON=0x50;
TR1=1;
}
//串口发,查询发送
void s_send(unsigned char ch)
{
SBUF=ch;
TI=0;
while(!TI);
TI=0;
}*/
main()
{
// unsigned char m;
// initialize_UART();
// lat_disp (0x00,0x00);
EA = 1;
ET0 = 1;
TR0 = 1;
LogOnScreen();
for(;;)
{
// m = HexToDec(0x32);
Time();
TimeDisplay();
}
}
/*****************************************************************************
函数:void LogOnScreen(void)
出口参数:无
入口参数:无
日期:2007.12.28
编者:zhangfazhong
状态:待测
*****************************************************************************/
void LogOnScreen(void)
{
init_lcd ();
delay1 (800);
clrram();
lat_disp (0x00,0x00);
chn_disp (tab1);
delay1 (50000);
clrram();
lat_disp (0x00,0x00);
chn_disp (tab2);
delay1 (50000);
delay1 (50000);
clrram();
lat_disp (0x00,0x00);
chn_disp (tab31);
delay1 (50000);
delay1 (50000);
clrram();
}
/*****************************************************************************
函数:void TimeDisplay(void)
出口参数:无
入口参数:无
日期:2007.12.27
编者:zhangfazhong
状态:已测通过
*****************************************************************************/
void TimeDisplay(void)
{
wr_lcd (comm,0x80); //现
wr_lcd (dat,0xcf);
wr_lcd (dat,0xd6);
wr_lcd (comm,0x81); //在
wr_lcd (dat,0xd4);
wr_lcd (dat,0xda);
wr_lcd (comm,0x82); //是
wr_lcd (dat,0xca);
wr_lcd (dat,0xc7);
wr_lcd (comm,0x83); //:
wr_lcd (dat,0xa3);
wr_lcd (dat,0xba);
wr_lcd (comm,0x92);
wr_lcd (dat,(unsigned)(hour/10)+48);
wr_lcd (dat,hour%10+48);
wr_lcd (comm,0x93);
wr_lcd (dat,0x3a); //:
wr_lcd (dat,(unsigned)(minute/10)+48);
wr_lcd (comm,0x94);
wr_lcd (dat,minute%10+48);
wr_lcd (dat,0x3a); //:
wr_lcd (comm,0x95);
wr_lcd (dat,(unsigned)(second/10)+48 );
wr_lcd (dat,second%10+48);
// wr_lcd (dat,(unsigned)(HexToDec(second)/10)+48 );
// wr_lcd (dat,HexToDec(second)%10+48);
}
/*****************************************************************************
函数:unsigned char HexToDec(unsigned char hex)
出口参数:十进制数
入口参数:十六进制数
日期:2007.12.27
编者:zhangfazhong
状态:待测
****************************************************************************
unsigned char HexToDec(unsigned char hex)
{
unsigned int dec = 0;
unsigned int dec1 = 0;
switch (hex>>4)
{
case 0x01:dec1 = 1;break;
case 0x02:dec1 = 2;break;
case 0x03:dec1 = 3;break;
case 0x04:dec1 = 4;break;
case 0x05:dec1 = 5;break;
case 0x06:dec1 = 6;break;
case 0x07:dec1 = 7;break;
case 0x08:dec1 = 8;break;
case 0x09:dec1 = 9;break;
case 0x0a:dec1 = 10;break;
case 0x0b:dec1 = 11;break;
case 0x0c:dec1 = 12;break;
case 0x0d:dec1 = 13;break;
case 0x0e:dec1 = 14;break;
case 0x0f:dec1 = 15;break;
case 0x00:dec1 = 0;break;
}
switch (hex&0x0f)
{
case 0x01:dec = 1;break;
case 0x02:dec = 2;break;
case 0x03:dec = 3;break;
case 0x04:dec = 4;break;
case 0x05:dec = 5;break;
case 0x06:dec = 6;break;
case 0x07:dec= 7;break;
case 0x08:dec = 8;break;
case 0x09:dec = 9;break;
case 0x0a:dec = 10;break;
case 0x0b:dec = 11;break;
case 0x0c:dec = 12;break;
case 0x0d:dec = 13;break;
case 0x0e:dec = 14;break;
case 0x0f:dec = 15;break;
case 0x00:dec = 0;break;
}
// dec = hex;
// dec = hex>>4;
// dec1 = dec;
dec = dec1*16 + dec;
return (dec);
}
*/
/*****************************************************************************
函数:void Time(void)
出口参数:无
入口参数:无
日期:2007.12.27
编者:zhangfazhong
状态:已测通过
*****************************************************************************/
void Time(void)
{
/* if(timeflag) //占用较大的资源
{
timecounter++;
timeflag = 0;
if (timecounter == 450) //此值待定
{
timecounter = 0;
if(second <= 59)
second++;
else
{
if (minute <= 59)
minute++;
else
{
minute = 0;
if (hour == 23)
hour = 0;
else
hour++;
}
second = 0;
}
}
}*/
if(timeflag)
{
timecounter++;
timeflag = 0;
if (timecounter == 450) //此值待定
{
timecounter = 0;
if(second == 59)
{
if (minute == 59)
{
minute = 0;
if (hour == 23)
hour = 0;
else
hour++;
}
else
minute++;
second = 0;
}
else
second++;
}
}
}
/******************************************************************************
功能:T0中断
日期:
编者:
状态:已测功能实现
******************************************************************************/
Timer0() interrupt 1 using 1
{
TH0 = 0x97;//b1; //20ms
TL0 = 0xd5;//e0;
TF0 = 0;
timeflag = 1;
}
/*------------------初始化-----------------*/
void init_lcd (void)
{
rst=1;
psb=0;
wr_lcd (comm,0x30); /*30---基本指令动作*/
wr_lcd (comm,0x01); /*清屏,地址指针指向00H*/
delay (100);
wr_lcd (comm,0x06); /*光标的移动方向*/
wr_lcd (comm,0x0c); /*开显示,关游标*/
}
/*---------------显示汉字或字符----------------*/
void chn_disp (uchar code *chn)
{
uchar i,j;
wr_lcd (comm,0x30);
wr_lcd (comm,0x80);
for (j=0;j<4;j++)
{
for (i=0;i<16;i++)
wr_lcd (dat,chn[j*16+i]);
}
}
/*--------------显示点阵----------------*/
void lat_disp (uchar data1,uchar data2)
{
uchar i,j,k,x;
x=x1;
for(k=0;k<2;k++)
{
for(j=0;j<16;j++)
{
for(i=0;i<8;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y+j*2);
wr_lcd (comm,x+i);
wr_lcd (comm,0x30);
wr_lcd (dat,data1);
wr_lcd (dat,data1);
}
for(i=0;i<8;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y+j*2+1);
wr_lcd (comm,x+i);
wr_lcd (comm,0x30);
wr_lcd (dat,data2);
wr_lcd (dat,data2);
}
}
x=x2;
}
wr_lcd (comm,0x36);
}
/*-----------------------------------------------*/
//当data1=0xff,data2=0xff时,在x0,y0处反白显示16xl*yl.
void con_disp (uchar data1,uchar data2,uchar x0,uchar y0,uchar xl,uchar yl)
{
uchar i,j;
for(j=0;j<yl;j++)
{
for(i=0;i<xl;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y0+j);
wr_lcd (comm,x0+i);
wr_lcd (comm,0x30);
wr_lcd (dat,data1);
wr_lcd (dat,data2);
}
}
wr_lcd (comm,0x36);
}
/*--------------清DDRAM------------------*/
void clrram (void)
{
wr_lcd (comm,0x30);
wr_lcd (comm,0x01);
delay (300);
}
/*---------------------------------------*/
void wr_lcd (uchar dat_comm,uchar content)
{
uchar a,i,j;
delay (50);
a=content;
cs=1;
sclk=0;
std=1;
for(i=0;i<5;i++)
{
sclk=1;
sclk=0;
}
std=0;
sclk=1;
sclk=0;
if(dat_comm)
std=1; //data
else
std=0; //command
sclk=1;
sclk=0;
std=0;
sclk=1;
sclk=0;
for(j=0;j<2;j++)
{
for(i=0;i<4;i++)
{
a=a<<1;
std=CY;
sclk=1;
sclk=0;
}
std=0;
for(i=0;i<4;i++)
{
sclk=1;
sclk=0;
}
}
}
/*-----------------------------------*/
void delay (uint us) //delay time
{
while(us--);
}
void delay1 (uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<15;j++)
delay(1);
}
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。