Sei sulla pagina 1di 41

Thapar University

PROJECT REPORT on

MICRO-CONTROLLER (8051) and 8051 based Temperature Sensor

DECLARATION
I hereby declare that the project work on 8051 MICRO-CONTROLLER is an authentic record of my own work carried out at CDAC, MOHALI (PHASE 8) as requirements of six weeks project term for the award of degree of B.E. (Electronics & Communication Engineering), THAPAR UNIVERSITY, PATIALA, under the guidance of Mr. Ajay, Project in charge, CDAC during 18-June to 27-July, 2012.

Acknowledgement
First and foremost I would like to thank Mr. Abbas- training coordinator at CENTRE FOR DEVELOPMENT OF ADVANCED COMPUTING,MOHALI, for providing me the knowledge of MICRO CONTROLLER 8051. I would also like to thank to all the technical experts Mr. Ajay and Ms. Farihaa Naaz, project heads at CDAC MOHALI, for explaining practical aspects of the theoretical knowledge. My greatest thanks is to Mr. Ajay and Ms. Farihaa Naaz who helped me and my team mate in completion of the project by their consistent guidance and supervision on each and every step of our project. Without their push and direction, our project would have not been completed. Their continuous support and motivation made this project possible. I would also like to thank our teachers in Thapar University who helped me in understanding the basics of this course. Without their support I would not have been able to excel in my project. Lastly, I would like to thank my team mate for contributing to my project.

List of Contents

Preface Profile of the company Introduction 8051 micro-controller architecture Pin configuration Types of memory SFRs Timers and counters Addressing modes Interfacing Project description References

Preface

This training report is all about the MICRO-CONTROLLER and its application in various fields of real world. Our daily life largely depends on the proper functioning of these embedded micro-controller gadgets. Television, radio, cd player, washing machine or microwave oven in our kitchen, card readers, access controllers, palm devices of our work space enable us to do many of our tasks very effectively. Apart from all these, many controllers embedded in our car take care of car operations between the bumpers. All kinds of magazines and journals regularly dish out details about latest technologies, new devices; fast applications which make us believe that our basic survival is controlled by these products. Now we can agree to the fact that these products have successfully invaded into our world. What is this microcontroller? Theoretically, an embedded controller is a combination of piece of micro-processor based hardware and the suitable software to undertake a specific task. I have made a project based on microcontroller that is a TEMPERATURE SENSOR. This training report covers all about the microcontroller and project description. In this project i have implemented the working of temperature sensor that is describing a small application of microcontroller.

Profile of the company


Centre for Development of Advanced Computing (C-DAC), Mohali is a scientific society of the Ministry of Communications and Information Technology, Government of India. It was set up as Center for Electronics Design & Technology of India (CEDTI), Mohali. But later on CEDTI, Mohali merged with C-DAC with a primary mandate to promote high end R&D. CDAC Mohali, ISO 9001:2008 certified, is a Research & Development organization engaged in design and deployment of world class IT and electronics solutions. C-DAC Mohali also offers high-end courses like M.Tech in VLSI as well as ME in Electronic Product Design Technology (EPDT). The major thrust areas of the Centre in training are: Medical Electronics, Telecommunication, Animation & Multimedia Technologies, PCB Design & Manufacturing, CADD Engineering, Network Security, Embedded System Design & Entrepreneurship Development Programs.

Introduction

A micro-controller is a programmable logic and integrated circuit which can be programmed to do number of tasks. It is possible to control just about anything with the program written by the user. Some of the functions of micro-controller are:Ability to execute a stored set of instructions to carry out user defined task. Ability to access external memory chips to read and write data from/to memory Ability to interface with the I/O devices. Basic components of the micro-controller are:

CPU to execute programmed code Memory, both RAM & ROM Internal timers An input/output system, in form of i/o pins Some micro-controllers have some extra features like:

ADCs and DACs UART for serial communication Internal EEPROM PWM modules for analogue output. Micro-controllers are usually dedicated devices embedded within an application. For example, micro-controllers are used as engine controllers in automobiles and as exposure and focus controllers in cameras. In order to serve these applications, they have a high concentration of on-chip facilities such as serial ports, parallel input output ports, timers, counters, interrupt control, analog-to-digital converters, random access memory, read only memory, etc. The I/O, memory, and on-chip peripherals of a microcontroller are selected depending on the specifics of the target application. Since microcontrollers are powerful digital processors, the degree of control and programmability they provide significantly enhances the effectiveness of the application.

