单片机驱动DS1302时间DS18B20温度12864液晶显示完整程序设计
    

程序说明:这是一个用51单片机驱动DS1302时间模块+DS18B20温度传感器模块+12864液晶显示完整程序设计实例,有四个键盘KEY0 到KEY3,key0是修改时间的 首先是秒到分到时到年到月到日到星期 key1是加1 key2是减一 在修改时间状态再按一下key3的时候就出去并修改时间日期,在平时状态按着key3再按着key2 就会打开lcd 的灯 单单是只按key3那就是把灯关了。

文件一:DS1302驱动.c

#include<reg52.h>

//ds1302
sbit sclk=P0^3;
sbit io=P0^4;
sbit rst=P0^5;
sbit acc0=ACC^0;
sbit acc1=ACC^1;
sbit acc2=ACC^2;
sbit acc3=ACC^3;
sbit acc4=ACC^4;
sbit acc5=ACC^5;
sbit acc6=ACC^6;
sbit acc7=ACC^7;

delay()
{
unsigned char i;
i=10;
i=10;
i=10;
i=10;
i=10;
i=10;
i=10;}
w_1302(unsigned char dat,unsigned char shu){//写一个八位的数去DS1302 //上升效 ;;;选写地址再写数据

ACC=dat;//地址
sclk=0;
rst=1;//
io=acc0;///
sclk=0;
delay();
sclk=1;
io=acc1;
sclk=0;
delay();
sclk=1;
io=acc2;
sclk=0;
delay();
sclk=1;
io=acc3;
sclk=0;
delay();
sclk=1;
io=acc4;
sclk=0;
delay();
sclk=1;
io=acc5;
sclk=0;
delay();
sclk=1;
io=acc6;
sclk=0;
delay();
sclk=1;
io=acc7;
sclk=0;
delay();
sclk=1;///


//sclk=0;
ACC=shu; //数据
io=acc0;///
sclk=0;
delay();
sclk=1;
io=acc1;
sclk=0;
delay();
sclk=1;
io=acc2;
sclk=0;
delay();
sclk=1;
io=acc3;
sclk=0;
delay();
sclk=1;
io=acc4;
sclk=0;
delay();
sclk=1;
io=acc5;
sclk=0;
delay();
sclk=1;
io=acc6;
sclk=0;
delay();
sclk=1;
io=acc7;
sclk=0;
delay();
sclk=1;///

rst=0;
sclk=0;
} ///写完毕
unsigned char r_1302(unsigned char ADD){

sclk=0;
rst=1;
ACC=ADD; //地址
io=acc0;///
sclk=0;
delay();
sclk=1;
io=acc1;
sclk=0;
delay();
sclk=1;
io=acc2;
sclk=0;
delay();
sclk=1;
io=acc3;
sclk=0;
delay();
sclk=1;
io=acc4;
sclk=0;
delay();
sclk=1;
io=acc5;
sclk=0;
delay();
sclk=1;
io=acc6;
sclk=0;
delay();
sclk=1;
io=acc7;
sclk=0;/////
delay();
sclk=1;
delay();
sclk=0;
acc0=io;
delay();
sclk=1;
delay();
sclk=0;
acc1=io;
delay();
sclk=1;
delay();
sclk=0;
acc2=io;
delay();
sclk=1;
delay();
sclk=0;
acc3=io;
delay();
sclk=1;
delay();
sclk=0;
acc4=io;
delay();
sclk=1;
delay();
sclk=0;
acc5=io;
delay();
sclk=1;
delay();
sclk=0;
acc6=io;
delay();
sclk=1;
delay();
sclk=0;
acc7=io;
delay();

rst=0;
sclk=0;
return(ACC);
}
ds1302_c()
{
w_1302(0x80,0x80);
w_1302(0x8e,0x00);

w_1302(0x80,0x50); //;秒
w_1302(0x82,0x06); // 分=0
w_1302(0x84,0x01); //时 =0
w_1302(0x86,0x22); //
w_1302(0x88,0x11);//
w_1302(0x8a,0x04);//
w_1302(0x8b,0x07);//

w_1302(0x8e,0x80);
w_1302(0x90,0xa6);
w_1302(0x80,0x00);
}
main(){
rst=0;
ds1302_c();

for(;;){
P2=r_1302(0x81);
}
}

