Wednesday, June 3, 2020

Interfacing ds1621 digital thermometer to PIC16F628A

Introduction

In industrial control or consumer electronic product, measuring the temperature is usually required. A thermometer used for measuring the temperature comes with many interfaces, analog and digital interface.

For digital interface there are many options. In this example, I use ds1621 digital thermometer manufactured by Maxim Integrated.

This temperature sensor comes with 8 pin integrated circuit. It is also available in DIP package, a good choice for bread board prototyping and hobbyist. The communication interface is inter integrated circuit. 

If we use degree Celsius it could sample the temperature between -55  to +125 degree Celsius with a 0.5 degree Celsius step. Using the Fahrenheit unit equivalence, the temperature sampling ranges from -67 to 257 degree Fahrenheit.

The supply voltage ranges from 2.7 to 5.5 V. In usual prototyping, it's normally supplied at 5 V DC.


Interfacing ds1621 digital thermometer to PIC16F628A
Pin diagram of ds1621

Programming interface

Currently of microcontrollers come with a rich of peripherals including the communication interfaces like inter integrated circuit (I2C). For some old age microcontrollers like PIC16F628A, the I2C is absent. 

With CCS PICC compiler, the I2C interface could be implemented using I2C module inside the MCU. Anyway, without the I2C module any MCU with sufficient program memory could emulate this interface using an I2C library that use bit banging method.

In this example, the MCU read the temperature data from ds1621 thermometer. Temperature data is displayed on a 16x2 lines character LCD. Timer 0 schedule the temperature reading and displaying for every one minute.


Interfacing ds1621 digital thermometer to PIC16F628A
Schematic diagram. CPU clock at 4 MHz. Thermometer connects to PIC16F628A via RA0
and RA1. PortB connects to LCD using 4-bit mode. Clock pins left unconnected due
to 4 MHz internal clock sources is used. 

The PICC source code:

#include <16F628A.h>
#fuses INTRC
#use delay(clock=4000000)
//i2c pins
#define DAL_SCL   PIN_A0
#define DAL_SDA   PIN_A1
//LCD pins                         
#define LCD_RS_PIN      PIN_B0                                    
#define LCD_RW_PIN      PIN_B1   
#define LCD_ENABLE_PIN  PIN_B2
#define LCD_DATA4       PIN_B4                                    
#define LCD_DATA5       PIN_B5                                    
#define LCD_DATA6       PIN_B6                                    
#define LCD_DATA7       PIN_B7         
#include <ds1621.c>
#include<lcd.c>
BYTE value;
BYTE cntInterrupts=0;
float celsius;
/*this function activates
every one second
*/
void displayResult(void){
      value = read_temp();
      /*convert to degree Celsius*/
      celsius = 5.0*(value-32)/9;
      lcd_gotoxy(1,2);
      printf(LCD_PUTC,"%.1f degree C\r\n",celsius);
}
void main() {
   /*timer 0 is prescaled to 1:256*/
   setup_timer_0( RTCC_DIV_256);
   /*turn on timer 0 interrupt*/
   enable_interrupts(INT_TIMER0);
   /*turn on global interrupt control*/
   enable_interrupts(GLOBAL);
   /*clear timer 0 interrupt flage*/
   clear_interrupt(INT_TIMER0);
   /*initialize the ds1621 function*/
   init_temp();
   /*initialize the LCD function*/
   lcd_init();
  
   lcd_gotoxy(1,1);
   printf(LCD_PUTC,"Temperature: ");
   
   while(1){
   /*if it's one second*/
      if(cntInterrupts>=15){
      displayResult();
         cntInterrupts=0;       
      }
      
   } 
}
#INT_TIMER0
void overflowISR(void){
   /*Each interrupt occurs every 65 mS*/
   cntInterrupts++;
   /*Clear flag*/
   clear_interrupt(INT_TIMER0);
}

Interfacing ds1621 digital thermometer to PIC16F628A

A test program read 27.7 degree Celsius from ds1621 thermometers.


No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (54) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (46) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (66) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (2) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (30) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)