Micro-processor and Micro-controller are commonly used terms. Microprocessors generally require external components or circuits to implement program memory, RAM memory and Input/output. Intel's 8085, 80386 and Pentium are examples of microprocessors. Micro-controllers incorporate program memory, RAM memory and input/output port into one chip. Microchip's PIC series and Atmel's AVR series are examples of microcontrollers. One of the main differences is that micro-controllers are usually designed to perform a small set of specific functions, for example as in the case of a Automatic Braking System which performs a small set of input

processing functions, whereas micro-processors tend to be designed to perform a wider set of general purpose functions. For example, microcontrollers are widely used in modern cars where they will each perform a dedicated task, i.e. a micro-controller to regulate the brakes on all four wheels, or a micro-controller to regulate the car air conditioning, or a microcontroller for automatic gate systems. These micro-controllers will perform few other tasks (if any) other than those specified. Compare to a microprocessor in a PC which performs a wide range of tasks related to the general requirements of a PC such as performing the necessary calculations for a very wide set of software applications, performing input/output for the main subsystems, peripheral control etc. In short we can say that: A micro-controller differs from a micro-processor, which is general-purpose chip that is used to create a multi function computer or device and requires multiple chips to handle various tasks. A micro-controller is meant to be more self-contained and independent, and functions as a tiny, dedicated computer.

8051 MICRO-CONTROLLER ARCHITECTURE


All 805C51 devices have separate addresses or program and data memory, as shown in figure 1. The logical separation of the program and data memory allows the data memory to be accessed by 8-bit addresses, which can be quickly stored and manipulated by an 8-bit CPU. Nevertheless, 16-bit data memory address can also be generated through the DPTR (data pointer) register. Program memory (ROM, EPROM) can only be read, not written to. There can be upto 64k bytes of program memory. In the 89C51, the lowest 4k bytes of program are on-chip.

Figure 1 In the ROM less version, all program memory is external. The read strobe for external program memory is the PSEN (program store enable). Data Memory (RAM) occupies a separate address space from Program Memory. In the 80C51, the lowest 128 bytes of data memory are on-chip.

Up to 64k bytes of external RAM can be addressed in external Data Memory space. In the ROM less version, lowest 128 bytes are on-chip. The CPU generates read and write signals RD and WR, as needed during external Data Memory accesses. The microcontrollers have an 8-bit data bus. The 8051 has 128 bytes of internal Random Access Memory (RAM). It has two timer/counters, a serial port, 4 general purpose parallel input/output ports, and interrupt control logic with five sources of interrupts. Besides internal RAM, the 8051 has various Special Function Registers (SFR), which are the control and data registers for on-chip facilities. Some of the salient features that have made the 8051 popular are: 8-bit data bus 16-bit address bus 32 general purpose registers each of 8 bits 16 bit timers (usually 2, but may have more, or less). 3 internal and 2 external interrupts. Bit as well as byte addressable RAM area of 16 bytes. Four 8-bit ports, (short models have two 8-bit ports). 16-bit program counter and data pointer

8051 MICROCHIP

COMPARISON OF 8051 FAMILY MEMBER

FEATURES ROM(program source in bytes) RAM(in bytes) TIMER I/O PINS SERIAL PORT INTERRUPT SOURCES

8051 4k 128 2 32 1 6

8052 8k 256 3 32 1 8

8031 0k 128 2 32 1 6

Pin configuration

PIN DIAGRAM FOR 8051

PIN 30(ALE/PROG):
Address Latch Enable output pulse for latching the low byte of address during accesses to external memory.ALE is emitted at a constant rate of 1/6 of the oscillator frequency, for external timing or clocking purposes, even when there is no access to external data. (However, one ALE pulse is skipped during each access to external Data Memory.) This pin is also the program pulse input (PROG) during EPROM programming.

PIN 29 (PESN):
Program Store Enable is the read strobe to external Program Memory. When the devices is executing out of external Program Memory, PSEN is activated

twice each machine cycle (except that two PSEN activation are skipped during accesses to external data memory). PSEN is not activated when the device is executing out of internal Program Memory.

EA/VPP (PIN 31)


When EA is held high the CPU executes out of internal Program Memory. Holding EA low forces the CPU to execute out of external memory regardless of the Program Memory.

