单片机驱动DS1302时间DS18B20温度12864液晶显示完整程序设计
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(k12){
for(iy=0;iy2;iy++)
for(ix=0;ix8;ix++){
y_lcd(iy+y);
x_lcd(ix+x);
w_lcd(shu[k][i]);
i++;
}
}
else{k-=12;
for(iy=0;iy2;iy++)
for(ix=0;ix16;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;i3;i++){
time=r_1302(k);
time1[i]=time;
add=add-8;;
time=time0x0f;
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,time0x0f);//: 显示日
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,time0x0f);//: 显示月
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,time0x0f);//: 显示年
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);
}
/////////////////////////显示时间完毕
单片机 DS1302 DS18B20 12864液晶显示 相关文章:
- FPGA的DSP性能揭秘(06-16)
- 基于单片机通用引脚的软件UART设计(10-16)
- 分时操作系统思想在单片机中的具体应用 (10-30)
- 基于AT89C51+DSP的双CPU伺服运动控制器的研究(05-26)
- 关于RTX51 TINY的分析与探讨(05-30)
- 基于MC9S12DGl28单片机的智能寻迹车设计(04-03)