极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11756|回复: 3

1602LCD_1307RTC_DS18B20

[复制链接]
发表于 2015-1-17 10:58:07 | 显示全部楼层 |阅读模式
本帖最后由 56832926 于 2015-1-17 12:53 编辑

今天在弘毅大牛关于   “arduino学习笔记27 - DS1307 RTC时钟芯片与DS18B20数字温度传感器实验 ”的基础上实现了1602液晶显示日期、时间、温度值。以供大家学习!
DS1307和DS18B20(注此图借用):

结果如图:

程序如下:
/*
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
* DS1307 SDA pin to analog pin A4
* DS1307 SCL pin to analog pin A5
* DS18B20 DS pin to digital pin 8
*/
#include <LiquidCrystal.h>
#include <DS1307RTC.h>
#include <Time.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 8
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

tmElements_t tm;

void setup() {
  sensors.begin();
  lcd.begin(16, 2);   
}

void loop() {
  sensors.requestTemperatures();
  tmElements_t tm;

  if (RTC.read(tm)) {
    lcd.setCursor(0, 0);
    print2digits(tm.Hour);
    lcd.write(':');
    print2digits(tm.Minute);
    lcd.write(':');
    print2digits(tm.Second);
    lcd.setCursor(10, 0);
    lcd.print(sensors.getTempCByIndex(0),2);
    lcd.print("C");
    lcd.setCursor(0, 1);
    lcd.print("Date:");
    lcd.print(tm.Day);
    lcd.write('/');
    lcd.print(tm.Month);
    lcd.write('/');
    lcd.print(tmYearToCalendar(tm.Year));
  }
}

void print2digits(int number) {
  if (number >= 0 && number < 10) {
    lcd.write('0');
  }
  lcd.print(number);
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2015-1-18 23:33:54 | 显示全部楼层
不错啊 还可以把数据存储起来或者上传到上位机 这样可以绘制一条温度曲线了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-1-19 09:18:10 | 显示全部楼层
darkorigin 发表于 2015-1-18 23:33
不错啊 还可以把数据存储起来或者上传到上位机 这样可以绘制一条温度曲线了

不错不错,可以试试
回复 支持 反对

使用道具 举报

发表于 2015-4-5 12:31:12 | 显示全部楼层
不知道1602是怎样连接的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-17 19:04 , Processed in 0.045603 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表