You are on page 1of 39

SYNOPSIS ON AUTOMATIC TEMPRATURE CONTROLLER

BY CETPA INFOTECH PRIVATE LIMITED

Block Diagram of temperature indicator using IC89C52:

POWER SUPPLY

7805 REGULATOR

LCD DISPLAY (16*1)

MCU AT89C52

DS1621 TEMPRATURE SENSOR

CONSTRUCTION AND WORKING OF THE CIRCUIT


The figure above shows the basic block diagram of the temperature indicator system using microcontroller AT89C52. The power supply for the circuit is regulated by the IC7805 and supplied to different parts of the unit. DS1621 is the temperature sensor chip. The microcontroller unit (MCU) reads the temperature from the sensor. The temperature data is compared with certain user-define temperature values and processed inside the MCU as per the program and then sent to the LCD display.The functions of each section of the circuit are explained in the following sections.

Power Supply The power supply unit consists of a step-down transformer (230V AC primary to 0-9V, 250mA secondary), bridge rectifier and voltage regulator. The output of the transformer is fed to bridge rectifier diodes D1 through D4 (each IN4007). The ripple from the output bridge rectifier is filtered by capacitor C1 and fed to regulator IC7805. The regulated output is given to the temperature sensor, microcontroller unit and LCD module, respectively. When the switch S1 is closed, LED1 glows to indicate the presence of power in the system. Temperature Sensor Temperature sensor chip DS1621 (IC3) is an 8-pin DIP IC. The pin details of DS1621 are shown in its diagram and the internal block diagram in figure-3. The chip can measure temperatures from -55 to 125 degree Celsius in 0.5 degree Celsius increments, which are read as 9-bit values. It can operate off 2.7V to 5.5V. Data is read /written via a 2-wire serial interface. Pins 1 and 2 of the temperature IC are connected to pins 11 and 10 of the microcontroller, respectively. The thermal alarm output (Tout) of IC DS1621 activates when the temperature exceeds user defined high temperature TH. The output remains active until the temperature drops below user-defined low temperature Tl. User-defined temperature settings are stored in the non-volatile memory. Temperature settings and temperature readings are all communicated to/from IC DS1621 over a 2-wire serial cable. The most significant bit (MSB) of the data is transmitted first and the last significant bit (LSB) is transmitted last. Addressing The chip address of DS1621 comprises internal preset code nibble '1001' (binary) followed by internally configurable address pins/bits A2, A1 and A0. The eighth bit of the address byte is determined by the type of operation (either read or write) that is to be performed. For writing to the device the eight bit is '0' and for reading from the device the eighth bit is '1'. In our case, A2, A1 and A0 pins are grounded and hence the device address for writing is '1001000b' or 90 (hex) and for reading the device address is '10010001b' or 91 (hex).

Configuration/Status register This register can be accessed for reading or writing by issuing command byte AC(hex) from the master (82C52). This register is particularly required if DS1621 is used for thermostat control, since it contains flag bits THF (high-temperature flag) which are set to '1' when temperature crosses the respective limits earlier written into TH and TL registers.

It also contains the flag bit (done), which is set to '1' when results of conversion are available after issuing of start conversion command EE(hex). The other bits of configuration register are defined. 'NVB' is the non-volatile memory busy flag, '1' is to write to an E2 memory cell in progress, '0' indicates that non-volatile memory is not busy, 'POL' is non-volatile output polarity bit ('1'=active high and '0' = active low) and '1shot' is one-shot mode. A copy to E2 may take up to 10ms. If 1shot is '1', DS1621 will perform one temperature conversion upon reception of the start convert T protocol. If 1shot is '0', DS1621 will continuously perform temperature conversions. This bit is non-volatile.

Command Set Complete command instruction set for accessing various internal registers as well as for starting and stopping of conversion process are given in Table. For understanding the exact sequence in which start bit, address byte, acknowledgement bit, command byte and data bytes are to be sent along the I2C bus, please refer to the datasheet of DS1621, wherein these aspects have been explained in proper detail. This will help in understanding the contents of the main program.

