Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
PROJECT REPORT on
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.
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.
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
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 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.
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.
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 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.
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
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).
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.
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 REGISTER
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.
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
Switches
Leds
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
+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.
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
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
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:
ret data2: mov p0,a setb p3.4 setb p3.5 clr p3.5 ret
mov r3,#50h mov r4,#0ffh djnz r4,here1 djnz r5,here2 ret end
CIRCUIT DIAGRAM:
References
www.engineersgarrage.com
www.8051projects.com www.wikipedia.com