|
发表于 2014-9-29 22:31:44
|
显示全部楼层
本帖最后由 504835618 于 2014-9-29 22:37 编辑
谢谢LZ的程序,在原来的程序上加上了OLED显示,效果还可以,下面上程序
#include "DS18B20_S.h"
#include <U8glib.h>
//SSD1306
U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9,8);// SW SPI Com: SCK = 13, MOSI = 11, CS = 10-NC, A0/DC = 9
//DS18B20(byte pin) 连接管脚
//传感器设定为10位模式,每次转换时间<187.5ms,如果需要12位模式,请修改库文件of ds.set(0x7F);
DS18B20_S ds(7);//pin9
void setup() {
Serial.begin(9600);
}
void loop() {
ds.start();//开始测量(所有传感器)
/////////判断转换是否完成
///只有在三根线连接模式下有效,两根线模式下请不要使用
// while(!ds.ready()){
// delay(10);
// }
////////////
delay(200);//2根线连接模式
float a=ds.get();
Serial.println("c0=");
if(a>200){ //CRC 校验错误
Serial.println("CRC error");
}
else{
Serial.print(a);
}
//下面的不重要
// void set(byte n);//set(0x1F) 9位模式 delay(94) ;
//0x3F 10位模式 delay(188);
//0x5F 11位模式 delay(375);
//0x7F 12 位模式 delay(750)
u8g.firstPage();
do {
draw();
}
while( u8g.nextPage() );
delay(1000);
}
void draw(void) {
//u8g.setRot180();
u8g.drawLine(0,15 , 128, 15);
u8g.setFont(u8g_font_osb26);
u8g.setPrintPos(5, 55);
u8g.print(ds.get());
u8g.setFont(u8g_font_fub14);
u8g.setPrintPos(100, 55);
u8g.print(char(176));
u8g.print("C");
u8g.setFont(u8g_font_fub11);
u8g.setPrintPos(3, 12);//X,Y
u8g.print("SD18B20.Temp");
//delay(5);
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|