
The reason of choosing DS1821 thermo sensor is that the circuit is very simple, it only need on IO pin.
Originally, I wrote the test program by SDCC compiler, the test has some problem, the LCD display is work, but the temperature is still display zero?
Then, I did compiling by HI-TECH's PICC, the temperature value is correct.
If you are using PICC, please comment out lines as following:
typedef unsigned int config;
config at 0x2007 __CONFIG = _XT_OSC & _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF;
Replace pic/pic16f877a.h by htc.h
Circuit schematics is as following:

Main process:
/*******************************************************************************
Copyright (c) 2008 Wizign Ltd.
All Rights Reserved.
main.c: Main program for demo thermometer
Version: 1.0.0
Date: Sep 05, 2008
Author: YenHung Chen
E-mail: yhchen@wizign.com
Revision:
---------- -----------------------------------------------------------------
2008/09/05 Created by YenHung Chen, demo thermometer for both 8051 and PIC
******************************************************************************/
/*******************************************************************************
The IO control
<>For AT89S52
LCD display:
There are 8 data pins, which are connected P2.
The control pins are connected to P1_0, P1_1, and P1_2.
DS1821:
P1_7
<>For PIC16F877A
LCD display:
There are 8 data pins, which are connected PORTD
The control pins are connected to RA0, RA1, and RA2.
DS1821:
RA5
******************************************************************************/
#include "global.h"
#include "delay.h"
#include "lcd.h"
#include "thermo.h"
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define IO and global variables
#ifdef MCU_PIC
// Configurations
typedef unsigned int config;
config at 0x2007 __CONFIG = _XT_OSC & _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF;
#endif
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define functions
/* Initilize parameters before run the main loop */
void InitParams(void)
{
LCDInit();
ThermoInit();
}
/* Display message on LCD panel */
void DisplayTemperature(void)
{
char tmMsg[16];
int theT;
unsigned char myT;
int hundred;
int tenth;
int ones;
LCDGoto(0); // goto 1st line
LCDPuts(" WIZIGN LTD. ");
// Convert value to string
myT = ThermoReadTemperature();
if(myT > 127){
theT = (int)(myT - 0xFF);
}else{
theT = (int)myT;
}
// start
// it can not display correct format in this block
BLOCK
// end
hundred = (int)(theT/100);
tenth = (int)((theT%100)/10);
ones = theT%10;
tmMsg[1] = 0x30 + hundred;
tmMsg[2] = 0x30 + tenth;
tmMsg[3] = 0x30 + ones;
tmMsg[4] = 0x20;
tmMsg[5] = 'C';
tmMsg[6] = 0x20;
tmMsg[7] = '\0';
LCDGoto(0x40); // goto 2nd line
LCDPuts(tmMsg);
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// main program
void main(void)
{
// Initilize parameters
InitParams();
/* do loop */
while(1){
DisplayTemperature();
// The LCD display and the calculation of time
// will consume times, so, the delay time is less than 1000 ms.
DelayMs(900);
}
}
17 comments:
請問前輩是如何寫DS1821的模組
可以教導我嗎
請說明聯絡的方式, 可以寄範例給您參考.
你好!最近有用到DS1821但是GOOGLE大神資料不太多(keil c).我想要把DS1821資料讀出來給8051.再用8051把資料TX傳輸到電腦上.其中DS1821給8051的地方我不是很懂.想請你幫幫忙!謝謝^^
EM:fuck1218@yahoo.com.tw
及時通:fuck1218
您好!
已經將範例程式寄給您了.
你好 我想請問一下ds1821 可以用C寫 進89c51嗎 如果有可以麻煩寄一下範例給我嗎?
信箱:ioploki@yahoo.com.tw
你好!我想使用8051讀取DS1821的資料,再透過TX傳輸到電腦上.可否提供C 的範例程式,謝謝
EM:willinglee@mail2000.com.tw
你好請問可以分享給我ds1821用C寫進89c51嗎的範例& 詳細電路圖嗎~???謝謝~
關於 DS1821 的 example code, 請參考:
Dallas DS1821 three-pin digital thermostat by Mike Pearce
http://www.microchipc.com/sourcecode/PIC_Hi-Tech_C_Mike_Pearces_DS1821_thermostat.zip
前輩你好:
小弟是新手,最近因為製作專題需要用到DS1821當sensor,因為是現學現賣,有些東西不是很熟,我有到前輩給的網站上下載範例程式,但是還是希望可以跟前輩要8051和DS1821的C語言範例程式,對照著看。謝謝。
EM:joseph_jone@yahoo.com.tw
你好謝謝你之前提供的資料,研究了之後我發現我在89s51部分還真的不太行 能否麻煩你給我8051和DS1821的C語言範例程式~麻煩您了
您好關於 DS1821 的 example code,裡面的電路圖 因為我想要自己實際做一個起來!!!但是零件表真的好不清楚@@我不知道要買什麼...可以給我零件資料嗎感恩!!!
望了提供MAIL:soccerin1019@hotmail.com & soccerin1019@yahoo.com.tw 麻煩您了
您好 小弟專題有需要DS1821讀給8051然後在用8051把資料TX傳輸到電腦上
您的範例可否傳給小弟研究一下
小弟EMAIL為:larry74689@gmail.com
感謝^^
你好~最近要使用DS1821做溫度SENSOR,但一直遲遲弄不出來,希望你能幫忙,可以給我範例程式與電路圖,謝謝!!!
你好:最近需要用到相關的實作
能否借我參考範例程式呢謝謝
DS1821 的最佳範例,請參考 Microchip 網站上的 source code:
Dallas DS1821 three-pin digital thermostat by Mike Pearce
http://www.microchipc.com/sourcecode/PIC_Hi-Tech_C_Mike_Pearces_DS1821_thermostat.zip
Post a Comment