---------------------------------------------------------------------------------------------------------------
文件2:完全版 有关灯键.c

#include<reg52.h>
sbit di = P2^7; ////////定义引脚
sbit rw = P2^6;
sbit e = P2^5;
sbit cs1 = P2^4;
sbit cs2 = P2^1;
sbit lcd_d = P2^0;
sbit key0 = P2^3;
sbit key1 = P2^2;
sbit key2 = P1^0;
sbit key3 = P1^1;
sbit P07 = P0^7;
sbit P06 = P0^6;
sbit P05 = P0^5;
sbit P04 = P0^4;
sbit P03 = P0^3;
//ds1302
sbit sclk=P1^4;
sbit io=P1^3;
sbit rst=P1^2;
sbit acc0=ACC^0;
sbit acc1=ACC^1;
sbit acc2=ACC^2;
sbit acc3=ACC^3;
sbit acc4=ACC^4;
sbit acc5=ACC^5;
sbit acc6=ACC^6;
sbit acc7=ACC^7;
typedef unsigned char byte;
typedef unsigned int word;
sbit KEY=P3^7;//根据实际情况定义端口ds1820
unsigned char key_time=0; //全局变量


//////////////////////////////////温度
//ds18b20数字温度传感器模块程序

void delay1(word useconds)
{
for(;useconds>0;useconds--);
}

//复位
byte ow_reset(void)
{
byte presence;
KEY = 0; //pull DQ line low
delay1(29); // leave it low for 480us
KEY = 1; // allow line to return high
delay1(3); // wait for presence
presence = KEY; // get presence signal
delay1(25); // wait for end of timeslot
return(presence); // presence signal returned
} // 0=presence, 1 = no part

//从 1-wire 总线上读取一个字节
byte read_byte(void)
{
byte i;
byte value = 0;
for (i=8;i>0;i--)
{
value>>=1;
KEY = 0; // pull DQ low to start timeslot
KEY = 1; // then return high
delay1(1); //for (i=0; i<3; i++);
if(KEY)value|=0x80;
delay1(6); // wait for rest of timeslot
}
return(value);
}

//向 1-WIRE 总线上写一个字节
void write_byte(char val)
{
byte i;
for (i=8; i>0; i--) // writes byte, one bit at a time
{
KEY = 0; // pull DQ low to start timeslot
KEY = val&0x01;
delay1(5); // hold value for remainder of timeslot
KEY = 1;
val=val/2;
}
delay1(5);
}

//读取温度
float wendu(void)
{
float tem;
union{
byte c[2];
int x;
}temp;

ow_reset();
write_byte(0xCC); // Skip ROM
write_byte(0xBE); // Read Scratch Pad
temp.c[1]=read_byte(); //lsd
temp.c[0]=read_byte(); //msd
ow_reset();
write_byte(0xCC); //Skip ROM
write_byte(0x44); // Start Conversion

tem=0.0;
if(temp.x & 0x01) tem+=0.0625;temp.x>>=1;
if(temp.x & 0x01) tem+=0.125;temp.x>>=1;
if(temp.x & 0x01) tem+=0.25;temp.x>>=1;
if(temp.x & 0x01) tem+=0.5;temp.x>>=1;
tem+=temp.x;

return tem;
}


void cs1_lcd(){ ////////选择左边
bit a=1;
cs1=a;
cs2=!a;
}
void cs2_lcd(){ ////////选择右边
bit a=1;
cs1=!a;
cs2=a;
}
void busy_lcd(){//////判断忙
bit a=1;
di=!a;
rw=a;
e=a;
while(P07==a);
}
w_lcd(unsigned b){ ///写a到12864
bit a=1;
busy_lcd();
rw =!a;
di =a;
P0=b;
e=a;
e=!a;
}
void dis_lcd(){//打开显示选择第一行显示
bit a=1;
busy_lcd();
rw=!a;
di=!a;
P0=0x3f;
e=a;
e=!a;
P0=0xc0;
e=a;
e=!a;
}
y_lcd(unsigned a){///由A确定y轴
bit b=1;
busy_lcd();
rw=!b;
di=!b;
P0=a;
P07=b;
P06=!b;
P05=b;
P04=b;
P03=b;
e=b;
e=!b;
}
x_lcd(unsigned a){//由a确定X轴
bit b=1;
busy_lcd();
rw=!b;
di=!b;
P0=a;
P07=!b;
P06=b;
e=b;
e=!b;
}

