文末下载完整资料
sbit DS1302CE=P0^0;
sbit DS1302CK=P0^2;
sbit DS1302IO=P0^1;
extern bit DS18B20_Reset(void);
extern void DS18B20_Write(unsigned char command);
extern unsigned char DS18B20_Read(void);
sbit DQ=P1^0;
#define RSCLR P0_5=0//PORTC &=~ BIT(PORTC0)
#define RSSET P0_5=1//PORTC |= BIT(PORTC0)
#define RWCLR P0_6=0//PORTC &=~ BIT(PORTC1)
#define RWSET P0_6=1//PORTC |= BIT(PORTC1)
#define ENCLR P0_7=0//PORTC &=~ BIT(PORTC2)
#define ENSET P0_7=1//PORTC |= BIT(PORTC2)
extern void lcd_delay(unsigned int delaytime);
extern void write_lcd_command(unsigned char write_command);
extern void write_lcd_data(unsigned char write_data);
extern void initize_lcd(void);
extern void lcd_displaystr(unsigned char x,unsigned char y,const unsigned char *str);
extern void lcd_displaystr_ram(unsigned char x,unsigned char y,unsigned char *str);
带温度测量LCD显示的实时时钟
extern void Init_DS1302_RTC(void);
extern unsigned char Read_DS1302_RTC(unsigned char RTC_Address);
extern void Write_DS1302_RTC(unsigned char RTC_Address,unsigned char RTC_Data);
#include
#include "1602LCDDriver.h"
#include "DS18B20Driver.h"
#include "DS1302Driver.h"
//#include "tiaozheng.h"
#include
struct TimerStruct
{
unsigned char Year;
unsigned char Month;
unsigned char Day;
unsigned char Week;
unsigned char Hour;
unsigned char Minute;
unsigned char Second;
};
//const unsigned char DATECODE1[]={"Tiaosh"};
//const unsigned char DATECODE[]={"Date:"};
//const unsigned char TIMECODE[]={"Time:"};
const unsigned char DATECODE1[]={"TH"};
const unsigned char DATECODE2[]={"DF"};
const unsigned char DATECODE3[]={"DJ"};
//const unsigned char DATECODE4[]={' '};
sbit key1=P1^2;
sbit key2=P1^3;
sbit key3=P1^4;
sbit sound=P1^1;
sbit k1=P0^3;
sbit k2=P0^4;
unsigned char mins,hours,days,months,weeks,years;
unsigned char a,b,c,k,flag1,flag2,flag3,flag4,flag5;
unsigned char Minute1,Hour1,Day1,Month1,Week1,Year1;
unsigned char Minute2,Hour2,Day2,Month2,Week2,Year2;
unsigned char DATECODE22[1]={' '};
unsigned char DATECODE33[1]={' '};
//struct TimerStruct *Real;
struct TimerStruct RealClock;
unsigned char DateBuffer1[]={"2006/08/18/5"};
unsigned char TimeBuffer1[]= {"23:50:00"};
//const unsigned char DATECODE[]={"Date:"};
//const unsigned char TIMECODE[]={"Time:"};
unsigned char DateBuffer[]={"2005/01/01/5"};
unsigned char TimeBuffer[]= {"00:00:00"};
unsigned char LCDDisplayBuffer[]={" "};
unsigned int SecondCounter;
//蜂鸣器测试
void fmq_fre(unsigned char f)
{
unsigned int i,j;
for(i=f;i>0;i--)
for(j=248;j>0;j--); //延时0.5MS
}
void fmq_delay(unsigned char delaytimef)
{
unsigned char j,h;
for(j=delaytimef;j>0;j--)
//for(k=200;k>0;k--)
for(h=248;h>0;h--)
{
sound=1;
fmq_fre(1);
sound=0;
fmq_fre(1);
}
}
//jdq的测试
void jdq_delay(unsigned char delaytimej)
{
unsigned char k,i,j;
for (k=delaytimej;k>0;k--)
for(i=200;i>0;i--)
for(j=248;j>0;j--);
}
void jdq(void)
{
k1=0;
k2=0;
}
//时间调整
void tiao_delay(void)
{
unsigned char i,j;
for(i=10;i>0;i--)
for(j=248;j>0;j--);
}
unsigned char change( void )
{
while(flag1)
{
if(key2==0) tiao_delay();
if(key2==0) a++;
if(key3==0) tiao_delay();
if(key3==0) a--;
switch(k)
{
case 1:
mins=a%60;
break;
case 2:
hours=a%24;
break;
case 3:
days=a%32;
break;
case 4:
weeks=a%8;
break;
case 5:
months=a%13;
break;
case 6:
years=a;
break;
}
TimeBuffer1[4]=mins%10+0x30; //分个位
TimeBuffer1[3]=mins/10+0x30;
TimeBuffer1[1]=hours%10+0x30; //时
TimeBuffer1[0]=hours/10+0x30;
DateBuffer1[9]=days%10+0x30; //日
DateBuffer1[8]=days/10+0x30;
DateBuffer1[6]=months%10+0x30;//月
DateBuffer1[5]=months/10+0x30;
DateBuffer1[11]=weeks%10+0x30;//星期
DateBuffer1[3]=years%10+0x30; //年
DateBuffer1[2]=years/10+0x30;
jdq_delay(2);
if(key1==0) tiao_delay();
if(key1==0) flag1=0;
write_lcd_command(12);
lcd_displaystr_ram(0,1,DateBuffer1);
lcd_displaystr_ram(1,1,TimeBuffer1);
}
}
void tiao1(void)
{
mins=mins-mins/16*6;
hours=hours-hours/16*6;
days=days-days/16*6;
months=months-months/16*6;
years=years-years/16*6;
TimeBuffer1[4]=mins%10+0x30; //分个位
TimeBuffer1[3]=mins/10+0x30;
TimeBuffer1[1]=hours%10+0x30; //时
TimeBuffer1[0]=hours/10+0x30;
DateBuffer1[9]=days%10+0x30; //日
DateBuffer1[8]=days/10+0x30;
DateBuffer1[6]=months%10+0x30;//月
DateBuffer1[5]=months/10+0x30;
DateBuffer1[11]=weeks%10+0x30;//星期
DateBuffer1[3]=years%10+0x30; //年
DateBuffer1[2]=years/10+0x30;
lcd_displaystr_ram(0,1,DateBuffer1);
lcd_displaystr_ram(1,1,TimeBuffer1);
write_lcd_command(0x0f);
write_lcd_command(0x80+0x45);
jdq_delay(2);
k=1,a=mins,flag1=1;
change(); //分
write_lcd_command(0x0f);
write_lcd_command(0x80+0x42);
jdq_delay(2);
k++,a=hours,flag1=1;
change(); //时
write_lcd_command(0x0f);
write_lcd_command(0x80+10);
jdq_delay(2);
k++,a=days,flag1=1;
change(); //日
}
void tiao2(void)
{
write_lcd_command(0x0f);
write_lcd_command(0x80+12);
jdq_delay(2);
k++,a=years,flag1=1;
change(); //星期
write_lcd_command(0x0f);
write_lcd_command(0x80+7);
jdq_delay(2);
k++,a=months,flag1=1;
change(); //月
write_lcd_command(0x0f);
write_lcd_command(0x80+4);
jdq_delay(2);
k++,a=years,flag1=1;
change(); //年
mins=mins+mins/10*6;
hours=hours+hours/10*6;
days=days+days/10*6;
months=months+months/10*6;
years=years+years/10*6;
jdq_delay(5);
}
//调整1302时间
void tiaozheng(struct TimerStruct *Real)
{
lcd_displaystr(0,14,DATECODE1);
mins=Real->Minute;
hours=Real->Hour;
days=Real->Day;
months=Real->Month;
weeks=Real->Week;
years=Real->Year;
tiao1();
tiao2();
write_lcd_command(0x01);//清屏
Write_DS1302_RTC(0x8e,0x00); //写控制
Write_DS1302_RTC(0x80,0x00); //写秒
Write_DS1302_RTC(0x82,mins); //写分
Write_DS1302_RTC(0x84,hours); //写时
Write_DS1302_RTC(0x86,days); //写日
Write_DS1302_RTC(0x88,months); //写月
Write_DS1302_RTC(0x8a,weeks); //写星期
Write_DS1302_RTC(0x8c,years); //写年
Write_DS1302_RTC(0x8e,0x80); //控制
initize_lcd();
Init_DS1302_RTC();
}
//调整蜂鸣器定时
void dingshif(void)
{
flag3=1;
lcd_displaystr(0,14,DATECODE2);
mins=Minute1;
hours=Hour1;
days=Day1;
//months=Month1;
//weeks=Week1;
//years=Year1;
tiao1();
tiao_delay();
mins=mins+mins/10*6;
hours=hours+hours/10*6;
days=days+days/10*6;
Minute1=mins;
Hour1=hours;
Day1=days;
//Month1=months;
//Week1=weeks;
//Year1=years;
write_lcd_command(0x01);//清屏
DATECODE22[0]='&';
if(flag4==1) DATECODE33[0]='!';
jdq_delay(5);
lcd_displaystr(0,14,DATECODE22);
lcd_displaystr(0,15,DATECODE33);
}
//调整继电器定时
void dingshij(void)
{
flag4=1;
lcd_displaystr(0,14,DATECODE3);
mins=Minute2;
hours=Hour2;
days=Day2;
//months=Month2;
//weeks=Week2;
//years=Year2;
tiao1();
mins=mins+mins/10*6;
hours=hours+hours/10*6;
days=days+days/10*6;
Minute2=mins;
Hour2=hours;
Day2=days;
// Month2=months;
//Week2=weeks;
//Year2=years;
k1=k2=1;
write_lcd_command(0x01); //清屏
DATECODE33[0]='!';
if(flag3==1) DATECODE22[0]='&';
jdq_delay(5);
lcd_displaystr(0,14,DATECODE22);
lcd_displaystr(0,15,DATECODE33);
}
全套资料免费下载:
关注v-x-公-众-号:【嵌入式基地】
后-台-回-复:【毕业设计】 即可获资料
回复【编程】即可获取
包括有:C、C++、C#、JAVA、Python、JavaScript、PHP、数据库、微信小程序、人工智能、嵌入式、Linux、Unix、QT、物联网、算法导论、大数据等资料