单片机时钟电路仿真.doc_第1页
单片机时钟电路仿真.doc_第2页
单片机时钟电路仿真.doc_第3页
单片机时钟电路仿真.doc_第4页
单片机时钟电路仿真.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

#include #include sbit RS=P20;sbit RW=P21;sbit E=P22;sbit BF=P07;unsigned char flag;unsigned char time=time:;unsigned char mon=Mon;unsigned char tus=Tus;unsigned char wed=Wed;unsigned char thur=Thur;unsigned char fri=Fri;unsigned char sat=Sat;unsigned char sun=Sun;/寄存器宏定义#define WRITE_SECOND 0x80#define WRITE_MINUTE 0x82#define WRITE_HOUR 0x84#define READ_SECOND 0x81#define READ_MINUTE 0x83#define READ_HOUR 0x85#define WRITE_PROTECT 0x8E#define WRITE_DAY 0x86#define WRITE_MONTH 0x88#define WRITE_YEAR 0x8c#define WRITE_WEEK 0x8a#define READ_DAY 0x87#define READ_MONTH 0x89#define READ_YEAR 0x8d#define READ_WEEK 0x8b/位寻址寄存器定义sbit ACC_7 = ACC7;/管脚定义sbit SCLK = P31; / DS1302时钟信号7脚sbit DIO= P32; / DS1302数据信号6脚sbit CE = P30; / DS1302片选5脚/*函数功能:延时1ms*/void delay1ms()unsigned char i,j;for (i=0;i10;i+)for (j=0;j33;j+); /*函数功能:延时n毫秒入口参数:n*/void delaynms(unsigned char n)unsigned char i;for (i=0;i0; i- ) /循环8次移位SCLK = 0;temp = addr;DIO = (bit)(temp&0x01); /每次传输低字节addr = 1; /右移一位SCLK = 1;/发送数据for ( i=8; i0; i- )SCLK = 0;temp = dat;DIO = (bit)(temp&0x01);dat = 1;SCLK = 1;CE = 0;/*数据读取子程序*/unsigned char Read1302 ( unsigned char addr )unsigned char i,temp,dat1,dat2;CE=0;SCLK=0;CE = 1;/发送地址for ( i=8; i0; i- ) /循环8次移位SCLK = 0;temp = addr;DIO = (bit)(temp&0x01); /每次传输低字节addr = 1; /右移一位SCLK = 1;/读取数据for ( i=8; i0; i- )ACC_7=DIO;SCLK = 1;ACC=1;SCLK = 0;CE=0;dat1=ACC;dat2=dat1/16; /数据进制转换dat1=dat1%16; /十六进制转十进制dat1=dat1+dat2*10;return (dat1);/*初始化DS1302 */void initial1302(void)Write1302 (WRITE_PROTECT,0X00); /禁止写保护Write1302 (WRITE_SECOND,0x56); /秒位初始化Write1302 (WRITE_MINUTE,0x34); /分钟初始化Write1302 (WRITE_HOUR,0x12); /小时初始化Write1302 (WRITE_DAY,0x12);Write1302 (WRITE_MONTH,0x12);Write1302 (WRITE_YEAR,0x00);Write1302 (WRITE_WEEK,0x01);Write1302 (WRITE_PROTECT,0x80);/*lcd时钟显示子程序*/void display_clock()unsigned char i;WriteAddress(1,0);i=0;while(timei!=0)WriteData(timei);i+;delaynms(20);WriteAddress(0,5);WriteData(:);delaynms(20);WriteAddress(0,8);WriteData(:);delaynms(20);WriteAddress(1,9);WriteData(:);delaynms(20);WriteAddress(1,12);WriteData(:);delaynms(20);void display_year()unsigned char year,y1,y2;year=Read1302(READ_YEAR);y1=year/10+48;y2=year%10+48;WriteAddress(0,1);WriteData(2+48);delaynms(20);WriteAddress(0,2);WriteData(48);delaynms(20);WriteAddress(0,3);WriteData(y1);delaynms(20);WriteAddress(0,4);WriteData(y2);delaynms(20);void display_month()unsigned char month,m1,m2;month=Read1302(READ_MONTH);m1=month/10+48;m2=month%10+48;WriteAddress(0,6);WriteData(m1);delaynms(20);WriteAddress(0,7);WriteData(m2);delaynms(20);void display_day()unsigned char day,d1,d2;day=Read1302(READ_DAY);d1=day/10+48;d2=day%10+48;WriteAddress(0,9);WriteData(d1);delaynms(20);WriteAddress(0,10);WriteData(d2);delaynms(20);void display_week()unsigned char i,j,k,a,b,c,d,week;week=Read1302(READ_WEEK);WriteAddress(0,12);switch(week)case 1:while(moni!=0) WriteData(moni); i+;delaynms(20); ;break;case 2:while(tusj!=0)WriteData(tusj);j+;delaynms(20);break;case 3:while(wedk!=0)WriteData(wedk);k+;delaynms(20);break; case 4:while(thura!=0) WriteData(thura);a+;delaynms(20);break; case 5:while(frib!=0) WriteData(frib);b+;delaynms(20);break; case 6:while(satc!=0) WriteData(satc);c+;delaynms(20);break; case 7:while(sund!=0) WriteData(sund);d+;delaynms(20);break; default:;void display_hour()unsigned char hour,h1,h2;hour=Read1302(READ_HOUR);h1=hour/10+48;h2=hour%10+48;WriteAddress(1,7);WriteData(h1);delaynms(20);WriteAddress(1,8);WriteData(h2);delaynms(20);void display_second()unsigned char second,s1,s2;second=Read1302(READ_SECOND);s1=second/10+48;s2=second%10+48;WriteAddress(1,13);WriteData(s1);delaynms(20);WriteAddress(1,14);WriteData(s2);delaynms(20);void display_minute()unsigned char minute,m1,m2;minute=Read1302(READ_MINUTE);m1=minute/10+48;m2=minute%10+48;WriteAddress(1,10);WriteData(m1);delaynms(20);WriteAddress(1,11);WriteData(m2);delaynms(20); /*主函数*/void main()TR0=1;EA=1;ET0=1;IT0=1;TMOD=0x01;TH0=0x3c;TL0=0xb0;LcdInitiate();initial1302();displ

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论