void clr_lcd(){///清屏
bit a=0;
unsigned x,y,date,i;
cs1_lcd();
date=0x00;
for(i=0;i<2;i++){
for(y=0;y<8;y++)
for(x=0;x<64;x++){
x_lcd(x);
y_lcd(y);
w_lcd(date);
}
cs2_lcd();}
}

unsigned char code shu[18][16]={///0到9数字
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},//0
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},//1
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},//2
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},//3
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},///4
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},//5
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},//6
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},//7
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},//8
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00},//9
{0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},// :
{0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},// /
};
unsigned char code shu1[9][32]={///
{0x02,0x42,0x42,0xFE,0x42,0x42,0xFE,0x02,0x02,0xFA,0x02,0x02,0xFE,0x00,0x00,0x00,0x08,0x08,0x08,0x07,0x84,0x44,0x23,0x18,0x06,0x01,0x3E,0x40,0x43,0x40,0x78,0x00},//现12
{0x00,0x04,0x04,0xC4,0x64,0x9C,0x87,0x84,0x84,0xE4,0x84,0x84,0x84,0x84,0x04,0x00,0x04,0x02,0x01,0x7F,0x00,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x00},//在 13
{0x00,0xFC,0x44,0x44,0x44,0xFC,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,0x00,0x07,0x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7F,0x00,0x00,0x00,0x00},//时 14
{0x00,0xF8,0x01,0x06,0x00,0xF0,0x92,0x92,0x92,0x92,0xF2,0x02,0x02,0xFE,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x07,0x04,0x04,0x04,0x04,0x07,0x40,0x80,0x7F,0x00,0x00},//间 15
{0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00,0x48,0x46,0x41,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x49,0x41,0x40,0x00},//星 16
{0x00,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,0x42,0x22,0x1B,0x02,0x02,0x0A,0x33,0x62,0x18,0x07,0x02,0x22,0x42,0x3F,0x00,0x00},//期 17
{0x10,0x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00,0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00},//温18
{0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00,0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0x12,0x2A,0x26,0x42,0xC0,0x40,0x00},//度19
};

unsigned char time1[7]={0x30,0x00,0x16,8,7,2,8};//分别是秒,分,时,日,月,星期,年 次子程序出自http://www.51hei.com hkcd斑竹,已通过测试无误。
delay()
{
unsigned char i;
i=10;
i=10;
i=10;
i=10;
i=10;
i=10;
i=10;}
w_1302(unsigned char dat,unsigned char shu){//写一个八位的数去DS1302 //上升效 ;;;选写地址再写数据

ACC=dat;//地址
sclk=0;
rst=1;//
io=acc0;///
sclk=0;
delay();
sclk=1;
io=acc1;
sclk=0;
delay();
sclk=1;
io=acc2;
sclk=0;
delay();
sclk=1;
io=acc3;
sclk=0;
delay();
sclk=1;
io=acc4;
sclk=0;
delay();
sclk=1;
io=acc5;
sclk=0;
delay();
sclk=1;
io=acc6;
sclk=0;
delay();
sclk=1;
io=acc7;
sclk=0;
delay();
sclk=1;///


//sclk=0;
ACC=shu; //数据
io=acc0;///
sclk=0;
delay();
sclk=1;
io=acc1;
sclk=0;
delay();
sclk=1;
io=acc2;
sclk=0;
delay();
sclk=1;
io=acc3;
sclk=0;
delay();
sclk=1;
io=acc4;
sclk=0;
delay();
sclk=1;
io=acc5;
sclk=0;
delay();
sclk=1;
io=acc6;
sclk=0;
delay();
sclk=1;
io=acc7;
sclk=0;
delay();
sclk=1;///

rst=0;
sclk=0;
} ///写完毕
unsigned char r_1302(unsigned char ADD){

sclk=0;
rst=1;
ACC=ADD; //地址
io=acc0;///
sclk=0;
delay();
sclk=1;
io=acc1;
sclk=0;
delay();
sclk=1;
io=acc2;
sclk=0;
delay();
sclk=1;
io=acc3;
sclk=0;
delay();
sclk=1;
io=acc4;
sclk=0;
delay();
sclk=1;
io=acc5;
sclk=0;
delay();
sclk=1;
io=acc6;
sclk=0;
delay();
sclk=1;
io=acc7;
sclk=0;/////
delay();
sclk=1;

delay();
sclk=0;
acc0=io;
delay();
sclk=1;
delay();
sclk=0;
acc1=io;
delay();
sclk=1;
delay();
sclk=0;
acc2=io;
delay();
sclk=1;
delay();
sclk=0;
acc3=io;
delay();
sclk=1;
delay();
sclk=0;
acc4=io;
delay();
sclk=1;
delay();
sclk=0;
acc5=io;
delay();
sclk=1;
delay();
sclk=0;
acc6=io;
delay();
sclk=1;
delay();
sclk=0;
acc7=io;
delay();

rst=0;
sclk=0;
return(ACC);
}
ds1302_c()
{
w_1302(0x80,0x80);
w_1302(0x8e,0x00);
w_1302(0x80,time1[0]); //;秒
w_1302(0x82,time1[1]); // 分=0
w_1302(0x84,time1[2]); //时 =0
w_1302(0x86,time1[3]); // 日
w_1302(0x88,time1[4]);// 月
w_1302(0x8a,time1[5]);//星期
w_1302(0x8c,time1[6]);//年
w_1302(0x8e,0x80);
w_1302(0x90,0xb8);
w_1302(0x80,0x00);
}