Microcontroller Unit Microcontroller AT89C52 (IC2) is a 40 pin IC from Atmel. Its pin details are shown in the pin description diagram. Like AT89C51, it also belongs to the 8031/8051 family. Microcontroller AT89C52 has a 256*8 bit internal random- access memory (RAM), eight interrupt sources and 8KB of flash memory compared to 128*8 -bit internal RAM, six interrupt sources and 4KB flash memory in AT89C51. By combining a versatile 8-bit CPU with flash memory on a monolithic chip, Atmel AT89C52 is a powerful, highly costeffective solution to many embedded control applications. Ports 0 and 2 are 8-bit bidirectional input/ output (I/O) ports. These ports haven't been used in this temperature indicator. Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. Ports 1.0 through 1.7 are connected to pins 7 through 14 of the LCD. Port 1 output buffers can sink/ source four TTl inputs. Port 3 is a 8-bit bidirectional I/O port with internal pull-ups. Ports 3.0 and 3.1 of IC2 are connected to serial clock line (SCL) and serial data line (SDA) of IC3, respectively. Port 3 output buffers can sink/source four TTL inputs. A 12MHz crystal oscillator is connected to XTAL1 and XTAL2 pins for operation of the microcontroller. A high pulse on RST pin (pin 9) while the oscillator is running resets the microcontroller. In this circuit, this pin is connected to +Vcc through capacitors C5 (10uF, 16V). The externalaccess enable pin (EA) is connected to +Vcc for internal program executions. This pin also receives the 12V programming enable voltage (Vpp) during flash programming when 12V program is selected

TESTING
Visualization Test: When the fabrication process is completed & all the components have been mounted perfectly the visualization testing is performed. In this testing the circuit is scanned simply by the eyes & not by the help of any instrument. It to ensure that the soldering is perfect and there is no loose connection between the components. Pre-heating Test: This test is performed to check the heat tolerance of the components. In this the circuit is provided power supply and left for some time. After a interval of time it is checked that if there is any component get faulty component specially for ICs.

Applications:
1. This system can be placed near computer processors for heat sensing. 2. Placed near heat sensitive devices to indicate the temperature. 3. This system can interfaced with computers and temperature can be controlled.

PCB Layout:

PROGRAM in Assembly:

;program for the automatic temperature Controller ;Cetpa-Roorkee ; matirx keyboard with connections on p2 port ;rows are connected to p2.0 to p2.2 ;columns are connected to p2.4 to p2.7 ;Lcd connected at p1 with Controls pins ; at rs-p3.5,rw-p3.4,en-p3.3

sda equ p0.1 scl equ p0.0 rs equ p3.5 rw equ p3.4 en equ p3.3 lcd equ p1 lcd_busy equ p1.7 key_brd equ p2 th equ 50h tl equ 51h ascii_store equ 40h delimiter equ 20h

delay_count equ 23h temperature_store equ 30h temp_result equ 35h LCD_str equ 2ah

;Flags th_flag equ 7fh tl_flag equ 7eh temp_flag equ 7dh

org 0000h mov sp,#60h lcall ini

clr th_flag clr tl_flag

mov th,#40 mov tl,#37 mov dptr,#Msg0 acall msg_read mov delay_count,#40 acall time ;for 2-sec time

; $$$$$$$$$$$$$$$

value_enter: mov r7,#01h acall command mov dptr,#Msg1 acall read ;show th

mov a,th mov r1,#LCD_str acall bin2ascii inc r1 acall tim_display

mov r7,#87H acall command mov dptr,#Msg2 acall read ;show th

mov a,tl mov r1,#LCD_str acall bin2ascii inc r1 acall tim_display

