lcd1602 显示 ds18b20与lcd1602 总是出现 X95

求DS18B20测温程序,LCD1602显示程序,还有仿真图,8051单片机用的 - PIC单片机论坛 -
中国电子技术论坛 -
最好最受欢迎电子论坛!
后使用快捷导航没有帐号?
求DS18B20测温程序,LCD1602显示程序,还有仿真图,8051单片机用的
21:36:31  
求DS18B20测温程序,LCD1602显示程序,还有仿真图
16:04:27  
不错哦,值得学习
17:13:46  
仿真图,没有,有效果图。
22:31:47  
不错哦,值得学习
我是新手啊,做毕业设计用的
22:32:25  
仿真图,没有,有效果图。
DS18B20 LCD1206 自己做的板子。DS18B20 LCD1206 自己做的板子。
那个是毕业设计用的,关键就是仿真图啊
16:42:47  
20:28:04  
本人有一个小项目,是一个多功能电子表,整点报时,闹钟,时间设置,温度显示,用的就是LCD1602液晶屏现实的,需要否?
21:17:30  
有没有人有程序和图的
21:20:48  
有没有人有程序和图的
我有啊& &需要私聊& && && && && && && && && &
21:24:38  
我有啊& &需要私聊
用ds18b20测温度,lcd1602显示
21:24:39  
我有啊& &需要私聊
用ds18b20测温度,lcd1602显示
21:32:40  
用ds18b20测温度,lcd1602显示
恩恩&&有& && && && && && && && && && && && && && && && && &
03:29:15  
有NTC电阻测温,DTH11测温湿度,DS18B20的程序,STC15系列的,
17:19:25  
20:46:23  
Powered by
供应链服务
版权所有 (C) 深圳华强聚丰电子科技有限公司已解决问题
于AT89C51单片机和DS18B20温度传感器、LCD1602液晶显示的数字温度计编程C语言,我急用的,谢谢你了!!!
提问时间: 10:18:22
浏览次数:2359
/***********ds18b20子程序*************************/ /***********ds18b20延迟子函数(晶振12MHz )*******/ #include&reg51.h&gt
sbit DQ=P1^2; #define uchar unsigned char void delay_18B20(unsigned int i)
while(i--); } /**********ds18b20初始化函数**********************/ void Init_DS18B20(void)
unsigned char x=0
DQ = 1; //DQ复
delay_18B20(8); //稍做延
DQ = 0; //单片机将DQ拉
delay_18B20(80); //精确延时 大于 480u
DQ = 1; //拉高总
delay_18B20(4)
x=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失
delay_18B20(20); } /***********ds18b20读一个字节**************/ unsigned char ReadOneChar(void)
uchar dat = 0
for (i=8;i&0;i--
DQ = 0; // 给脉冲信
DQ = 1; // 给脉冲信
delay_18B20(4)
return(dat); } /*************ds18b20写一个字节****************/ void WriteOneChar(uchar dat)
unsigned char i=0
for (i=8; i&0; i--
DQ = dat&0x01
delay_18B20(5)
} } /**************读取ds18b20当前温度************
ReadTemp(void) { float val
uchar temp_value,value
unsigned char a=0
unsigned char b=0
unsigned char t=0
Init_DS18B20()
WriteOneChar(0xCC); // 跳过读序号列号的操
WriteOneChar(0x44); // 启动温度转
delay_18B20(100); // this message is wery importan
Init_DS18B20()
WriteOneChar(0xCC); //跳过读序号列号的操
WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温
delay_18B20(100)
a=ReadOneChar(); //读取温度值低
b=ReadOneChar(); //读取温度值高
temp_value=b&&4
temp_value+=(a&0xf0)&&4
value=a&0x0f
val=temp_value+value
return(val); } 以上是DS18B20的驱动程序。
答案创立者
以企业身份回答&
快速解决你的电商难题
店铺优化排查提升2倍流量
擅长&nbsp 店铺优化
您可能有同感的问题当前位置: →
→ LCD1602展示+ds18b20温度测试+ds1302时钟显示
LCD1602展示+ds18b20温度测试+ds1302时钟显示
& 作者:佚名 & 来源: 互联网 & 热度:
&收藏到→_→:
摘要: LCD1602显示+ds18b20温度测试+ds1302时钟显示/*********************************************************** 功能:LCD1602显...
"LCD1602展示+ds18b20温度测试+ds1302时钟显示"::
lcd1602显示+ds18b20温度测试+ds1302时钟显示/***********************************************************
功能:lcd1602显示+ds18b20温度测试+ds1302时钟显示
说明:适用于mini板
作者:荆轩道
************************************************************/
#include &reg52.h&
#include &intrins.h&
//#include &lcd1602.h&
//#include &ds1302.h&
#define uint unsigned int
#define uchar unsigned char
sbit& ds1302_clk = p1^5;&&&&&&&&&&&&& //实时时钟时钟线引脚
sbit& ds1302_io& = p1^4;&&&&&&&&&&&&& //实时时钟数据线引脚
sbit& ds1302_rst = p1^3;&&&&&&&&&&&&& //实时时钟复位线引脚
sbit& wireless_1 = p3^0;
sbit& wireless_2 = p3^1;
sbit& wireless_3 = p3^2;
sbit& wireless_4 = p3^3;
sbit& acc0 = acc^0;
sbit& acc7 = acc^7;
char hide_sec,hide_min,hide_hour,hide_day,hide_week,hide_month,hide_& //秒,分,时到日,月,年位闪的计数
sbit set = p3^1;&&&&&& //模式切换键
sbit up = p3^2;&&&&&&& //加法按钮
sbit down = p3^3;&&&&& //减法按钮
sbit out = p2^3;&&&&&& //立刻跳出调整模式按钮
sbit dq = p3^7;&&&&&&& //温度传送数据io口
char done,count,temp,flag,up_flag,down_
uchar temp_&&&&& //温度值
uchar tempbuffer[5],week_value[2];
void show_time();&& //液晶显示程序
/***********1602液晶显示部分子程序****************/
//port definitions**********************************************************
sbit lcdrs&&= p1^0;
sbit lcdrw&&= p1^1;
sbit lcden& &= p1^2;
sfr& dbport &= 0x80;&&//p0=0x80,p1=0x90,p2=0xa0,p3=0xb0.数据端口
//内部等待函数**************************************************************************
unsigned char lcd_wait(void)
&lcdrw=1;&_nop_();
&lcden=1;&_nop_();
//向lcd写入命令或数据************************************************************
#define lcd_command&&&0&&&&& // command
#define lcd_data&&&1&&&&& // data
#define lcd_clear_screen&0x01&&&&& // 清屏
#define lcd_homing& &&0x02&&&&& // 光标返回原点
void lcd_write(bit style, unsigned char input)
&lcdrw=0;&&_nop_();
&dbport=&_nop_();//注意顺序
&lcden=1;&&_nop_();//注意顺序
&lcden=0;&&_nop_();
&lcd_wait();&
//设置显示模式************************************************************
#define lcd_show&&&0x04&&& //显示开
#define lcd_hide&&&0x00&&& //显示关&&
#define lcd_cursor&&&0x02 &//显示光标
#define lcd_no_cursor&&0x00&&& //无光标&&&&&&
#define lcd_flash&&&0x01&&& //光标闪动
#define lcd_no_flash&&0x00&&& //光标不闪动
void lcd_setdisplay(unsigned char displaymode)
&lcd_write(lcd_command, 0x08|displaymode);&
//设置输入模式************************************************************
#define lcd_ac_up&&&0x02
#define lcd_ac_down&&&0x00&&&&& // default
#define lcd_move&&&0x01&&&&& // 画面可平移
#define lcd_no_move&&&0x00&&&&& //default
void lcd_setinput(unsigned char inputmode)
&lcd_write(lcd_command, 0x04|inputmode);
//初始化lcd************************************************************
void lcd_initial()
&lcd_write(lcd_command,0x38);&&&&&&&&&& //8位数据端口,2行显示,5*7点阵
&lcd_write(lcd_command,0x38);
&lcd_setdisplay(lcd_show|lcd_no_cursor);&&& //开启显示, 无光标
&lcd_write(lcd_command,lcd_clear_screen);&& //清屏
&lcd_setinput(lcd_ac_up|lcd_no_move);&&&&&& //ac递增, 画面不动
//液晶字符输入的位置************************
void gotoxy(unsigned char x, unsigned char y)
&&lcd_write(lcd_command,0x80|x);
&&lcd_write(lcd_command,0x80|(x-0x40));
//将字符输出到液晶显示
void print(unsigned char *str)
&while(*str!='\0')
&&lcd_write(lcd_data,*str);
&&str++;
/***********ds1302时钟部分子程序******************/
typedef struct __systemtime__
&unsigned char&
&unsigned char datestring[11];
&unsigned char timestring[9];
}&//定义的时间类型
#define am(x)&x
#define pm(x)&(x+12)&&&&&&&&&&& && // 转成24小时制
#define ds1302_second&0x80&&&&&&&&& //时钟芯片的寄存器位置,存放时间
#define ds1302_minute&0x82
#define ds1302_hour&&0x84
#define ds1302_week&&0x8a
#define ds1302_day&&0x86
#define ds1302_month&0x88
#define ds1302_year&&0x8c
void ds1302inputbyte(unsigned char d) &//实时时钟写入一字节(内部函数)
&&& for(i=8; i&0; i--)
&&&&&&& ds1302_io = acc0;&&&&&&&&&& &//相当于汇编中的 rrc
&&&&&&& ds1302_clk = 1;
&&&&&&& ds1302_clk = 0;
&&&&&&& acc = acc && 1;
unsigned char ds1302outputbyte(void) &//实时时钟读取一字节(内部函数)
&&& for(i=8; i&0; i--)
&&&&&&& acc = acc &&1;&&&&&&&& &&&//相当于汇编中的 rrc
&&&&&&& acc7 = ds1302_
&&&&&&& ds1302_clk = 1;
&&&&&&& ds1302_clk = 0;
&&& return(acc);
void write1302(unsigned char ucaddr, unsigned char ucda)&//ucaddr: ds1302地址, ucdata: 要写的数据
&&& ds1302_rst = 0;
&&& ds1302_clk = 0;
&&& ds1302_rst = 1;
&&& ds1302inputbyte(ucaddr);&&&&&& &// 地址,命令
&&& ds1302inputbyte(ucda);&&&&&& &// 写1byte数据
&&& ds1302_clk = 1;
&&& ds1302_rst = 0;
unsigned char read1302(unsigned char ucaddr)&//读取ds1302某地址的数据
&&& ds1302_rst = 0;
&&& ds1302_clk = 0;
&&& ds1302_rst = 1;
&&& ds1302inputbyte(ucaddr|0x01);&&&&&&& // 地址,命令
&&& ucdata = ds1302outputbyte();&&&&&&&& // 读1byte数据
&&& ds1302_clk = 1;
&&& ds1302_rst = 0;
&&& return(ucdata);
void ds1302_gettime(systemtime *time)& //获取时钟芯片的时钟数据到自定义的结构型数组
&readvalue = read1302(ds1302_second);
&time-&second = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);
&readvalue = read1302(ds1302_minute);
&time-&minute = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);
&readvalue = read1302(ds1302_hour);
&time-&hour = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);
&readvalue = read1302(ds1302_day);
&time-&day = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);&
&readvalue = read1302(ds1302_week);
&time-&week = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);
&readvalue = read1302(ds1302_month);
&time-&month = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);
&readvalue = read1302(ds1302_year);
&time-&year = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);&
void datetostr(systemtime *time)&&& //将时间年,月,日,星期数据转换成液晶显示字符串,放到数组里datestring[]
{&& if(hide_year&2)&&&&&&&&&&&&&&&& //这里的if,else语句都是判断位闪烁,&2显示数据,&2就不显示,输出字符串为
&&& {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&& time-&datestring[0] = '2';
&& time-&datestring[1] = '0';&
&& time-&datestring[2] = time-&year/10 + '0';
&& time-&datestring[3] = time-&year%10 + '0';
&&&&&& time-&datestring[0] = ' ';
&&&&&& time-&datestring[1] = ' ';&&
&&&&&& time-&datestring[2] = ' ';
&&&&&& time-&datestring[3] = ' ';
&time-&datestring[4] = '/';
&if(hide_month&2)
&& time-&datestring[5] = time-&month/10 + '0';
&& time-&datestring[6] = time-&month%10 + '0';
&&&& time-&datestring[5] = ' ';
&&&& time-&datestring[6] = ' ';
&time-&datestring[7] = '/';
&if(hide_day&2)
&& time-&datestring[8] = time-&day/10 + '0';
&& time-&datestring[9] = time-&day%10 + '0';
&&&& time-&datestring[8] = ' ';
&&&& time-&datestring[9] = ' ';&&&&
&if(hide_week&2)
&& week_value[0] = time-&week%10 + '0';& //星期的数据另外放到 week_value[]数组里,跟年,月,日的此文来自: 马开东博客
转载请注明出处 网址:
分开存放,因为等一下要在最后显示
&&&& week_value[0] = ' ';
&& week_value[1] = '\0';
&time-&datestring[10] = '\0'; //字符串末尾加 '\0' ,判断结束字符
void timetostr(systemtime *time)& //将时,分,秒数据转换成液晶显示字符放到数组 timestring[];
{&& if(hide_hour&2)
&& time-&timestring[0] = time-&hour/10 + '0';
&& time-&timestring[1] = time-&hour%10 + '0';
&&&&&& time-&timestring[0] = ' ';
&&&&&& time-&timestring[1] = ' ';
&time-&timestring[2] = ':';
&&& if(hide_min&2)
&& time-&timestring[3] = time-&minute/10 + '0';
&& time-&timestring[4] = time-&minute%10 + '0';
&&&&&& time-&timestring[3] = ' ';
&&&&&& time-&timestring[4] = ' ';
&time-&timestring[5] = ':';
&&& if(hide_sec&2)
&& time-&timestring[6] = time-&second/10 + '0';
&& time-&timestring[7] = time-&second%10 + '0';
&&&&& else
&&&&&&&& time-&timestring[6] = ' ';
&&&&& time-&timestring[7] = ' ';
&time-&datestring[8] = '\0';
void initial_ds1302(void)&& //时钟芯片初始化
&unsigned char second=read1302(ds1302_second);
&if(second&0x80)&&&&&& //判断时钟芯片是否关闭&&
&writee,0x00); //写入允许
&writec,0x12); //以下写入初始化时间 日期:12/05/14.星期: 1. 时间: 23:59:55
&write,0x05);
&write,0x14);
&writea,0x01);
&write,0x23);
&write,0x59);
&write,0x55);
&writee,0x80); //禁止写入
/***********ds18b20子程序*************************/
/***********ds18b20延迟子函数(晶振12mhz )*******/
void delay_18b20(unsigned int i)
&while(i--);
/**********ds18b20初始化函数**********************/
void init_ds18b20(void)
& unsigned char x=0;
& dq = 1;&&&&&&&&& //dq复位
& delay_18b20(8);& //稍做延时
& dq = 0;&&&&&&&&& //将dq拉低
& delay_18b20(80); //精确延时 大于 480us
& dq = 1;&&&&&&&&& //拉高总线
& delay_18b20(14);
& x=&&&&&&&&&&& //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
& delay_18b20(20);
/***********ds18b20读一个字节**************/&
unsigned char readonechar(void)
&uchar i=0;
&uchar dat = 0;
&for (i=8;i&0;i--)
&&& dq = 0; // 给脉冲信号
&&& dat&&=1;
&&& dq = 1; // 给脉冲信号
&&& if(dq)
&&& dat|=0x80;
&&& delay_18b20(4);
&&return(dat);
/*************ds18b20写一个字节****************/&
void writeonechar(uchar dat)
&&unsigned char i=0;
&&for (i=8; i&0; i--)
& &&dq = 0;
&&&dq = dat&0x01;
&&& &delay_18b20(5);
&&&dq = 1;
&&& &dat&&=1;
/**************读取ds18b20当前温度************/
void readtemp(void)
&unsigned char a=0;
&unsigned char b=0;
&unsigned char t=0;
&init_ds18b20();
&writeonechar(0xcc);&&& &// 跳过读序号列号的操作
&writeonechar(0x44); &// 启动温度转换
&delay_18b20(100);&&&&&& // this message is wery important
&init_ds18b20();
&writeonechar(0xcc); &//跳过读序号列号的操作
&writeonechar(0xbe); &//读取温度寄存器等(共可读9个寄存器) 前两个就是温度
&delay_18b20(100);
&a=readonechar();&&& &//读取温度值低位
&b=readonechar();&& &&//读取温度值高位
&temp_value=b&&4;
&temp_value+=(a&0xf0)&&4;&&&&&&&&&&&&&&
void temp_to_str()&& //温度数据转换成液晶字符显示
& tempbuffer[0]=temp_value/10+'0';& //十位
& tempbuffer[1]=temp_value%10+'0';& //个位
& tempbuffer[2]=0&& //温度符号
& tempbuffer[3]='c';
& tempbuffer[4]='\0';
void delay1ms(unsigned int count)
&unsigned int i,j;
&for(i=0;i&i++)
&for(j=0;j&120;j++);
/*延时子程序*/
void mdelay(uint delay)
&&for(;delay&0;delay--)
&& &&{for(i=0;i&62;i++) //1ms延时.
&&&&&& &&{;}
void outkey()&&&&&&&&&&&&&&&&&&& //跳出调整模式,返回默认显示
& if(out==0||wireless_1==1)&&&&&&&&
& { mdelay(8);
&hide_sec=0,hide_min=0,hide_hour=0,hide_day=0,hide_week=0,hide_month=0,hide_year=0;
&second=read1302(ds1302_second);
&&& writee,0x00); //写入允许
&write,second&0x7f);
&writee,0x80);&&&&&&&&& //禁止写入
&done=0;&&&&&&&&&&
&while(out==0);
&while(wireless_1==1);
////////////////////////////////////////////////////////////////////////////////////////////////////////////
void upkey()//升序按键
&&if(up==0||wireless_2==1)
&&&&&&&&&&& {
&&&&&& mdelay(8);
&&&&&&&&&& switch(count)
&&&&&&&&&&&&& {case 1:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_second);& //读取秒数
&&&&&&&&& temp=temp+1;& //秒数加1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& up_flag=1;&&& //数据调整后更新标志
&&&&&&&&& if((temp&0x7f)&0x59)&& //超过59秒,清零
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=0;&&&&&&&&&
&&&&&&&&&&&&&& case 2:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_minute);& //读取分数
&&&&&&&&& temp=temp+1;& //分数加1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& up_flag=1;
&&&&&&&&& if(temp&0x59)&&&&&&&&& //超过59分,清零
&&&&&&&&& temp=0;
&&&&&&&&&&&&&& case 3:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_hour);& //读取小时数
&&&&&&&&& temp=temp+1;& //小时数加1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& up_flag=1;
&&&&&&&&& if(temp&0x23)&& //超过23小时,清零
&&&&&&&&& temp=0;
&&&&&&&&&&&&&& case 4:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_week);& //读取星期数
&&&&&&&&& temp=temp+1;& //星期数加1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& up_flag=1;
&&&&&&&&& if(temp&0x7)&
&&&&&&&&& temp=1;
&&&&&&&&&&&&&& case 5:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_day);& //读取日数
&&&&&&&&& temp=temp+1;& //日数加1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& up_flag=1;
&&&&&&&&& if(temp&0x31)
&&&&&&&&& temp=1;
&&&&&&&&&&&&&& case 6:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_month);& //读取月数
&&&&&&&&& temp=temp+1;& //月数加1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& up_flag=1;
&&&&&&&&& if(temp&0x12)
&&&&&&&&& temp=1;
&&&&&&&&&&&&&& case 7:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_year);& //读取年数
&&&&&&&&& temp=temp+1;& //年数加1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& up_flag=1;
&&&&&&&&& if(temp&0x85)
&&&&&&&&& temp=0;
&&&&&&&&&&& default:
&&&&&&&&&&&&& }
&&&&&& while(up==0);
&&&&&&&&&&&&&&& while(wireless_2==1);
////////////////////////////////////////////////////////////////////////////////////////////////////////////
void downkey()//降序按键
&&&& if(down==0||wireless_3==1)
&&&&&&&&&&& {
&&&&&& mdelay(8);
&&&&&&&& switch(count)
&&&&&&&&&&&&& {case 1:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_second);& //读取秒数
&&&&&&&&& temp=temp-1;&&&&&&&&& //秒数减1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& down_flag=1;&&&&&& //数据调整后更新标志
&&&&&&&&& if(temp==0x7f)&&&& //小于0秒,返回59秒
&&&&&&&&& temp=0x59;
&&&&&&&&&&&&&& case 2:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_minute);& //读取分数
&&&&&&&&& temp=temp-1;& //分数减1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& down_flag=1;
&&&&&&&&& if(temp==-1)
&&&&&&&&& temp=0x59;&&&&& //小于0秒,返回59秒
&&&&&&&&&&&&&& case 3:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_hour);& //读取小时数
&&&&&&&&& temp=temp-1;& //小时数减1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& down_flag=1;
&&&&&&&&& if(temp==-1)
&&&&&&&&& temp=0x23;
&&&&&&&&&&&&&& case 4:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_week);& //读取星期数
&&&&&&&&& temp=temp-1;& //星期数减1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& down_flag=1;
&&&&&&&&& if(temp==0)
&&&&&&&&& temp=0x7;;
&&&&&&&&&&&&&& case 5:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_day);& //读取日数
&&&&&&&&& temp=temp-1;& //日数减1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& down_flag=1;
&&&&&&&&& if(temp==0)
&&&&&&&&& temp=31;
&&&&&&&&&&&&&& case 6:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_month);& //读取月数
&&&&&&&&& temp=temp-1;& //月数减1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& down_flag=1;
&&&&&&&&& if(temp==0)
&&&&&&&&& temp=12;
&&&&&&&&&&&&&& case 7:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& temp=read1302(ds1302_year);& //读取年数
&&&&&&&&& temp=temp-1;& //年数减1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& down_flag=1;
&&&&&&&&& if(temp==-1)
&&&&&&&&& temp=0x85;
&&&&&&&&&& default:
&&&&&&&&&&&& }
&&&&&& while(down==0);
&&&&&& while(wireless_3==1);
void setkey()//模式选择按键
&&if(set==0||wireless_4==1)
&&&&&&&&&& mdelay(8);
&&&&&&&&&& count=count+1;& //setkey按一次,count就加1
&&&& done=1;&&& //进入调整模式
&&&&&&&&&& while(set==0);
&&&&&&&&&& while(wireless_4==1);
void keydone()//按键功能执行
&& if(flag==0)&&& //关闭时钟,停止计时
&&&&&&&& { writee,0x00); //写入允许
&&&&&&&&&& temp=read);
&&&&&&&&&& write,temp|0x80);
&&&&&&& writee,0x80); //禁止写入
&&&&&&&&&& flag=1;
&&&&&&&& }
&&&&&&&& setkey();&&&&&&&&&&&&&&& //扫描模式切换按键
&& switch(count)
&& {case 1:do&&&&&&&&&&&& //count=1,调整秒
&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&& outkey();&&&&& //扫描跳出按钮
&&&&&& upkey();&&&&&&&&&&&&&&& //扫描加按钮
&&&&&& downkey();&&&&&&&&&&&&& //扫描减按钮
&&&&&& if(up_flag==1||down_flag==1)& //数据更新,重新写入新的数据
&&&&&& writee,0x00); //写入允许
&&&&&& write,temp|0x80); //写入新的秒数
&&&&&& writee,0x80); //禁止写入
&&&&&& up_flag=0;
&&&&&& down_flag=0;
&&&&&& hide_sec++;&&&&&&&&& //位闪计数
&&&&&& if(hide_sec&3)
&&&&&&&& hide_sec=0;
&&&&&&&&&&&&&&&&&& show_time();&&&&&&&& //液晶显示数据
&&&&& }while(count==2);&
&&& case 2:do&&&&&&&&&&&& //count=2,调整分
&&&&&&&&&&& {
&&&&&& hide_sec=0;
&&&&&& outkey();
&&&&&& upkey();
&&&&&& downkey();
&&&&&& if(temp&0x60)
&&&&&&&& temp=0;
&&&&&& if(up_flag==1||down_flag==1)
&&&&&& writee,0x00); //写入允许
&&&&&& write,temp); //写入新的分数
&&&&&& writee,0x80); //禁止写入
&&&&&& up_flag=0;
&&&&&& down_flag=0;
&&&&&& hide_min++;
&&&&&& if(hide_min&3)
&&&&&&&& hide_min=0;
&&&&&&&&&&&&&&&&&& show_time();
&&&&& }while(count==3);
&&& case 3:do&&&&&&&&&&&& //count=3,调整小时
&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&& hide_min=0;
&&&&&& outkey();
&&&&&& upkey();
&&&&&& downkey();
&&&&&& if(up_flag==1||down_flag==1)
&&&&&& writee,0x00); //写入允许
&&&&&& write,temp); //写入新的小时数
&&&&&& writee,0x80); //禁止写入
&&&&&& up_flag=0;
&&&&&& down_flag=0;
&&&&&& hide_hour++;
&&&&&& if(hide_hour&3)
&&&&&&&& hide_hour=0;
&&&&&&&&&&&&&&&&&& show_time();
&&&&& }while(count==4);
&&& case 4:do&&&&&&&&&&&& //count=4,调整星期
&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&& hide_hour=0;
&&&&&& outkey();
&&&&&& upkey();
&&&&&& downkey();
&&&&&& if(up_flag==1||down_flag==1)
&&&&&& writee,0x00); //写入允许
&&&&&& writea,temp); //写入新的星期数
&&&&&& writee,0x80); //禁止写入
&&&&&& up_flag=0;
&&&&&& down_flag=0;
&&&&&& hide_week++;
&&&&&& if(hide_week&3)
&&&&&&&& hide_week=0;
&&&&&&&&&&&&&&&&&& show_time();
&&&&& }while(count==5);
&&& case 5:do&&&&&&&&&&&& //count=5,调整日
&&&&&&&&&&& {
&&&&&& hide_week=0;
&&&&&& outkey();
&&&&&& upkey();
&&&&&& downkey();
&&&&&& if(up_flag==1||down_flag==1)
&&&&&& writee,0x00); //写入允许
&&&&&& write,temp); //写入新的日数
&&&&&& writee,0x80); //禁止写入
&&&&&& up_flag=0;
&&&&&& down_flag=0;
&&&&&& hide_day++;
&&&&&& if(hide_day&3)
&&&&&&&& hide_day=0;
&&&&&&&&&&&&&&&&&& show_time();
&&&&& }while(count==6);
&&& case 6:do&&&&&&&&&&&& //count=6,调整月
&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&& hide_day=0;
&&&&&& outkey();
&&&&&& upkey();
&&&&&& downkey();
&&&&&& if(up_flag==1||down_flag==1)
&&&&&& writee,0x00); //写入允许
&&&&&& write,temp); //写入新的月数
&&&&&& writee,0x80); //禁止写入
&&&&&& up_flag=0;
&&&&&& down_flag=0;
&&&&&& hide_month++;
&&&&&& if(hide_month&3)
&&&&&&&& hide_month=0;
&&&&&&&&&&&&&&&&&& show_time();
&&&&& }while(count==7);
&&& case 7:do&&&&&&&&&&&& //count=7,调整年
&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&& hide_month=0;
&&&&&& outkey();
&&&&&& upkey();
&&&&&& downkey();
&&&&&& if(up_flag==1||down_flag==1)
&&&&&& writee,0x00); //写入允许
&&&&&& writec,temp); //写入新的年数
&&&&&& writee,0x80); //禁止写入
&&&&&& up_flag=0;
&&&&&& down_flag=0;
&&&&&& hide_year++;
&&&&&& if(hide_year&3)
&&&&&&&& hide_year=0;
&&&&&&&&&&&&&&&&&& show_time();
&&&&& }while(count==8);
&&& case 8: count=0;hide_year=0;& //count8, 跳出调整模式,返回默认显示状态
&&&&&&&&&&&&&& second=read1302(ds1302_second);
&&&&&&&&&&&&&&&&& writee,0x00); //写入允许
&&&&&&&&&&&&&& write,second&0x7f);
&&&&&&&&&&&&&& writee,0x80);&&&&&&&&& //禁止写入
&&&&& done=0;
&&& //count=7,开启中断,标志位置0并退出
&&& default:
void show_time()&& //液晶显示程序
& ds1302_gettime(&currenttime);& //获取时钟芯片的时间数据
& timetostr(&currenttime);&&&&&& //时间数据转换液晶字符
& datetostr(&currenttime);&&&&&& //日期数据转换液晶字符
& readtemp();&&&&&&&&&&&&&&&&&&& //开启温度采集程序
& temp_to_str();&&&&&&&&&&&&&&&& //温度数据转换成液晶字符
& gotoxy(12,1);&&&&&&&&&&&&&&&&& //液晶字符显示位置
& print(tempbuffer);&&&&&&&&&&&& //显示温度
& gotoxy(0,1);
& print(currenttime.timestring); //显示时间
& gotoxy(0,0);
& print(currenttime.datestring); //显示日期
& gotoxy(15,0);
& print(week_value);&&&&&&&&&&&& //显示星期
& gotoxy(11,0);
& print(&week&);&//在液晶上显示 字母 week
& delay1ms(400);&&&&&&&&&&&&&&&& //扫描延时
&&& flag=1;&&&&&&&&&& //时钟停止标志
&lcd_initial();&&& //液晶初始化
&init_ds18b20( ) ;&&&&& //ds18b20初始化
&initial_ds1302(); //时钟芯片初始化
&up_flag=0;
&down_flag=0;
&done=0;&&&&&&&&&& //进入默认液晶显示
&wireless_1=0;
&wireless_2=0;
&wireless_3=0;
&wireless_4=0;
&&&&&&& while(done==1)
&&&&&&&&& keydone();&&& //进入调整模式
&&while(done==0)
&&&&&&&&&&& show_time();&&&&&&&&&&&&&&& //液晶显示数据
&&&&&&&&&&& flag=0;&&&&&&&&&&&&&&&&&
& &&&&& setkey();&&&& //扫描各功能键
/**************************************************************************
&&&&&&&&&&&&&&&&&& &&the real timer ds1302 driver lib
&&&&&&&&&&&& &&copyright (c)&& 2005 by jjj.
&&&&&&&&&&&&&&&&&&&&&& &&--& all rights reserved& --
&& file name:&&&&&& ds1302.h
&& author:&&&&&&&&& jiang jian jun
&& created:&&&&&&&&
&& modified:&&no
&& revision: &&1.0
***************************************************************************/
#ifndef _real_timer_ds_21_
#define _real_timer_ds_21_
sbit& ds1302_clk = p1^6;&&&&&&&&&&&&& //实时时钟时钟线引脚
sbit& ds1302_io& = p1^7;&&&&&&&&&&&&& //实时时钟数据线引脚
sbit& ds1302_rst = p1^5;&&&&&&&&&&&&& //实时时钟复位线引脚
sbit& acc0 = acc^0;
sbit& acc7 = acc^7;
char hide_sec,hide_min,hide_hour,hide_day,hide_week,hide_month,hide_
typedef struct __systemtime__
&unsigned char&
&unsigned char datestring[11];
&unsigned char timestring[9];
}&//定义的时间类型
#define am(x)&x
#define pm(x)&(x+12)&&&&&&&&&&& && // 转成24小时制
#define ds1302_second&0x80
#define ds1302_minute&0x82
#define ds1302_hour&&0x84
#define ds1302_week&&0x8a
#define ds1302_day&&0x86
#define ds1302_month&0x88
#define ds1302_year&&0x8c
#define ds1302_ram(x)&(0xc0+(x)*2)&& &//用于计算 ds1302_ram 地址的宏
void ds1302inputbyte(unsigned char d) &//实时时钟写入一字节(内部函数)
&&& for(i=8; i&0; i--)
&&&&&&& ds1302_io = acc0;&&&&&&&&&& &//相当于汇编中的 rrc
&&&&&&& ds1302_clk = 1;
&&&&&&& ds1302_clk = 0;
&&&&&&& acc = acc && 1;
unsigned char ds1302outputbyte(void) &//实时时钟读取一字节(内部函数)
&&& for(i=8; i&0; i--)
&&&&&&& acc = acc &&1;&&&&&&&& &&&//相当于汇编中的 rrc
&&&&&&& acc7 = ds1302_
&&&&&&& ds1302_clk = 1;
&&&&&&& ds1302_clk = 0;
&&& return(acc);
void write1302(unsigned char ucaddr, unsigned char ucda)&//ucaddr: ds1302地址, ucdata: 要写的数据
&&& ds1302_rst = 0;
&&& ds1302_clk = 0;
&&& ds1302_rst = 1;
&&& ds1302inputbyte(ucaddr);&&&&&& &// 地址,命令
&&& ds1302inputbyte(ucda);&&&&&& &// 写1byte数据
&&& ds1302_clk = 1;
&&& ds1302_rst = 0;
unsigned char read1302(unsigned char ucaddr)&//读取ds1302某地址的数据
&&& ds1302_rst = 0;
&&& ds1302_clk = 0;
&&& ds1302_rst = 1;
&&& ds1302inputbyte(ucaddr|0x01);&&&&&&& // 地址,命令
&&& ucdata = ds1302outputbyte();&&&&&&&& // 读1byte数据
&&& ds1302_clk = 1;
&&& ds1302_rst = 0;
&&& return(ucdata);
void ds1302_setprotect(bit flag)&&&&&&& //是否写保护
&&writee,0x10);
&&writee,0x00);
void ds1302_settime(unsigned char address, unsigned char value)&&&&&&& // 设置时间函数
&ds1302_setprotect(0);
&write1302(address, ((value/10)&&4 | (value%10)));
void ds1302_gettime(systemtime *time)
&readvalue = read1302(ds1302_second);
&time-&second = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);
&readvalue = read1302(ds1302_minute);
&time-&minute = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);
&readvalue = read1302(ds1302_hour);
&time-&hour = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);
&readvalue = read1302(ds1302_day);
&time-&day = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);&
&readvalue = read1302(ds1302_week);
&time-&week = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);
&readvalue = read1302(ds1302_month);
&time-&month = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);
&readvalue = read1302(ds1302_year);
&time-&year = ((readvalue&0x70)&&4)*10 + (readvalue&0x0f);&
void datetostr(systemtime *time)
{&& if(hide_year&2)
&& time-&datestring[0] = time-&year/10 + '0';
&& time-&datestring[1] = time-&year%10 + '0';
&&&&&& time-&datestring[0] = ' ';
&&&&&& time-&datestring[1] = ' ';
&time-&datestring[2] = '-';
&if(hide_month&2)
&& time-&datestring[3] = time-&month/10 + '0';
&& time-&datestring[4] = time-&month%10 + '0';
&&&& time-&datestring[3] = ' ';
&&&& time-&datestring[4] = ' ';
&time-&datestring[5] = '-';
&if(hide_day&2)
&& time-&datestring[6] = time-&day/10 + '0';
&& time-&datestring[7] = time-&day%10 + '0';
&&&& time-&datestring[6] = ' ';
&&&& time-&datestring[7] = ' ';&&&&
&if(hide_week&2)
&& time-&datestring[8] = ' ';
&& time-&datestring[9] = time-&week%10 + '0';
&&&& time-&datestring[8] = ' ';
&&&& time-&datestring[9] = ' ';
&time-&datestring[10] = '\0';
void timetostr(systemtime *time)
{&& if(hide_hour&2)
&& time-&timestring[0] = time-&hour/10 + '0';
&& time-&timestring[1] = time-&hour%10 + '0';
&&&&&& time-&timestring[0] = ' ';
&&&&&& time-&timestring[1] = ' ';
&time-&timestring[2] = ':';
&&& if(hide_min&2)
&& time-&timestring[3] = time-&minute/10 + '0';
&& time-&timestring[4] = time-&minute%10 + '0';
&&&&&& time-&timestring[3] = ' ';
&&&&&& time-&timestring[4] = ' ';
&time-&timestring[5] = ':';
&&& if(hide_sec&2)
&& time-&timestring[6] = time-&second/10 + '0';
&& time-&timestring[7] = time-&second%10 + '0';
&&&&& else
&&&&&&&& time-&timestring[6] = ' ';
&&&&& time-&timestring[7] = ' ';
&time-&datestring[8] = '\0';
void initial_ds1302(void)
&unsigned char second=read1302(ds1302_second);
&writee,0x00); //写入允许
&write,0x50);
&write,0x56);
&write,0x22);
&writee,0x80); //禁止写入
&if(second&0x80)&&&
&&ds1302_settime(ds1302_second,0x80);
/**************************************************************************
&&&&&&&&&&&&&&&&&& &&the 1602 char lcd lib
&&&&&&&&&&&& &&copyright (c)&& 2005 by jjj.
&&&&&&&&&&&&&&&&&&&&&& &&--& all rights reserved& --
&& file name:&&&&&& lcd.h
&& author:&&&&&&&&& jiang jian jun
&& created:&&&&&&&&
&& modified:&&no
&& revision: &&1.0
***************************************************************************/
#ifndef lcd_char__9
#define lcd_char__9
#include &intrins.h&
//port definitions**********************************************************
sbit lcdrs&&= p2^0;
sbit lcdrw&&= p2^1;
sbit lcden& &= p2^2;
sfr& dbport &= 0x80;&&//p0=0x80,p1=0x90,p2=0xa0,p3=0xb0.数据端口
//内部等待函数**************************************************************************
unsigned char lcd_wait(void)
&lcdrw=1;&_nop_();
&lcden=1;&_nop_();
&//while(dbport&0x80);//在用proteus仿真时,注意用屏蔽此语句,在调用gotoxy()时,会进入死循环,
&&&&&& //可能在此文来自: 马开东博客
转载请注明出处 网址:
写该控制字时,该模块没有返回写入完备命令,即dbport&0x80==0x80
&&&&&& //实际硬件时打开此语句
//向lcd写入命令或数据************************************************************
#define lcd_command&&&0&&&&& // command
#define lcd_data&&&1&&&&& // data
#define lcd_clear_screen&0x01&&&&& // 清屏
#define lcd_homing& &&0x02&&&&& // 光标返回原点
void lcd_write(bit style, unsigned char input)
&lcdrw=0;&&_nop_();
&dbport=&_nop_();//注意顺序
&lcden=1;&&_nop_();//注意顺序
&lcden=0;&&_nop_();
&lcd_wait();&
//设置显示模式************************************************************
#define lcd_show&&&0x04&&& //显示开
#define lcd_hide&&&0x00&&& //显示关&&
#define lcd_cursor&&&0x02 &//显示光标
#define lcd_no_cursor&&0x00&&& //无光标&&&&&&
#define lcd_flash&&&0x01&&& //光标闪动
#define lcd_no_flash&&0x00&&& //光标不闪动
void lcd_setdisplay(unsigned char displaymode)
&lcd_write(lcd_command, 0x08|displaymode);&
//设置输入模式************************************************************
#define lcd_ac_up&&&0x02
#define lcd_ac_down&&&0x00&&&&& // default
#define lcd_move&&&0x01&&&&& // 画面可平移
#define lcd_no_move&&&0x00&&&&& //default
void lcd_setinput(unsigned char inputmode)
&lcd_write(lcd_command, 0x04|inputmode);
//移动光标或屏幕************************************************************
#define lcd_cursor&&0x02&&&&&
#define lcd_screen&&0x08
#define lcd_left&&0x00
#define lcd_right&&0x04
void lcd_move(unsigned char object, unsigned char direction)
&if(object==lcd_cursor)
&&lcd_write(lcd_command,0x10|direction);
&if(object==lcd_screen)
&&lcd_write(lcd_command,0x18|direction);
//初始化lcd************************************************************
void lcd_initial()
&lcd_write(lcd_command,0x38);&&&&&&&&&& //8位数据端口,2行显示,5*7点阵
&lcd_write(lcd_command,0x38);
&lcd_setdisplay(lcd_show|lcd_no_cursor);&&& //开启显示, 无光标
&lcd_write(lcd_command,lcd_clear_screen);&& //清屏
&lcd_setinput(lcd_ac_up|lcd_no_move);&&&&&& //ac递增, 画面不动
//************************************************************************
void gotoxy(unsigned char x, unsigned char y)
&&lcd_write(lcd_command,0x80|x);
&&lcd_write(lcd_command,0x80|(x-0x40));
void print(unsigned char *str)
&while(*str!='\0')
&&lcd_write(lcd_data,*str);
&&str++;
void lcd_loadchar(unsigned char user[8], unsigned char place)
&uns搜索此文相关文章:此文来自: 马开东博客
网址: 站长QQ
上一篇:没有了
LCD1602展示+ds18b20温度测试+ds1302时钟显示_移动开发相关文章
移动开发_总排行榜
移动开发_最新
移动开发_月排行榜
移动开发_周排行榜
移动开发_日排行榜

我要回帖

更多关于 ds18b20用1602显示 的文章

 

随机推荐