PIN 9(RST):
PIN 9 is the reset pin which is used reset the micro-controllers internal registers and ports. It is an input and is active high (normally low). On applying high pulse to this pin, micro-controller will reset and terminate all the activities. This is also called Power-on reset. But this power-on reset will cause all values in registers to be lost.

PINS 18 & 19(XTAL2, XTAL1):


The 8051 has a built-in oscillator amplifier hence we need to only connect a crystal at these pins to provide clock pulses to the circuit. XTAL1 signifies the input to inverting oscillator amplifier. XTAL2 signifies the output from inverting oscillator amplifier.

PIN 40 and 20:


Pins 40 and 20 are VCC and ground respectively. The 8051 chip needs +5V500mA to function properly.

There are 4 8-bit ports: P0, P1, P2 and P3: PORT P1 (Pins 1 to 8):
The port P1 is a general purpose input/output port which can be used for a variety of interfacing tasks. The other ports P0, P2 and P3 have dual roles or additional functions associated with them based upon the context of their usage. There is an internal pull up.

PORT P3 (Pins 10 to 17):


PORT P3 acts as a normal IO port, but Port P3 has additional functions such as, serial transmit(P3.0) and receive(P3.1) pins, 2 external interrupt pins(P3.2 , P3.3), 2 external counter/timer(P3.4 , P3.5) inputs, read(P3.7) and write(P3.6) pins for memory access. There is an internal pull up.

PORT P2 (pins 21 to 28):

PORT P2 can also be used as a general purpose 8 bit port when no external memory is present, but if external memory access is required then PORT P2 will act as an address bus in conjunction with PORT P0 to access external memory. PORT P2 acts as A8-A15. There is an internal pull up.

PORT P0 (pins 32 to 39):


PORT P0 can be used as a general purpose 8 bit port when no external memory is present, but if external memory access is required then PORT P0 acts as a multiplexed address and data bus that can be used to access external memory in conjunction with PORT P2. P0 acts as AD0-AD7. There is no internal pull up, we need to add a pull up resistance externally (SIP).

TYPES OF MEMORY
The 8051 has three very general types of memory. To effectively program the 8051 it is necessary to have a basic understanding of these memory types. The memory types are illustrated in the following graphic. They are: On-Chip Memory, External Code Memory, and External RAM.

On-Chip Memory:
It refers to any memory (Code, RAM, or other) that physically exists on the microcontroller itself. On-chip memory can be of several types: Internal RAM: - It is fastest RAM available and is most flexible in terms of reading writing and modifying its contents. It is volatile, so when 8051 is reset this memory is cleared. It supports 128 bytes. SFRs:- These are a sort of control table used for running and monitoring the operation of the microcontroller. Out of 128 memory locations there are only 21 such registers

External Code Memory:

It is code (or program) memory that resides off-chip. This is often in the form of an external EPROM. It is the memory that actually holds the 8051 program that is to be run. This memory is limited to 64k and comes in many shapes and sizes

External RAM:
It is RAM memory that resides off-chip. This is often in the form of standard static RAM or flash RAM. Since this memory is off-chip it is not flexible in terms of accessing and is also slower. Although it looses speed and flexibility, it gains quality. It supports upto 64k.

INTERNAL RAM Internal RAM consists of 4 Register Banks: RB0 RB1 RB2 RB3 These are set according to the requirements and controlled using PSW (PSW.4, PSW.3).

SFR MEMORY MAP

SPECIAL FUNCTION registers (SFRS)


SFR is the upper area of addressable memory, from address 0x80 to 0xFF. This area of memory cannot be used for data or program storage, but is instead a series of memory-mapped ports and registers. All port input and output can therefore be performed by memory MOV operations on specified addresses in the SFR. Also, different status registers are mapped into the SFR, for use in checking the status of the 8051, and changing some operational parameters of the 8051

The Accumulator (A)


The Accumulator, as its name suggests, is used as a general register to accumulate the results of a large number of instructions. It can hold an 8-bit (1-byte) value and is the most versatile register the 8051 has due to the sheer number of instructions that make use of the accumulator. More than

half of the 8051s 255 instructions manipulate or use the accumulator in some way.

The B Register
The "B" register is very similar to the Accumulator in the sense that it may hold an 8-bit (1- byte) value. The "B" register is only used by two 8051 instructions: MUL AB and DIV AB. Thus, if you want to quickly and easily multiply or divide A by another number, you may store the other number in "B" and make use of these two instructions. Aside from the MUL and DIV instructions, the B register is often used as yet another temporary storage register much like a ninth "R" register.