;till here default values are shown ;into nezt line show following mov r7,#0c0h acall command mov dptr,#Msg5 acall msg_read

scan0: mov key_brd,#0f0h ;bcoz upper 4 mov a,key_brd ;are connected to colu

cjne a,#0f0h,mode_check0 sjmp scan0 ;**************** detecting rows mode_check0: acall delay1 mov a,key_brd cjne a,#0f0h,mode_check1 sjmp scan0

mode_check1: acall delay acall delay1 mov key_brd,#0ffh

mov key_brd,#0fbh mov a,key_brd cjne a,#0fbh,enter_check ajmp scan0

enter_check:

;This is enter button

jb acc.6,mod43 ajmp temp_conversion_start ljmp scan0

mod43:

;This is clear button

jnb acc.7,clear_press ljmp scan0

clear_press: mov r7,#01h acall command mov dptr,#Msg1 acall read mov r7,#38h acall command mov r7,#0eh acall command ;show th

mov r7,#06h acall command mov r7,#0c0h acall command setb th_flag ; mov r6,#3 ajmp forward tl_edit: mov r7,#01h acall command

mov dptr,#Msg2 acall read mov r7,#0c0h acall command

;show tl

setb tl_flag

forward: mov lcd,#00h scan: mov key_brd,#0f0h ;bcoz upper 4 are mov a,key_brd ;connected to column

cjne a,#0f0h,row sjmp scan ;*************** detecting rows row: acall delay1 mov a,key_brd cjne a,#0f0h,row111 sjmp scan

row111: acall delay acall delay1 mov key_brd,#0ffh mov key_brd,#11111110b mov a,key_brd orl a,#0fh cjne a,#0ffh,row1 mov key_brd,#0ffh mov key_brd,#0fdh mov a,key_brd cjne a,#0fdh,row2

mov key_brd,#0ffh

mov key_brd,#0fbh mov a,key_brd cjne a,#0fbh,row3 ajmp scan

;********** row1: jb acc.4,c2 mov r7,#'0' acall display sjmp scan c2: jb acc.5,c3 mov r7,#'1' acall display sjmp scan c3: jb acc.6,c4 mov r7,#'2' acall display sjmp scan c4: mov r7,#'3'

acall display sjmp scan ;**************** row2: jb acc.4,c22 mov r7,#'4' acall display ljmp scan c22: jb acc.5,c32 mov r7,#'5' acall display ljmp scan c32: jb acc.6,c42 mov r7,#'6' acall display ljmp scan c42: mov r7,#'7' acall display ljmp scan ;****************

row3: jb acc.4,c23 mov r7,#'8' acall display ljmp scan c23: jb acc.5,c33 mov r7,#'9' acall display ljmp scan c33: jb acc.6,c43 ajmp test ;This is enter button ljmp scan c43: ;This is clear button ;not used here ljmp scan

;******************* test: mov r7,#04h acall command

acall ready acall read_add1 clr c mov b,#0c0h subb a,b mov r0,a mov r1,#ascii_store acall ready acall read_data repeat: inc r1 acall ready acall read_data mov @r1,a djnz r0,repeat mov delimiter,r1 inc delimiter

;******** ;conversion routine ;bank 1 used setb psw.3 mov r5,#00h mov r6,#00h ;used for msb ;used for storing the lsb result

mov r0,#0ah mov r2,#1 mov r3,#10 mov r4,#100 mov r1,#(ascii_store+1) here: clr a mov a,r1 cjne a,delimiter,convert ajmp break convert: mov a,@r1 anl a,#0fh mov b,@r0 mul ab mov r7,a xch a,b cjne a,#00h,hiii looo: mov a,r6 addc a,r7 jc for con: mov r6,a inc r1 ;result of add ; read till there

inc r0 ajmp here break: clr psw.3 ;********************** jb tl_flag,tl_save clr c mov a,0eh ;0eh is the add of r6 of bank1

cjne a,#7dh,th_check

th_check: jnc error_msg mov th,0eh clr th_flag ajmp tl_edit ;a> or = 125 show error ;if c then save

error_msg: mov r7,#01h acall command jb tl_flag,tl_error mov dptr,#Msg3 acall msg_read acall time

ajmp clear_press ;again enter th

tl_error: mov dptr,#Msg4 acall msg_read acall time ajmp tl_edit ;again enter tl

;***************portion of the conversion routine hiii: add a,r5 mov r5,a ajmp looo for: inc r5 ajmp con ;********************** tl_save: clr c mov a,0eh ;0eh is the add of r6 of bank2

cjne a,th,tl_check

tl_check:

jnc error_msg mov tl,0eh clr tl_flag

;a> or = th show error ;0eh is the add of r6 of bank2

;now we have to show the saved values on ;LCD & wait for enter to be pressed ajmp value_enter ;___________________________ temp_conversion_start: mov r0,#th acall delay10 acall i2cstart mov a,#90h acall i2cwrite mov a,#0ach acall i2cwrite acall delay10 mov a,#02h acall i2cwrite acall delay10 acall i2cstart mov a,#90h acall i2cwrite mov a,#0a1h

acall i2cwrite acall delay10 mov a,th acall i2cwrite mov a,#00h acall i2cwrite acall delay10 acall i2cstart mov a,#90h acall i2cwrite mov a,#0a2h acall i2cwrite acall delay10 mov a,tl acall i2cwrite mov a,#00h acall i2cwrite acall delay10 acall i2cstop clr temp_flag ;temp flag mov r7,#01h acall command mov dptr,#Msg ;#24h ;#28h

acall read mov temperature_store,#00h here1: acall temp jb temp_flag,EEE setb temp_flag mov temperature_store,a ajmp here1 EEE: cjne a,temperature_store,make_equal ajmp here1 ;temp read by this routine

make_equal: mov temperature_store,a acall conversion mov r7,#8bh acall command acall string sjmp here1 ; ************************ temp: acall i2cstart mov a,#90h

acall i2cwrite ;***************************** mov a,#0eeh acall i2cwrite ; start temp conversion acall i2cstop acall i2cstart mov a,#90h acall i2cwrite mov a,#0aah acall i2cwrite ; read last read temp acall i2cstart mov a,#91h acall i2cwrite acall i2cread acall i2cstop ret

i2cstart: setb sda acall delayone setb scl

acall delayone clr sda clr scl ret

i2cstop: clr scl clr sda setb scl acall delayone setb sda mov c,sda ret ;======================= i2cwrite: mov r0,#08h i2cwrite_loop: rlc a mov sda,c setb scl acall delayone clr scl djnz r0,i2cwrite_loop

mov c,sda setb scl acall delayone clr scl ret ;=======================

i2cread: mov c,sda mov r0,#8 rlc a i2cread_loop: setb scl mov c,sda rlc a acall delayone clr scl djnz r0,i2cread_loop ret

delayone: mov r1,#100 loopa:

djnz r1,loopa ret ;**********************

read_data:

;data is stored in the r0 register

mov lcd,#0ffh setb rs setb rw clr en setb en mov a,lcd clr en ret ;to select data register

read_add1: mov lcd,#0ffh clr rs setb rw clr en setb en mov a,lcd clr en orl a,#80h

ret

read_add: push acc mov lcd,#0ffh clr rs setb rw clr en setb en mov a,lcd clr en orl a,#80h cjne a,#8fh,out mov r7,#0c0h acall command out: pop acc ret ;******************

conversion: push acc mov a,temperature_store

mov r0,#(temperature_store+1) conloop: mov b,#10 div ab orl 0f0h,#30h mov @r0,0f0h inc r0 cjne a,#00h,conloop dec r0 mov r1,#temp_result;35h conloop1: mov a,@r0 mov @r1,a dec r0 inc r1 cjne r0,#temperature_store,conloop1 mov @r1,#'$' pop acc ret ;====================

