基于单片机的电子日历时钟系统.docx
- 文档编号:3261244
- 上传时间:2022-11-21
- 格式:DOCX
- 页数:16
- 大小:18.54KB
基于单片机的电子日历时钟系统.docx
《基于单片机的电子日历时钟系统.docx》由会员分享,可在线阅读,更多相关《基于单片机的电子日历时钟系统.docx(16页珍藏版)》请在冰豆网上搜索。
基于单片机的电子日历时钟系统
目录
一、设计任务
二、设计方案
三、硬件及电路设计
四、程序设计及流程图
五、设计体会
一、设计任务
利用单片机及外围接口电路(键盘接口和显示接口电路)设计制作一个电子日历时钟系统。
使用液晶显示器将日期,时间实时显示出来,并且能够通过按钮修改日期,完成实时操作并具有闹铃功能。
二、设计方案
硬件选择:
单片机AT89C51,DS1302时钟芯片,SED1520液晶控制器
接口芯片:
74LS138,74LS373,片选CS0
三、硬件及电路设计
(一)实验所用芯片简要介绍
1、主控芯片采用单片机AT89C51
AT89C51是一种带4K字节FLASH存储器(FPEROM—FlashProgrammableandErasableReadOnlyMemory)的低电压、高性能CMOS8位微处理器,俗称单片机,与AT80C51引脚和指令系统完全兼容,可擦除只读存储器可以反复擦除1000次。
AT89C51共有128×8位内部RAM,32可编程I/O线,两个16位定时器/计数器,5个中断源,采用全静态工作,三级程序存储器锁定和可编程串行通道,工作频率为0Hz-24MHz。
另外片内内置振荡器和时钟电路,低功耗的闲置和掉电模式。
2、实时时钟部分采用DS1302
DS1302是美国DALLAS公司推出的一种高性能、低功耗、带RAM的实时时钟电路,它可以对年、月、日、周日、时、分、秒进行计时,具有闰年补偿功能,工作电压为2.5V~5.5V。
采用三线接口与CPU进行同步通信,并可采用突发方式一次传送多个字节的时钟信号或RAM数据。
DS1302内部有一个31×8的用于临时性存放数据的RAM寄存器。
DS1302是DS1202的升级产品,与DS1202兼容,但增加了主电源/后备电源双电源引脚,同时提供了对后备电源进行涓细电流充电的能力。
3、SED1520液晶控制器
SED1520液晶显示驱动器是一种点阵图形式液晶显示驱动器,它可直接与8位微处理器相连,集行、列驱动器于一体,因此使用起来十分方便,作为内藏式控制器被广泛应用于点阵数较少的液晶显示模块,内置显示RAM区RAM容量为2560位,RAM中的1位数据控制液晶屏上一个点的亮灭状态:
“1”表示亮,“0”表示暗,具有16个行驱动口和16个列驱动口,可直接与80系列微处理器相连,亦可直接与68系列微处理器相连。
驱动占空比为1/16或1/32。
可以与SED1520配合使用,以便扩展列驱动口数目。
(二)硬件设计
(三)电路图
四、程序设计
实验执行程序如下:
#include
#defineucharunsignedchar
#defineuintunsignedint
#definePD161
unsignedcharaa,bb,cc,s1num;
unsignedcharcurtime[];
voidWriteSHU16x16(unsignedchar,unsignedchar,unsignedchar);
voidWriteZHI16x16(unsignedchar,unsignedchar,unsignedchar);
voidDelay(unsignedchar);
sbitt_clk=P1^0;
sbitt_io=P1^1;
sbitt_rst=P1^2;
sbits1=P1^5;
sbits2=P1^6;
sbits3=P1^7;
sbitsv=reset;
unsignedinti;
unsignedcharColumn;
unsignedcharPage_;
unsignedcharCode_;
unsignedcharColumn1;
unsignedcharPage;
unsignedcharCode1;
unsignedcharCommand;
unsignedcharLCDData;
xdataunsignedcharCWADD1_at_0x8000;
xdataunsignedcharDWADD1_at_0x8001;
xdataunsignedcharCRADD1_at_0x8002;
xdataunsignedcharDRADD1_at_0x8003;
xdataunsignedcharCWADD2_at_0x8004;
xdataunsignedcharDWADD2_at_0x8005;
xdataunsignedcharCRADD2_at_0x8006;
xdataunsignedcharDRADD2_at_0x8007;
codeunsignedcharSHUTAB[][16]={
{0x3E,0x51,0x49,0x45,0x3E},//-0-
{0x00,0x42,0x7F,0x40,0x00},//-1-
{0x62,0x51,0x49,0x49,0x46},//-2-
{0x21,0x41,0x49,0x4D,0x33},//-3-
{0x18,0x14,0x12,0x7F,0x10},//-4-
{0x27,0x45,0x45,0x45,0x39},//-5-
{0x3C,0x4A,0x49,0x49,0x31},//-6-
{0x01,0x71,0x09,0x05,0x03},//-7-
{0x36,0x49,0x49,0x49,0x36},//-8-
{0x46,0x49,0x49,0x29,0x1E},//-9-
{0x00,0x08,0x08,0x08,0x00},//---
};
codeunsignedcharCCTAB[][32]={
{0x00,0x20,0x10,0xCC,0x47,0x44,0x44,0xFC,
0x44,0x44,0x44,0x64,0x46,0x04,0x00,0x00,
0x04,0x04,0x04,0x07,0x04,0x04,0x04,0xFF,
0x04,0x04,0x04,0x04,0x04,0x06,0x04,0x00},
{0x00,0x00,0x00,0x00,0xFE,0x22,0x22,0x22,
0x22,0x22,0x22,0xFF,0x02,0x00,0x00,0x00,
0x00,0x80,0x40,0x30,0x0F,0x02,0x02,0x02,
0x02,0x42,0x82,0x7F,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,
0x82,0x82,0x82,0xFF,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x7F,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x7F,0x00,0x00,0x00,0x00}
};
voidwr_1302(unsignedcharadd,unsignedchardate)
{uchari;
t_rst=0;
t_clk=0;
t_rst=1;
for(i=0;i<8;i++)
{if(add&0x01)
t_io=1;
else
t_io=0;
t_clk=1;
t_clk=0;
add>>=1;
}
for(i=0;i<8;i++)
{if(date&0x01)
t_io=1;
else
t_io=0;
t_clk=1;
t_clk=0;
date>>=1;
}
t_rst=0;
}
unsignedcharre_1302(unsignedcharadd)
{uchardate,i;
t_rst=0;
t_clk=0;
t_rst=1;
for(i=0;i<8;i++)
{if(add&0x01)
t_io=1;
else
t_io=0;
t_clk=1;
t_clk=0;
add>>=1;
}
for(i=0;i<8;i++)
{date>>=1;
if(t_io)
date=date|0x80;
t_clk=1;
t_clk=0;
}
t_rst=0;
return(date);
}
voidset_1302()
{wr_1302(0x8e,0x00);
wr_1302(0x8c,curtime[6]);
wr_1302(0x8a,curtime[5]);
wr_1302(0x88,curtime[4]);
wr_1302(0x86,curtime[3]);
wr_1302(0x84,curtime[2]);
wr_1302(0x82,curtime[1]);
wr_1302(0x80,curtime[0]);
wr_1302(0x8e,0x80);
}
voidget_1302()
{cc=re_1302(0x81);
aa=cc>>4;
bb=cc&0x0f;
WriteSHU16x16(0x04,0x30,aa);
Delay(5);
WriteSHU16x16(0x04,0x38,bb);
curtime[0]=aa*10+bb;
cc=re_1302(0x83);
aa=cc>>4;
bb=cc&0x0f;
WriteSHU16x16(0x04,0x18,aa);
Delay(5);
WriteSHU16x16(0x04,0x20,bb);
curtime[1]=aa*10+bb;
cc=re_1302(0x85);
aa=cc>>4;
bb=cc&0x0f;
WriteSHU16x16(0x04,0x00,aa);
Delay(5);
WriteSHU16x16(0x04,0x08,bb);
curtime[2]=aa*10+bb;
cc=re_1302(0x87);
aa=cc>>4;
bb=cc&0x0f;
WriteSHU16x16(0x02,0x40,aa);
Delay(5);
WriteSHU16x16(0x02,0x48,bb);
curtime[3]=aa*10+bb;
cc=re_1302(0x89);
aa=cc>>4;
bb=cc&0x0f;
WriteSHU16x16(0x02,0x20,aa);
Delay(5);
WriteSHU16x16(0x02,0x28,bb);
curtime[4]=aa*10+bb;
cc=re_1302(0x8d);
aa=cc>>4;
bb=cc&0x0f;
WriteSHU16x16(0x02,0x00,aa);
Delay(5);
WriteSHU16x16(0x02,0x08,bb);
curtime[6]=aa*10+bb;
WriteSHU16x16(0x04,0x10,10);
WriteSHU16x16(0x04,0x28,10);
WriteZHI16x16(0x02,0x10,0);
WriteZHI16x16(0x02,0x30,1);
WriteZHI16x16(0x02,0x50,2);
}
voidWriteCommandE1(unsignedcharCommand)
{while(CRADD1&0x80);
CWADD1=Command;
}
voidWriteDataE1(unsignedcharLCDData)
{while(CRADD1&0x80);
DWADD1=LCDData;
}
voidReadDataE1(unsignedcharDRADD1)
{while(CRADD1&0x80);
LCDData=DRADD1;
}
voidWriteCommandE2(unsignedcharCommand)
{while(CRADD2&0x80);
CWADD2=Command;
}
voidWriteDataE2(unsignedcharLCDData)
{while(CRADD2&0x80);
DWADD2=LCDData;
}
voidReadDataE2(unsignedcharDRADD2)
{while(CRADD2&0x80);
LCDData=DRADD2;
}
voidInit()
{WriteCommandE1(0xe2);
WriteCommandE2(0xe2);
WriteCommandE1(0xa4);
WriteCommandE2(0xa4);
WriteCommandE1(0xa9);
WriteCommandE2(0xa9);
WriteCommandE1(0xa0);
WriteCommandE2(0xa0);
WriteCommandE1(0xc0);
WriteCommandE2(0xc0);
WriteCommandE1(0xaf);
WriteCommandE2(0xaf);
}
voidClear()
{unsignedchari,j;
for(i=0;i<4;i++)
{WriteCommandE1(i+0xb8);
WriteCommandE2(i+0xb8);
WriteCommandE1(0x00);
WriteCommandE2(0x00);
for(j=0;j<61;j++)
{WriteDataE1(0x00);
WriteDataE2(0x00);
}
}
}
voidDelay(unsignedintz)
{unsignedintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
voidWriteSHU16x16(unsignedcharPage_,unsignedcharColumn,unsignedcharCode_)
{unsignedinti,j,k;
i=0;
j=0;
while(j<2)
{WriteCommandE1(((Page_+j)&0x03)|0xb8);
WriteCommandE2(((Page_+j)&0x03)|0xb8);
k=Column;
while(k {if(k {WriteCommandE1(k); LCDData=SHUTAB[Code_][i]; WriteDataE1(LCDData); } else {Command=k-PD1; WriteCommandE2(Command); LCDData=SHUTAB[Code_][i]; WriteDataE2(LCDData); }; i++; if(++k>=PD1*2)break; }; j++; }; } voidWriteZHI16x16(unsignedcharPage,unsignedcharColumn1,unsignedcharCode1) {unsignedinti,j,k; i=0; j=0; while(j<2) {WriteCommandE1(((Page+j)&0x03)|0xb8); WriteCommandE2(((Page+j)&0x03)|0xb8); k=Column1; while(k {if(k {WriteCommandE1(k); LCDData=CCTAB[Code1][i]; WriteDataE1(LCDData); } else {Command=k-PD1; WriteCommandE2(Command); LCDData=CCTAB[Code1][i]; WriteDataE2(LCDData); }; i++; if(++k>=PD1*2)break; }; j++; }; } voidkeyscan() {s1num=0; sv=0; if(s1==0) {Delay(5); if(s1==0) {s1num++; while(! s1); } } if(s1num! =0) {if(s1num==1) { if(s2==0) {Delay(5); if(s2==0) {if(curtime[0]==59) {curtime[0]=0; } elsecurtime[0]++; } } if(s3==0) {Delay(5); if(s3==0) {if(curtime[0]==0) {curtime[0]=59; } elsecurtime[0]--; } } } if(s1num==2) {if(s2==0) {Delay(5); if(s2==0) {if(curtime[1]==59) {curtime[1]=0; } elsecurtime[1]++; } } if(s3==0) {Delay(5); if(s3==0) {if(curtime[1]==0) {curtime[1]=59; } elsecurtime[1]--; } } } if(s1num==3) {if(s2==0) {Delay(5); if(s2==0) {if(curtime[2]==23) {curtime[2]=0; } elsecurtime[2]++; } } if(s3==0) {Delay(5); if(s3==0) {if(curtime[2]==0) {curtime[2]=23; } elsecurtime[2]--; } } } if(s1num==4) {if(s2==0) {Delay(5); if(s2==0) {if(curtime[3]==31) {curtime[3]=1; } elsecurtime[3]++; } } if(s3==0) {Delay(5); if(s3==0) {if(curtime[3]==1) {curtime[3]=31; } elsecurtime[3]--; } } } if(s1num==5) {if(s2==0) {Delay(5); if(s2==0) {if(curtime[4]==12) {curtime[4]=1; } elsecurtime[4]++; } } if(s3==0) {Delay(5); if(s3==0) {if(curtime[4]==1) {curtime[4]=12; } elsecurtime[4]--; } } } if(s1num==6) {if(s2==0) {Delay(5); if(s2==0) {if(curtime[6]==99) {curtime[6]=0; } elsecurtime[6]++; } } if(s3==0) {Delay(5); if(s3==0) {if(curtime[6]==0) {curtime[6]=99; } elsecurtime[6]--; } } } if(s1num==7) {s1num=0; } set_1302(); get_1302(); } } voidmain() {Init(); Clear(); set_1302(); while (1) {keyscan(); get_1302(); } } .
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 单片机 电子 日历 时钟 系统