The Data Pointer (DPTR)


The Data Pointer (DPTR) is the 8051s only user-accessible 16-bit (2-byte) register. The Accumulator, "R" registers, and "B" register are all 1-byte values. DPTR, as the name suggests, is used to point to data. It is used by a number of commands which allow the 8051 to access external memory. When the 8051 accesses external memory it will access external memory at the address indicated by DPTR. It is a combination of 2 8-bit registers i.e. DPH (higher) and DPL (lower). The data pointer is used in operations regarding external RAM and some instructions involving code memory. Since it is an unsigned two-byte integer value, it can represent values from 0000h to FFFFh (0 through 65,535 decimal).

The Program Counter (PC)


The Program Counter (PC) is a 2-byte address which tells the 8051 where the next instruction to execute is found in memory. When the 8051 is initialized PC always starts at 0000h and is incremented each time an instruction is executed. It is important to note that PC isnt always incremented by one. Since some instructions require 2 or 3 bytes the PC will be incremented by 2 or 3 in these cases. The Program Counter is special in that there is no way to directly modify its value.

DPTR REGISTER The Stack Pointer (SP)


The Stack Pointer, like all registers except DPTR and PC, may hold an 8-bit (1-byte) value. The Stack Pointer is used to indicate where the next value to be removed from the stack should be taken from. When you push a value onto the stack, the 8051 first increments the value of SP and then stores the value at the resulting memory location. When you pop a value off the stack, the 8051 returns the value from the memory location indicated by SP and then decrements the value of SP. This order of operation is important. When the 8051 is initialized SP will be initialized to 07h.If you immediately push a value onto the stack, the value will be stored in Internal RAM address 08h. First the 8051 will increment the value of SP (from 07h to 08h) and then will store the pushed value at that memory address (08h). Then on using POP instruction the 8051 will decrement the value of SP (from 08h to 07h) and then will store the popped value at the specified memory location.

IE (Interrupt Enable, Addresses A8h):


The Interrupt Enable SFR is used to enable and disable specific interrupts. The low 7 bits of the SFR are used to enable/disable the specific interrupts, where as the highest bit is used to enable or disable ALL interrupts. Thus, if the high bit of IE is 0 all interrupts are disabled regardless of whether an individual interrupt is enabled by setting a lower bit.

PSW (Program Status Word, Addresses D0h, BitAddressable):


The Program Status Word is used to store a number of important bits that are set and cleared by8051 instructions. The PSW SFR contains the carry flag, the auxiliary carry flag, the overflow flag, and the parity flag. Additionally, the PSW register contains the register bank select flags which are used to select which of the "R" register banks are currently selected

PSW TABLE

Timers/Counters
The 8051 comes equipped with two timers, both of which may be controlled, set, read, and configured individually. The 8051 timers have three general functions: Keeping time and/or calculating the amount of time between events, Counting the events themselves, Generating baud rates for the serial port. As mentioned before, the 8051 has two timers which each function essentially the same way. TIMER0 TIMER1 The two timers share two SFRs (TMOD and TCON) which control the timers, and each timer also has two SFRs dedicated solely to itself (TH0/TL0 and TH1/TL1).

TMOD (Timer Mode, Addresses 89h):


The Timer Mode SFR is used to configure the mode of operation of each of the two timers. Using this SFR your program may configure each timer to be a 16-bit timer, an 8-bit auto reload timer, a 13-bit timer, or two separate timers. Additionally, you may configure the timers to only count when an external pin is activated or to count "events" that are indicated on an external pin.TL0/TH0 (Timer 0 Low/High, Addresses 8Ah/8Ch): These two SFRs, taken together, represent timer 0. Their exact behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is configurable is how and when they incrementing value.TL1/TH1 (Timer 1 Low/High, Addresses 8Bh/8Dh): These two SFRs, taken together, represent timer 1. Their exact behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is configurable is how and when they incrementing value.

TMOD REGISTER

TCON (Timer Control, Addresses 88h, Bit-Addressable):


The Timer Control SFR is used to configure and modify the way in which the 8051's two timers operate. This SFR controls whether each of the two timers is running or stopped and contains a flag to indicate that each timer has overflowed. Additionally, some non-timer related bits are located in the TCON SFR. These bits are used to configure the way in which the external interrupts are activated and also contain the external interrupt flags which are set when an external interrupt has occurred.

