您好,欢迎光临本网站![请登录][注册会员]  
文件名称: DS1302 LCD12864
  所属分类: 硬件开发
  开发工具:
  文件大小: 127kb
  下载次数: 0
  上传时间: 2014-10-25
  提 供 者: z8520*****
 详细说明: DS1302 LCD12864 时钟加adc转换,LED时钟加按钮调时间。代码及仿真 #include #include #define u_char unsigned char #include"ds1302.h" #include"lcd.h" #include"main.h" #include"adc.h" u_char judge_year(u_char); u_char count_week(u_char year,u_char month,u_char day); unsigned char code black_write[]= { 0xFF,0x1F,0xEF,0xF7,0xF7,0xEF,0x1F,0xFF,0xFF,0xF0,0xEF,0xDF,0xDF,0xEF,0xF0,0xFF, 0xFF,0xEF,0xEF,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xDF,0xDF,0xC0,0xDF,0xDF,0xFF,0xFF, 0xFF,0x8F,0xF7,0xF7,0x F7,0x77,0x8F,0xFF,0xFF,0xCF,0xD7,0xDB,0xDD,0xDE,0xCF,0xFF, 0xFF,0xCF,0xF7,0x77,0x77,0xB7,0xCF,0xFF,0xFF,0xE7,0xDF,0xDF,0xDF,0xEE,0xF1,0xFF, 0xFF,0xFF,0x3F,0xDF,0xEF,0x07,0xFF,0xFF,0xFF,0xF8,0xFB,0xDB,0xDB,0xC0,0xDB,0xFF, 0xFF,0x07,0xF7,0x77,0x77,0xF7,0xF7,0xFF,0xFF,0xE6,0xDE,0xDF,0xDF,0xEE,0xF1,0xFF, 0xFF,0x1F,0xEF,0x77,0x77,0xE7,0xFF,0xFF,0xFF,0xF0,0xEE,0xDF,0xDF,0xEE,0xF1,0xFF, 0xFF,0xC7,0xF7,0xF7,0x37,0xC7,0xF7,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xFF,0xFF, 0xFF,0x8F,0x77,0xF7,0xF7,0x77,0x8F,0xFF,0xFF,0xE3,0xDD,0xDE,0xDE,0xDD,0xE3,0xFF, 0xFF,0x1F,0xEF,0xF7,0xF7,0xEF,0x1F,0xFF,0xFF,0xFF,0xCE,0xDD,0xDD,0xEE,0xF0,0xFF}; sbit k1=P3^4; sbit k2=P3^5; sbit k3=P3^6; sbit k4=P3^7; sbit k=P3^2; int int_count=0; int ret=0; int stop=0; int main() { int i,temp,j=0;u_char dat[7];u_char adc_data0,adc_data1,adc_data; u_char date[]={0,59,21,28,9,7,14};//秒分时日月周年 u_char time[14]; init_lcd(); IT0=1; EX0=1; IP=0x01; for(i=0;i<7;i++) { temp=date[i]/10; date[i]=date[i]; date[i]=temp*16+date[i]; } write_data(0x8e,0x00);//什么意思?? for(i=0;i<7;i++) write_data(reg_write_address[i],date[i]); TMOD|=0x01; TH0=0xB0;//设初值 TL0=0x3C;//设初值 ET0=1; //中断位置高 EA=1; //开中断 TR0=1; //启动中断 while(1){ if(flag==1) { flag=0; j=0; for(i=0;i<7;i++){ dat[i]=read_data(reg_read_address[i]); //什么意思? time[j++]=dat[i]&0xf; time[j++]=dat[i]/16; } display(0,0,tim+time[13]*16,8); display(0,8,tim+time[12]*16,8); display(0,16,year,16); display(0,32,tim+time[9]*16,8); display(0,40,tim+time[8]*16,8); display(0,48,year+32,16); display(0,64,tim+time[7]*16,8); display(0,72,tim+time[6]*16,8); display(0,80,year+64,16); display(2,0,week,16); display(2,16,week+32,16); display(2,32,digtal+(time[10]-1)*32,16); i=5; for(j=7;j>=0;j--) //什么意思 ? { if(j!=2&&j!=5) display(4,(7-j)*8,tim+time[i--]*16,8); else{ if(flash==0) display(4,(7-j)*8,tim+10*16,8); else if(flash==1) display(4,(7-j)*8,tim+11*16,8); } } /************************************** AD转换 AD转换有什么用? *************************************/ adc_data=read_adc_data(); adc_data0=(adc_data*5)/255; adc_data1=((adc_data*5)%255)*10/255; for(j=0;j<4;j++) display(4,72+(j*8),v+j*16,8); display(4,104,tim+adc_data0*16,8); display(4,112,v+4*16,8); display(4,120,tim+adc_data1*16,8); } while(ret!=0); } } void time0() interrupt 1 { count++; TH0=0xB0; TL0=0x3C; if(count==20){ flash=~flash; count=0; flag=1; } } void interrupt0() interrupt 0 //此中断函数全部调节时间,是这个程序的精华,本来想分开,但是那样会带来的开销大,所以全写在了一起; { int i;u_char temp,t1,t2,year=0,leap_year,week,day; t1=temp_time[6]/16; t2=temp_time[6]&0xf; leap_year=t1*10+t2; day=(temp_time[3]/16)*10+(temp_time[3]&0xf); if(k1==0){ if(stop==0) { ret++; for(i=0;i<7;i++) temp_time[i]=read_data(reg_read_address[i]);} int_count++; stop++; if(k1==0&&int_count==1) { t1=temp_time[0]/16; t2=temp_time[0]&0xf; display(4,48,tim+t1*16,8); display(4,56,tim+t2*16,8); t1=temp_time[6]/16; t2=temp_time[6]&0xf; display(0,0,black_write+t1*16,8); display(0,8,black_write+t2*16,8); } else if(k1==0&&int_count==2) { t1=temp_time[6]/16; t2=temp_time[6]&0xf; display(0,0,tim+t1*16,8); display(0,8,tim+t2*16,8); t1=temp_time[4]/16; t2=temp_time[4]&0xf; display(0,32,black_write+t1*16,8); display(0,40,black_write+t2*16,8); } else if(k1==0&&int_count==3) { t1=temp_time[4]/16; t2=temp_time[4]&0xf; display(0,32,tim+t1*16,8); display(0,40,tim+t2*16,8); t1=temp_time[3]/16; t2=temp_time[3]&0xf; display(0,64,black_write+t1*16,8); display(0,72,black_write+t2*16,8); } else if(k1==0&&int_count==4) { t1=temp_time[3]/16; t2=temp_time[3]&0xf; display(0,64,tim+t1*16,8); display(0,72,tim+t2*16,8); t1=temp_time[2]/16; t2=temp_time[2]&0xf; display(4,0,black_write+t1*16,8); display(4,8,black_write+t2*16,8); } else if(k1==0&&int_count==5) { t1=temp_time[2]/16; t2=temp_time[2]&0xf; display(4,0,tim+t1*16,8); display(4,8,tim+t2*16,8); t1=temp_time[1]/16; t2=temp_time[1]&0xf; display(4,24,black_write+t1*16,8); display(4,32,black_write+t2*16,8); } else if(k1==0&&int_count==6) { t1=temp_time[1]/16; t2=temp_time[1]&0xf; display(4,24,tim+t1*16,8); display(4,32,tim+t2*16,8); temp=read_data(0x81); t1=temp_time[0]/16; t2=temp_time[0]&0xf; display(4,48,black_write+t1*16,8); display(4,56,black_write+t2*16,8); } else if(int_count==7) int_count=0; } else if(k2==0||k3==0) { if(int_count==1)//调节年 { t1=temp_time[6]/16; t2=temp_time[6]&0xf; if(k2==0) temp_time[6]=t1*10+t2+1; else temp_time[6]=t1*10+t2-1; if(temp_time[6]==-1) temp_time[6]=0; leap_year=temp_time[6]; if(temp_time[4]==2) { year=judge_year(leap_year); if(year==0&&day>28){ temp_time[3]=40; display(0,64,tim+(temp_time[3]/16)*16,8); display(0,72,tim+(temp_time[3]&0xf)*16,8); } } temp_time[5]=week=count_week(leap_year,temp_time[4],(temp_time[3]/16)*10+(temp_time[3]&0xf)); t1=temp_time[6]/10; t2=temp_time[6]; temp_time[6]=t1*16+t2; display(0,0,black_write+(temp_time[6]/16)*16,8); display(0,8,black_write+(temp_time[6]&0xf)*16,8); display(2,32,digtal+(temp_time[5]-1)*32,16); } else if(int_count==2)//调节月 { t1=temp_time[4]/16; t2=temp_time[4]&0xf; if(k2==0) temp_time[4]=t1*10+t2+1; else temp_time[4]=t1*10+t2-1; if(temp_time[4]<1) temp_time[4]=1; if(temp_time[4]==13) temp_time[4]=1; else if(temp_time[4]==2){ year=judge_year(leap_year); if(year==0&&day>28) temp_time[3]=40; else if(year==1&&day>29) temp_time[3]=41; display(0,64,tim+(temp_time[3]/16)*16,8); display(0,72,tim+(temp_time[3]&0xf)*16,8); } else if(temp_time[4]==4||temp_time[4]==6||temp_time[4]==9||temp_time[4]==11) { if(day>30) temp_time[3]=48; display(0,64,tim+(temp_time[3]/16)*16,8); display(0,72,tim+(temp_time[3]&0xf)*16,8); } t1=temp_time[4]/10; t2=temp_time[4]; temp_time[4]=t1*16+t2; week=count_week(leap_year,temp_time[4],(temp_time[3]/16)*10+(temp_time[3]&0xf)); temp_time[5]=week; display(0,32,black_write+(temp_time[4]/16)*16,8); display(0,40,black_write+(temp_time[4]&0xf)*16,8); display(2,32,digtal+(temp_time[5]-1)*32,16); } else if(int_count==3)//调节日 { if(temp_time[4]==2){ year=judge_year(leap_year); } t1=temp_time[3]/16; t2=temp_time[3]&0xf; if(k2==0) temp_time[3]=t1*10+t2+1; else temp_time[3]=t1*10+t2-1; if(temp_time[3]<1) temp_time[3]=1; if(year==1&&temp_time[4]==2&&temp_time[3]==30) temp_time[3]=29; else if(year==0&&temp_time[4]==2&&temp_time[3]==29) temp_time[3]=28; else if(temp_time[4]==4||temp_time[4]==6||temp_time[4]==9||temp_time[4]==17) { if(temp_time[3]==31) temp_time[3]=30; } else if(temp_time[3]==32) temp_time[3]=31; week=count_week(leap_year,temp_time[4],temp_time[3]); temp_time[5]=week; t1=temp_time[3]/10; t2=temp_time[3]; temp_time[3]=t1*16+t2; display(0,64,black_write+(temp_time[3]/16)*16,8); display(0,72,black_write+(temp_time[3]&0xf)*16,8); display(2,32,digtal+(temp_time[5]-1)*32,16); } else if(int_count==4)//调节小时 { t1=temp_time[2]/16; t2=temp_time[2]&0xf; if(k2==0) temp_time[2]=t1*10+t2+1; else temp_time[2]=t1*10+t2-1; if(temp_time[2]<0) temp_time[2]=0; if(temp_time[2]>23) temp_time[2]=0; t1=temp_time[2]/10; t2=temp_time[2]; temp_time[2]=t1*16+t2; display(4,0,black_write+(temp_time[2]/16)*16,8); display(4,8,black_write+(temp_time[2]&0xf)*16,8); } else if(int_count==5) { t1=temp_time[1]/16; t2=temp_time[1]&0xf; if(k2==0) temp_time[1]=t1*10+t2+1; else temp_time[1]=t1*10+t2-1; if(temp_time[1]<0) temp_time[1]=0; if(temp_time[1]>59) temp_time[1]=0; t1=temp_time[1]/10; t2=temp_time[1]; temp_time[1]=t1*16+t2; display(4,24,black_write+(temp_time[1]/16)*16,8); display(4,32,black_write+(temp_time[1]&0xf)*16,8); } else if(int_count==6) { t1=temp_time[0]/16; t2=temp_time[0]&0xf; if(k2==0) temp_time[0]=t1*10+t2+1; else temp_time[0]=t1*10+t2-1; if(temp_time[0]<0) temp_time[0]=0; if(temp_time[0]>23) temp_time[0]=0; t1=temp_time[0]/10; t2=temp_time[0]; temp_time[0]=t1*16+t2; display(4,48,black_write+(temp_time[0]/16)*16,8); display(4,56,black_write+(temp_time[0]&0xf)*16,8); } } else if(k4==0) { for(i=0;i<7;i++) write_data(reg_write_address[i],temp_time[i]); ret=0; stop=0; int_count=0; } } u_char judge_year(u_char y)//判断是否是润年 { int year=2000+(int)y; if(year%4==0&&year0!=0) return 1; else if(year0==0&&year%400==0) return 1; else return 0; } u_char count_week(u_char year,u_char month,u_char day)//计算周几的函数 { u_char t1,t2,week; t1=month/16; t2=month&0xf; month=t1*10+t2; week=year+(year/4)+(20/4)-2*20+(26*(month+1)/10)+day-1; week=week%7; if(week==0) week=7; return week; } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 时钟 adc转换
 输入关键字,在本站1000多万海量源码库中尽情搜索: