temp indicator use at89c51

13
Celsius and Fahrenheit scale digital thermometer using 8051 microcontroller (AT89C51) A digital thermometer can be easily made by interfacing a temperature sensor to the microcontroller AT89C51 . The temperature sensor used in the project is LM35 . The LM 35 IC generates a 10mV variation to its output voltage for every degree Celsius change in temperature. The Output of the temperature sensor is analog in nature so we need an analog to digital convertor for converting the analog input to its equivalent binary output. The ADC 0804 is the analog to digital convertor IC used in the project. 0804 is a single channel convertor which converts the analog input up to a range of 5V to an equivalent 8-bit binary output.

Upload: sumitsa

Post on 03-Apr-2015

1.105 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Temp Indicator use AT89C51

Celsius and Fahrenheit scale digital thermometer using 8051 microcontroller (AT89C51)

A digital thermometer can be easily made by interfacing a temperature sensor to the microcontroller AT89C51. The temperature sensor used in the project is LM35. The LM 35 IC generates a 10mV variation to its output voltage for every degree Celsius change in temperature. The Output of the temperature sensor is analog in nature so we need an analog to digital convertor for converting the analog input to its equivalent binary output. The ADC 0804 is the analog to digital convertor IC used in the project. 0804 is a single channel convertor which converts the analog input up to a range of 5V to an equivalent 8-bit binary output.

Page 2: Temp Indicator use AT89C51
Page 3: Temp Indicator use AT89C51

//Program to display temperature in Celsius and Farenheit scale.

#include<reg51.h>#define port P3#define adc_input P1#define dataport P0#define sec 100sbit rs = port^0;sbit rw = port^1;sbit e = port^2;

sbit wr= port^3;sbit rd= port^4;sbit intr= port^5;

int test_intermediate3=0, test_final=0,test_intermediate1[10],test_intermediate2[3]={0,0,0};

void delay(unsigned int msec ){ int i ,j ; for(i=0;i<msec;i++) for(j=0; j<1275; j++);}

void lcd_cmd(unsigned char item) // Function to send commands to LCD{ dataport = item; rs= 0; rw=0; e=1; delay(1); e=0; return;}

void lcd_data(unsigned char item) // Function to send data to LCD{ dataport = item; rs= 1; rw=0; e=1; delay(1); e=0; return;}

void lcd_data_string(unsigned char *str) // Function to string to LCD{ int i=0; while(str[i]!='\0') { lcd_data(str[i]); i++; delay(10); } return;

Page 4: Temp Indicator use AT89C51

}

void shape() // Function to make the shape of degree symbol{ lcd_cmd(64); lcd_data(2); lcd_data(5); lcd_data(2); lcd_data(0); lcd_data(0); lcd_data(0); lcd_data(0); lcd_data(0);} void convert() // Function to convert the values of ADC into numeric value to be sent to LCD{ int s; lcd_cmd(0x81); delay(2); lcd_data_string("TEMP:"); test_final=(((9*test_intermediate3)/5)+32); s=test_final/100; test_final=test_final%100; lcd_cmd(0x88); if(s!=0) lcd_data(s+48); else lcd_cmd(0x06); s=test_final/10; test_final=test_final%10; lcd_data(s+48); lcd_data(test_final+48); lcd_data(0); lcd_data('F'); lcd_data(' ');

test_final=test_intermediate3; lcd_cmd(0xc1); //Setting cursor to first position of first line delay(2); lcd_data_string("TEMP:"); s=test_final/100; test_final=test_final%100; lcd_cmd(0xc8); if(s!=0) lcd_data(s+48); else lcd_cmd(0x06); s=test_final/10; test_final=test_final%10; lcd_data(s+48); lcd_data(test_final+48); lcd_data(0); lcd_data('c'); lcd_data(' '); delay(2);

Page 5: Temp Indicator use AT89C51

}