TCON REGISTER

ADDRESSING MODE
An "addressing mode" refers to how you are addressing a given memory location. In summary, the addressing modes are as follows, with an example of each:

Immediate addressing:

Immediate addressing is so-named because the value to be stored in memory immediately follows the operation code in memory. That is to say, the instruction itself dictates what value will be stored in memory. For example, the instruction: MOV A, #20h This instruction uses Immediate Addressing because the Accumulator will be loaded with the value that immediately follows; in this case 20 (hexadecimal).Immediate addressing is very fast since the value to be loaded is included in the instruction. However, since the value to be loaded is fixed at compile-time it is not very flexible.

Direct Addressing:
Direct addressing is so-named because the value to be stored in memory is obtained by directly retrieving it from another memory location. For example: MOV A, 30h This instruction will read the data out of Internal RAM address 30 (hexadecimal) and store it in the Accumulator. Direct addressing is generally fast since, although the value to be loaded isnt included in the instruction, it is quickly accessible since it is stored in the 8051s Internal RAM. It is also much more flexible than Immediate Addressing since the value to be loaded is whatever is found at the given address--which may be variable. Also, it is important to note that when using direct addressing any instruction which refers to an address between 00h and 7Fh is referring to Internal Memory. Any instruction which refers to an address between 80h and FFh is referring to the SFR control registers that control the 8051microcontroller itself.

Register addressing:
The register banks, containing registers R0 through R7, can be accessed by certain instructions which carry a 3-bit register specification within the opcode of the instruction. Instructions that access the registers this way are code efficient, since this mode eliminates an address byte. When the instruction is executed, one of the eight registers in the selected bank is accessed. One of four banks is selected at execution time by the two bank select bits in the PSW.

Register indirect addressing:


Indirect addressing is a very powerful addressing mode which in many cases provides an exceptional level of flexibility. Indirect addressing is also the only way to access the extra 128 bytes of Internal RAM found on an 8052.Indirect addressing appears as follows: MOV A,@R0

This instruction causes the 8051 to analyze the value of the R0 register. The 8051 will then load the accumulator with the value from Internal RAM which is found at the address indicated by R0.

Indexed addressing:
Used in accessing data elements of look up table entries located in the program ROM space of 8051 E.g. MOVC A@A+DPTR.

INTERRUPTS
As the name implies, an interrupt is some event which interrupts normal program execution. As stated earlier, program flow is always sequential, being altered only by those instructions which expressly cause program flow to deviate in some way. However, interrupts give us a mechanism to "put on hold" the normal program flow, execute a subroutine, and then resume normal program flow as if we had never left it. This subroutine, called an interrupt handler, is only executed when a certain event (interrupt) occurs. The event may be one of the timers "overflowing," receiving a character via the serial port, transmitting a character via the serial port, or one of two "external events." The 8051 may be configured so that when any of these events occur the main program is temporarily suspended and control passed to a special section of code which presumably would execute some function related to the event that occurred. Once complete, control would be returned to the original program. The main program never even knows it was interrupted. The ability to interrupt normal program execution when certain events occur makes it much easier and much more efficient to handle certain conditions. If it were not for interrupts we would have to manually check in our main program whether the timers had over flown, whether we had received another character via the serial port, or if some external event had occurred. Besides making the main program ugly and hard to read, such a situation would make our program inefficient since wed be burning precious "instruction cycles" checking for events that usually dont happen. We can

configure the 8051 so that any of the following events will cause an interrupt: Timer 0 Overflow. Timer 1 Overflow. Reception/Transmission of Serial Character. External Event 0. External Event 1. In other words, we can configure the 8051 so that when Timer 0 overflows or when a character is sent/received, the appropriate interrupt handler routines are called.

Polling Sequence:
The 8051 automatically evaluates whether an interrupt should occur after every instruction. When checking for interrupt conditions, it checks them in the following order: External 0 Interrupt Timer 0 Interrupt External 1 Interrupt Timer 1 Interrupt Serial Interrupt This means that if a Serial Interrupt occurs at the exact same instant that an External 0 Interrupt occurs, the External 0 Interrupt will be executed first and the Serial Interrupt will be executed once the External 0 Interrupt has completed.

Interfacing

LED AND SWITCH INTERFACING:


