【文件属性】:
文件名称:DS1302 LCD12864
文件大小:127KB
文件格式:ZIP
更新时间:2017-11-14 17:43:35
时钟 adc转换
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,0xF7,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;
}
【文件预览】:
DS1302+LCD12864
----lcd.OBJ(6KB)
----SET_TIME.H(2KB)
----lcd.LST(5KB)
----DS1302.uvgui_Administrator.bak(132KB)
----lcd.c(2KB)
----set_time.OBJ(2KB)
----timer0.LST(3KB)
----DS1302_uvproj.bak(14KB)
----DS1302.uvopt(59KB)
----set_time.c(157B)
----ds1302.h(185B)
----MAIN.H(4KB)
----DS1302.uvgui.Administrator(131KB)
----LCD.H(327B)
----ds1302.OBJ(3KB)
----ds1302.c(876B)
----DS1302.M51(32KB)
----ADC.C(713B)
----DS1302.plg(7KB)
----DS1302_uvopt.bak(58KB)
----main.LST(26KB)
----DS1302.uvproj(14KB)
----timer0.c(13B)
----DS1302.hex(16KB)
----ADC.LST(3KB)
----ds1302.LST(3KB)
----timer0.OBJ(4KB)
----ADC.OBJ(3KB)
----main.OBJ(31KB)
----DS1302.lnp(66B)
----set_time.LST(1000B)
----adc.h(53B)
----main.c(11KB)
时钟加adc转换
----DS1302_LCD12864.PWI(2KB)
----DS1302_LCD12864.DSN(103KB)
----Last Loaded DS1302_LCD12864.DBK(103KB)
----DS1302.hex(16KB)