string:

push acc mov r0,#temp_result;30h strloop: mov a,@r0 mov r7,a cjne a,#'$',continue mov r7,#' ' acall display pop acc ret continue: acall display inc r0 sjmp strloop ;******************* bin2ascii: mov @r1,#'$' dec r1 rep: mov b,#10 div ab orl 0f0h,#30h mov @r1,0f0h

dec r1 cjne a,#00h,rep ret

tim_display: brij: mov 07h,@r1 cjne r7,#'$',shoe ret shoe: acall display inc r1 ajmp brij

command: acall ready mov lcd,r7 clr rs clr rw setb en clr en ret display: acall ready

mov lcd,r7 setb rs clr rw setb en clr en ret ready: clr en mov lcd,#0ffh clr rs setb rw wait: clr en setb en jb lcd_busy,wait clr en ret

ini: mov r7,#38h acall delay1 acall delay1 acall command

mov r7,#38h acall delay1 acall command mov r7,#38h acall delay1 acall command mov r7,#0eh acall command mov r7,#01h acall command mov r7,#06h acall command mov r7,#80h acall command ret

delay10: push acc mov tmod,#01h mov tl0,#10h mov th0,#27h mov tcon,#00h setb tr0 ;1050=2710h

wait12: clr tr0

jnb tf0,wait12

pop acc ret

delay1: push 07h push 06h mov r6,#100 loop24: mov r7,#100 loop23: djnz r7,loop23 djnz r6,loop24 pop 06h pop 07h ret ;**********

delay: push acc push 00h mov r0,#02h loopr: mov b,#0a0h

loopb: mov a,#0fah loopa12: dec a jnz loopa12 djnz 0f0h,loopb djnz r0,loopr pop 00h pop acc ret

time: push 00h mov r0,30h mov tmod,#01h repeat1: mov tcon,#00h mov th0,#3ch mov tl0,#0aah setb tr0 wait1: jnb tf0,wait1 clr tr0 djnz r0,repeat1 pop 00h ;30h contain counter

ret

msg_read: push acc push 07h

nex: clr a movc a,@a+dptr mov r7,a cjne a,#'0',aga sjmp down aga: acall read_add acall display inc dptr sjmp nex down: pop 07h pop acc ret ;r7 is used for passing parameter to display

read: nex1: clr a

movc a,@a+dptr cjne a,#'0',aga1 sjmp down1 aga1: mov r7,a acall display acall delay1 inc dptr sjmp nex1 down1: ret

Msg: db 'Temprature ','0' Msg0: db 'Welcome To Auto Temp Controller','0' Msg1: db 'TH ','0' Msg2: db 'Tl ','0' Msg3: db 'Error: TH > or = 125','0' Msg4: db 'Error: Tl > or = TH','0' Msg5: db 'Enter for cont.','0' end

; mov r7,#'4' ; ; acall display mov r7,#'0'

; acall display

; ; ; ; ; ; ; ;

mov r7,#87h acall command mov dptr,#Msg2 acall read mov r7,#'3' acall display mov r7,#'7' acall display ;show tl=

;================ =====================

End

Of

Program

Code

Components List for Project


AT89C51 DS-1621 2 Line LCD Buzzer Transistor BC 548 LED Resistances Resistance 10K 470 ohm 1 1 1 1 1 1 5 5 2 1 13 1 4 1 each 1 each 2 1 1 1 1 1

33picofarad Ceramic Disk Capacitor Crystal Osci. (12 MHz) Mini Switch 10K Pot (Preset) Diode 1n4007 IC Base (8Pin, 40Pin) Relimate (5 pin and 2 pin) Relimate (16pin) Power chord Capacitor 100Microfarad/ 25v Capacitor 10 Microfarad / 25v Voltage Regulator IC 7805 Transformer (9-0-9)