//x_lcd(unsigned a){//由a确定X轴 //y_lcd(unsigned a){///由A确定y轴
//void dis_lcd(){//打开显示选择第一行显示 //w_lcd(unsigned b){ ///写a到12864
//void busy_lcd(){//////判断忙 //void cs1_lcd(){ ////////选择左边
//void cs2_lcd(){ ////////选择右边
d12864_lcd(unsigned char x,y,k){
unsigned char ix,iy,i;
dis_lcd();//打开显示
if(x>63){
x=x-64;
cs2_lcd();
}
else cs1_lcd();
i=0;
if(k<12){
for(iy=0;iy<2;iy++)
for(ix=0;ix<8;ix++){
y_lcd(iy+y);
x_lcd(ix+x);
w_lcd(shu[k][i]);
i++;
}
}
else{k-=12;
for(iy=0;iy<2;iy++)
for(ix=0;ix<16;ix++){
y_lcd(iy+y);
x_lcd(ix+x);
w_lcd(shu1[k][i]);
i++;
}
}
}

time_lcd(){
unsigned char y,k,time,add,i,we1,we2;
add=128;///////必须是小于64-8大于64
d12864_lcd(0,0,12);//: 北
d12864_lcd(16,0,13);//: 京
d12864_lcd(31,0,14);//: 时
d12864_lcd(47,0,15);//: 间
k=0x81;
y=0; //在第几行显示
for(i=0;i<3;i++){
time=r_1302(k);
time1[i]=time;
add=add-8;;
time=time&0x0f;
d12864_lcd(add,y,time);///秒个位
add=add-8;
time=r_1302(k);
time&=0xf0;
time>>=4;
d12864_lcd(add,y,time);//秒十位
add=add-8;;
k+=2;
}
d12864_lcd(40+64,y,10);//:
d12864_lcd(16+64,y,10);//: 显示两点
//
time1[5]=r_1302(0x8b);
d12864_lcd(64,4,16);//: 星
d12864_lcd(64+16,4,17);//: 期
r_1302(0x8b);//读星期
d12864_lcd(64+32,4,r_1302(0x8b));//: 读星期几`并显示
////
y=2;//在第四行显示
add=56+16;
time=r_1302(0x87);
time1[3]=time;
d12864_lcd(add,y,time&0x0f);//: 显示日
time=r_1302(0x87);
time&=0xf0;
time>>=4;
add-=8;
d12864_lcd(add,y,time); //显示日的十位
add-=8;
add-=8;
time1[4]=time=r_1302(0x89);
d12864_lcd(add,y,time&0x0f);//: 显示月
time=r_1302(0x89);
time&=0xf0;
time>>=4;
add-=8;
d12864_lcd(add,y,time); //显示月的十位
add-=8;
add-=8;
time1[6]=time=r_1302(0x8d);
d12864_lcd(add,y,time&0x0f);//: 显示年
time=r_1302(0x8d);
time&=0xf0;
time>>=4;
add-=8;
d12864_lcd(add,y,time); //显示年的十位
//////读完

d12864_lcd(40+16,y,11);//:
d12864_lcd(16+16,y,11);//: 显示两/
add-=8;
d12864_lcd(add,y,0);//: 0
add-=8;
d12864_lcd(add,y,2);//: 2

d12864_lcd(0,4,18);//: 温
d12864_lcd(16,4,19);//: 度
we1=wendu();
we2=we1/10;
d12864_lcd(32,4,we2);//: 2
we2=we1-we2*10;
d12864_lcd(40,4,we2);//: 显示温度值
cs1_lcd();
y_lcd(4);
x_lcd(50);
w_lcd(0x18);
x_lcd(51);
w_lcd(0x18);
}
/////////////////////////显示时间完毕


hei_lcd(unsigned char x,y){ //全黑用来做闪标用
char iy,ix,di,i;
di=0x00;
if(x>63){
x=x-64;
cs2_lcd();
}
else cs1_lcd();
i=0;
for(iy=0;iy<2;iy++){
for(ix=0;ix<16;ix++){
y_lcd(iy+y);
x_lcd(ix+x);
w_lcd(di);
}
}
}
key_t(){ //键盘key1 加1 key2 减1

if(!key1){
key_time++;
delay1(20000);
while(!key1);
}
if(!key2){
key_time--;
delay1(20000);
while(!key2);
}
}


void delay11(word useconds)
{
for(;useconds>0;useconds--)
key_t();
}

time_key(){
unsigned char keyd,ktime;
unsigned int year;
word kk;
keyd=0;
kk=10000;///闪动快慢
if(!key0){
for(;;){
if(!key0){
keyd=keyd+1;
delay1(500);
if(keyd>8)keyd=1;
key_time=0;//////每设牟换一个就把存设时间清0
key0=1;
while(!key0);
key0=1;
}
////////////////////////闪程序
if(keyd==1){//=1进入秒闪 同时设置秒时间
key_time=(time1[0]&0x0f)+((time1[0]&0xf0)>>4)*10; //将数姐里的数度到key_time里 10进制
hei_lcd(112,0);//x y
delay11(kk);//////闪动快慢
if(key_time>=60)key_time=0;
d12864_lcd(112,0,key_time/10);
d12864_lcd(120,0,key_time-(key_time/10)*10);
time1[0]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //换成BCD码存到数组里
delay1(10000);
}
if(keyd==2){//=1进入分闪 同时设置秒时间
key_time=(time1[1]&0x0f)+((time1[1]&0xf0)>>4)*10; //将数姐里的数度到key_time里 10进制
hei_lcd(88,0);//x y
delay11(kk);//////闪动快慢
if(key_time>=60)key_time=0;
d12864_lcd(88,0,key_time/10);
d12864_lcd(96,0,key_time-(key_time/10)*10);
delay1(10000);
time1[1]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //换成BCD码存到数组里
}
if(keyd==3){//=1进入时闪 同时设置秒时间
key_time=(time1[2]&0x0f)+((time1[2]&0xf0)>>4)*10; //将数姐里的数度到key_time里 10进制
hei_lcd(64,0);//x y
delay11(kk);//////闪动快慢
if(key_time>=24)key_time=0;
d12864_lcd(64,0,key_time/10);
d12864_lcd(72,0,key_time-(key_time/10)*10);
time1[2]=(key_time/10)<<4+(key_time-key_time/10);
delay1(10000);
time1[2]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //换成BCD码存到数组里
}
if(keyd==4){//=1进入年闪 同时设置秒时间
key_time=(time1[6]&0x0f)+((time1[6]&0xf0)>>4)*10; //将数姐里的数度到key_time里 10进制
hei_lcd(16,2);//x y
delay11(kk);//////闪动快慢
if(key_time>99)key_time=0;
d12864_lcd(16,2,key_time/10);
d12864_lcd(24,2,key_time-(key_time/10)*10);
time1[6]=(key_time/10)<<4+(key_time-key_time/10);
delay1(10000);
time1[6]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //换成BCD码存到数组里
}

if(keyd==5){//=1进入月闪 同时设置秒时间
key_time=(time1[4]&0x0f)+((time1[4]&0xf0)>>4)*10; //将数姐里的数度到key_time里 10进制
hei_lcd(40,2);//x y
delay11(kk);//////闪动快慢
if(key_time>=13)key_time=0;
d12864_lcd(40,2,key_time/10);
d12864_lcd(48,2,key_time-(key_time/10)*10);
time1[4]=(key_time/10)<<4+(key_time-key_time/10);
delay1(10000);
time1[4]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //换成BCD码存到数组里
}

if(keyd==6){//=1进入日闪 同时设置秒时间
key_time=(time1[3]&0x0f)+((time1[3]&0xf0)>>4)*10; //将数姐里的数度到key_time里 10进制
year=(time1[4]&0x0f)+(((time1[4]&0xf0)>>4)*10)+2000;
switch(time1[4]){ //计算闰月
case 1: ktime=31;break;
case 3: ktime=31;break;
case 5: ktime=31;break;
case 7: ktime=31;break;
case 8: ktime=31;break;
case 10: ktime=31;break;
case 12: ktime=31;break;
case 4: ktime=30;break;
case 6: ktime=30;break;
case 9: ktime=30;break;
case 11: ktime=30;break;
case 2: if(year%4==0&&year%100!=0||year%400==0) ktime=29;
else ktime=29;break;
}
hei_lcd(64,2);//x y
delay11(kk);//////闪动快慢
if(key_time>ktime)key_time=0;
d12864_lcd(64,2,key_time/10);
d12864_lcd(72,2,key_time-(key_time/10)*10);
time1[3]=(key_time/10)<<4+(key_time-key_time/10);
delay1(10000);
time1[3]=(((key_time/10)<<4)&0xf0)+(key_time-(key_time/10)*10); //换成BCD码存到数组里
}

if(keyd==7){//=1进入星期闪 同时设置秒时
char iy,ix,di,i;
key_time=time1[5];
di=0x00;
cs2_lcd();
i=0;
for(iy=0;iy<2;iy++){
for(ix=0;ix<8;ix++){
y_lcd(iy+4);
x_lcd(ix+96);
w_lcd(di);
}
di=00;
}
delay11(kk);//////闪动快慢
if(key_time>7)key_time=0;
d12864_lcd(96,4,key_time);
time1[5]=key_time;
delay1(10000);
time1[5]=key_time; //换成BCD码存到数组里
}
////////////////////
if(!key3)break;
}
ds1302_c(); ///更改时间
}
}