Push button switches are widely used in embedded system projects and the knowledge about interfacing them to 8051 is very essential in designing such projects. A typical push button switch has two active terminals that are normally open and these two terminals get internally shorted when the push button is depressed. An image of a typical pushbutton switch is shown below.

Switches

Leds

Interfacing 8051 and pushbutton


The circuit diagram for interfacing push button switch to 8051 is shown above. AT89S51 is the microcontroller used here. The circuit is so designed that when push button S1 is depressed the LED D1 goes ON and remains ON until push button switch S2 is depressed and this cycle can be repeated. Resistor R3, capacitor C3 and push button S3 forms the reset circuitry for the microcontroller. Capacitor C1, C2 and crystal X1 belongs to the clock circuitry. R1 and R2 are pull up resistors for the push buttons. R4 is the current limiting resistor for LED.

7 SEGMENT DISPLAY:
A seven segment consists of eight LEDs which are aligned in a manner so as to display digits from 0 to 9 when proper combination of LED is switched on. Seven segment uses seven LEDs to display digits from 0 to 9 and the eighth LED is used

for the dot. A typical seven segment looks like as shown in the figure below.

Seven segment are available in two configuration Common Anode Common Cathode. Here common anode seven segment display is used because the output current of the microcontroller is not sufficient enough to drive the LEDs, similar to the case of driving an LED. The circuit diagram shows the connections of seven segment to the controller. The pins a to g of the Seven Segment are connected to the Port P2 of the microcontroller. The common pin of the seven segment is connected to VCC. The h has not been used, which is the dot pin of the controller. Since the seven segment display works on negative logic, we will have to provide logic 0 to the corresponding pin to make an LED glow. Table below shows the hex values used to display the different digits.

DIGIT 0 1 2 3 4 5 6 7 8 9

a 0 1 0 0 1 0 0 0 0 0

b 0 0 0 0 0 1 1 0 0 0

c 0 0 1 0 0 0 0 0 0 0

d 0 1 0 0 1 0 0 1 0 1

e 0 1 0 1 1 1 0 1 0 1

f 0 1 1 1 0 0 0 1 0 0

g 1 1 0 0 0 0 0 1 0 0

HEX Value 0x40 0xF9 0x24 0x30 0x19 0x12 0x02 0xF8 0x00 0x10

When the values corresponding to the digits 0 to 9 are given on the output port, the digit gets displayed on the seven segment.

Lcd interfacing:
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. Command/Instruction Register - stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing, clearing the screen, setting the cursor position, controlling display etc. 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.

Commonly used LCD Command codes: Hex Code 1 2 4 6 E 80 C0 38 Command to LCD Instruction Register Clear screen display Return home Decrement cursor Increment cursor Display ON, Cursor ON Force the cursor to the beginning of the 1st line Force cursor to the beginning of the 2nd line Use 2 lines and 5x7 matrix

Pin configuration:
Pin 1 2 3 Symbol VSS VCC VEE RS Description Ground Main power supply Power supply to control contrast 0V +5 V Contrast adjustment by providing a variable resistor through VCC RS=0 to select Command Register RS=1 to select Data Register R/W=0 to write to the register R/W=1 to read from the register A high to low pulse

Register Select

R/W

Read/write

EN

Enable

(minimum 450ns wide) is given when data is sent to data pins 7 DB0 To display letters or numbers, their ASCII codes are sent to data pins (with RS=1). Also instruction command codes are sent to these pins.

8 9 10 11 12 13 14 15 16

DB1 DB2 DB3 DB4 DB5 DB6 DB7 Led+ Led-

8-bit data pins

Backlight VCC Backlight Ground

+5 V 0V

Programming the LCD: 1. Data pin8 (DB7) of the LCD is busy flag and is read when R/W = 1 & RS = 0. When busy flag=1, it means that LCD is not ready to accept data since it is busy with the internal operations. Therefore before passing any data to LCD, its command register should be read and busy flag should be checked. 2. To send data on the LCD, data is first written to the data pins with R/W = 0 (to specify the write operation) and RS = 1 (to select the data register). A high to low pulse is given at EN pin when data is sent. Each write operation is performed on the positive edge of the Enable signal. 3. To send a command on the LCD, a particular command is first specified to the data pins with R/W = 0 (to specify the write operation) and RS = 0 (to select the command register). A high to low pulse is given at EN pin when data is sent.

PROJECT ON TEMPERATURE SENSOR