void main(){ int i,j; adc_input=0xff; lcd_cmd(0x38); //2 Line, 5X7 Matrix display lcd_cmd(0x0c); //Display On, Cursor blinking delay(2); lcd_cmd(0x01); // clear screen delay(2);

while(1) { for(j=0;j<3;j++) { for(i=0;i<10;i++) { delay(1); rd=1; wr=0; delay(1); wr=1; while(intr==1); rd=0; lcd_cmd(0x88); test_intermediate1[i]=adc_input/10; delay(1); intr=1; } for(i=0;i<10;i++) test_intermediate2[j]=test_intermediate1[i]+test_intermediate2[j]; }

test_intermediate2[0]=test_intermediate2[0]/3; test_intermediate2[1]=test_intermediate2[1]/3; test_intermediate2[2]=test_intermediate2[2]/3; test_intermediate3=test_intermediate2[0]+test_intermediate2[1]+test_intermediate2[2]; shape(); convert(); }}

Page 6: Temp Indicator use AT89C51

Analog to digital converters find huge application as an intermediate device to convert the signals from analog to digital form. These digital signals are used for further processing by the digital processors. Various sensors like temperature, pressure, force etc. convert the physical characteristics into electrical signals that are analog in nature.

ADC0804 is a very commonly used 8-bit analog to digital convertor. It is a single

channel IC, i.e., it can take only one analog signal as input. The digital outputs vary from

0 to a maximum of 255. The step size can be adjusted by setting the reference voltage

at pin9. When this pin is not connected, the default reference voltage is the operating

voltage, i.e., Vcc. The step size at 5V is 19.53mV (5V/255), i.e., for every 19.53mV rise

in the analog input, the output varies by 1 unit. To set a particular voltage level as the

reference value, this pin is connected to half the voltage. For example, to set a

reference of 4V (Vref), pin9 is connected to 2V (Vref/2), thereby reducing the step size

to 15.62mV (4V/255). 

ADC0804 needs a clock to operate. The time taken to convert the analog value to digital

value is dependent on this clock source. An external clock can be given at the Clock IN

pin. ADC 0804 also has an inbuilt clock which can be used in absence of external clock.

A suitable RC circuit is connected between the Clock IN and Clock R pins to use the

internal clock.

 

Pin Diagram: 

Page 7: Temp Indicator use AT89C51

Pin Description: 

Page 8: Temp Indicator use AT89C51

Pin No

Function Name

1 Activates ADC; Active low Chip select2 Input pin; High to low pulse brings the data from internal

registers to the output pins after conversionRead

3 Input pin; Low to high pulse is given to start the conversion Write4 Clock Input pin; to give external clock. Clock IN5 Output pin; Goes low when conversion is complete Interrupt6 Analog non-inverting input Vin(+)7 Analog inverting Input; normally ground Vin(-)8 Ground(0V) Analog

Ground9 Input pin; sets the reference voltage for analog input Vref/2

10 Ground(0V) Digital Ground11

8 bit digital output pins

D712 D613 D514 D415 D316 D217 D118 D019 Used with Clock IN pin when internal clock source is used Clock R20 Supply voltage; 5V Vcc

Page 9: Temp Indicator use AT89C51

LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on.

A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In

this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers,

namely, Command and Data.

The command register stores the command instructions given to the LCD. A command

is an instruction given to LCD to do a predefined task like initializing it, clearing its

screen, setting the cursor position, controlling display etc. The data register stores the

data to be displayed on the LCD. The data is the ASCII value of the character to be

displayed on the LCD.

Pin Diagram: 

Page 10: Temp Indicator use AT89C51

Pin Description:  Pin No

 Function  Name

1 Ground (0V) Ground2 Supply voltage; 5V (4.7V – 5.3V)  Vcc3 Contrast adjustment; through a variable  VEE

4 Selects command register when low; and data register when high

Register Select

5 Low to write to the register; High to read from the register Read/write6 Sends data to data pins when a high to low pulse is given Enable7

8-bit data pins

DB08 DB19 DB2

10 DB311 DB412 DB513 DB614 DB715 Backlight VCC (5V) Led+16 Backlight Ground (0V) Led-

 

A preset is a three legged electronic component which can be made to offer varying

resistance in a circuit. The resistance is varied by adjusting the rotary control over it.

Page 11: Temp Indicator use AT89C51

The adjustment can be done by using a small screw driver or a similar tool. The

resistance does not vary linearly but rather varies in exponential or logarithmic manner.

Such variable resistors are commonly used for adjusting sensitivity along with a sensor.

 

The variable resistance is obtained across the single terminal at front and one of the two

other terminals. The two legs at back offer fixed resistance which is divided by the front

leg. So whenever only the back terminals are used, a preset acts as a fixed resistor.

Presets are specified by their fixed value resistance.