///////////////
lcd_key(){
if(!key3){
if(!key2)lcd_d=1;
else lcd_d=0;
}
}
main(){
ds1302_c();
clr_lcd();
for(;;){
time_lcd();
time_key();
lcd_key();
}
}

相关阅读
  • 单片机驱动ds1302时间ds18b20温度1
  • 51单片机带闹钟可调时间的电子时钟
  • 单片机驱动19264液晶显示汉字c程序
  • 51单片机的ds1302驱动程序
  • 基于spce061a单片机的mgls12864液
  • 单片机驱动52寸液晶显示器
  • 单片机驱动52寸液晶显示器
  • 基于HT48单片机的笔段型液晶显示的
  • 基于51 单片机的12864LCD 显示驱动
  • 基于AT89S52单片机的液晶显示温度
  • 基于linux的温度传感器ds18b20驱动
  • 单片机与液晶显示模块HS12864-1的
  • P51XA单片机与图形液晶显示器的接
  • DS1302时钟芯片显示时间C51程序
  • ds1302时钟芯片显示时间c51程序
  • 基于51单片机的TFT液晶显示设计
  • 单片机闹钟程序设计
  • PIC16F877单片机与DS1302时钟程序
  • 单片机程序设计中运用事件驱动机制
  • 基于HT48单片机的笔段型液晶显示的
  • 12864液晶电子时钟+温度显示
  •  



     
     
         

    收录时间:2016年10月17日 17:01:28 来源:单片机教程网 作者:匿名
    上一篇:电子设计大赛  (电脑版  手机版)
     
    创建分享人
    失之东隅
    最新问题
     
    喜欢此文章的还喜欢
    Copyright by www.chinabaike.com;All rights reserved. 联系:QQ:469681782