Introduction:
Temperature sensors are devices used to measure the temperature of a medium. Consumer and commercial thermal applications all rely on temperature sensors. Simpler applications, such as electronic thermometers monitoring outdoor temperatures or temperature monitors inside vehicles, only report ambient temperatures.

Bill of material:
1 - AT89C2051-24PC Microcontroller (unprogrammed) 1 - 11.0592 MHz Crystal 2 - 33pF Capacitors 1 - 150pF Capacitor 1 - 10 uF Capacitor 1 - 220 uF Capacitor 1 - 8.2k Resistor 5 - 240 Ohm Resistors 5 - 510 Ohm Resistors 5 - 1k Resistors 5 - 2.2k Resistors 5 - 5.1k Resistors 5 - 10k Resistors 5 - 15k Resistors

1 - MAX232 1 - ADC0804 5 - 1 uF capacitors 1 - DB9 connector 1 LM 35 Temperature Sensor Jumper Wires

5 VOLT POWER SUPPLY:

A 5 Volt DC Power Supply has been used to supply power to the circuit. The above circuit is a small +5 Volts power supply, which is useful when experimenting with digital electronics. It consists of small inexpensive wall transformer with variable output voltage. The circuit can give +5V output at about 150mA current. The capacitors have high voltage ratings to safely handle the input voltage feed to the circuit. If we need other voltages than +5V, the circuit could be modified by replacing 7805 chip with other voltage regulators with different output voltage from regulator 78XX chip family.

DESCRIPTION: In this project , the IC used for sensing temperature is LM35. The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature.

The circuit uses A/D converter and AT89C51 microcontroller and the code for the project has been written in Assembly language.

WORKING:

When the power is supplied to the circuit, temperature sensor LM35 senses the temperature of the medium of which it is in the contact with. This means an analog signal is generated. This signal is passed through the A/D converter which converts the analog signal into digital signal. In Free Running Mode, ADC0804 will issue the results of reading the input data automatically and sustainable (Continue) after they finish converting analog

to digital. INTR pin will be logic low after the ADC conversion is complete, this logic is used as an insert for ordering WR ADC to start conversion again. Control Mode is a new mode to start the ADC conversion after being given instructions from the microcontroller. Instruction is done by providing a low pulse to the WR input instantaneous +1 ms, and then read the ADC output data after INTR logic output low. This raw data is sent to the micro-controller to which led is interfaced. As this data is in hexadecimal , it is converted into decimal and then into ASCII for proper display on the lcd. In this way, LCD displays the temperature.

CODE ORG 00h mov p1,#0ffh setb p2.7 acall display1 back: clr p2.6 setb p2.6 here: jb p2.7,here clr p2.5 mov a,p1 acall cnvrsn acall display setb p2.5 sjmp back

cnvrsn: acall bin_dec_convrt acall dec_asci_convrt

ret bin_dec_convrt: mov r0,#40h mov a,p1 mov b,#10 div ab mov @r0,b inc r0 mov b,#10 div ab mov @r0,b inc r0 mov @r0,a ret

dec_asci_convrt: mov r0,#40h mov r1,#50h mov r2,#3 back1: mov a,@r0 orl a,#30h mov @r1,a inc r0 inc r1 djnz r2,back1 ret

display1:

mov a,#38h

acall command acall delay mov a,#0ch acall command acall delay mov a,#01h acall command acall delay mov a,#06h acall command acall delay mov a,#84h acall command acall delay mov a,#'t' acall data2 acall delay mov a,#'e' acall data2 acall delay mov a,#'m' acall data2 acall delay mov a,#'p' acall data2 acall delay

mov a,#':' acall data2 acall delay mov a,#8Ch acall command acall delay mov a,#'C' acall data2 acall delay ret

display:

mov a,#8Ah acall command acall delay mov a,51h acall data2 acall delay mov a,50h acall data2 acall delay ret

command:

mov p0,a clr p3.4 setb p3.5 clr p3.5

ret data2: mov p0,a setb p3.4 setb p3.5 clr p3.5 ret

delay: here2: here1:

mov r3,#50h mov r4,#0ffh djnz r4,here1 djnz r5,here2 ret end

CIRCUIT DIAGRAM:

References

Muhammad Ali Mazidi, THE 8051 MICRO-CONTROLLER AND EMBEDDED SYSTEMS

www.engineersgarrage.com

www.8051projects.com www.wikipedia.com

Potrebbero piacerti anche