Professional Documents
Culture Documents
SUBMITTED AS A PART OF SIX WEEKS INSTITUTIONAL TRAINING DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGG.
HARWINDER SINGH
90510414068
DEPARTMENT OF ECE
ACKNOWLEDGEMENT
I, HARWINDER SINGH Student of NORTH WEST INSTITUTE OF ENGINEERING & TECNOLOGY majoring in ELECTRONICS & COMMUNICATIONS ENGINEERING (5th semester) express my heartfelt thanks to our Training & Placement Officers for providing us their valuable guidance & sharp vision to undertake this six months industrial training. Training in an institute like CDAC which is fuelled by the individuals with so much zest & energy, teaming up to form a formidable force, was in itself a true learning experience which is going to help us immensely in our career. There is no substitute to Teamwork, this is one of the many lessons I learnt during our training in CDAC. I would like to thank and express my gratitude towards the personalities who have helped me to undertake and complete this project. First and foremost I express my gratitude towards institute faculty. The technical expert and development engineers for their support during my training. They provided me valuable guidance and technical skill in completing this course and without which this training would not have been possible. I would also like to acknowledge my teachers who have given me the basic concepts of Course. Thank you to all for encouraging me every step of the way. I am deeply indebted to my HOD ER.VIKAS ARORA and to coordinator whose help, stimulating suggestions and encouragements were always with me.
HARWINDER SINGH
90510414068
DEPARTMENT OF ECE
CERTIFICATE
This is to certify that the work presented in the report
MICROCONTROLLERS:ARCHITECTURE,PROGRAMMING AND INTERFACING is a complete record of the work done during the period from 6th June, 2011 to 15th July 2011 at CENTRE FOR DEVELOPMENT OF ADVANCED COMPUTING(CDAC), Mohali by Harwinder Singh, with university roll no:90510414068. The project work is authentic record of my work and is carried under the supervision and guidance of institute teachers. The matter presented in the report has not been submitted elsewhere, wholly or in part, for the award of any other degree or diploma.
HARWINDER SINGH
90510414068
DEPARTMENT OF ECE
TABLE OF CONTENTS
TITLE: 1 ARCHITECTURE 1.1 Introduction
1.2 Microcontroller
PAGE NO:
6-7 8
8
1.3 Microcontroller V/S microprocessor 1.4 Features of 8051 microcontroller 1.5 Block diagram of microcontroller 1.6 Pin configuration of 8051 1.7 Pin description of 8051 1.8 Diagram of microcontroller 1.9 Special function registers 1.10 Memory 1.10A internal memory 1.10B External memory 2 PROGRAMMING 2.1 Addressing modes 2.2 Types of addressing modes
20 20-22
HARWINDER SINGH
90510414068
DEPARTMENT OF ECE
22-30
3 INTERFACING
3.1 keyboard interfacing 3.2 seven segment display 3.3 LCD interfacing 31-34 35-37 37-40
LIST OF FIGURES: Block Diagram of Microcontroller Pin Configuration Of 8051 Internal RAM Structure On Chip Memory Working On file With Simulator Lead Per Key Keyboard X-Y Matrix keyboard Coaded Keyboard Keyboard Configuration For Getkey And Inkey Common Cathode Configuration Of SSD Interfacing Of seven Segment Display Diagrams Of Interfacing Of LCD 10 11 14 19 22-30 31 32 33 34 36 37 38
HARWINDER SINGH
90510414068
DEPARTMENT OF ECE
1. ARCHITECTURE
1.1 INTRODUCTION
Circumstances that we find ourselves in today in the field of microcontrollers had their beginnings in the development of technology of integrated circuits. This development has made it possible to store thousands of transistors into one chip. That was a prerequisite for production of microprocessors, and the first computers were made by adding external peripherals such as memory, input-output lines, timers and other. Further increasing of the volume of the package resulted in creation of integrated circuits. These integrated circuits contained both processor and peripherals. That is how the first chip containing a microcomputer, or what would later be known as a microcontroller came about. An embedded computer is a computer that is a component of a larger system; it helps implement the system functionality. Embedded computers exist in automobiles, airplanes, home appliances, military vehicles & equipments, medical devices, robotic, mobile communication system etc. Sophisticated embedded computers have been used in products and systems for over twenty years. Embedded computing includes several aspects: methodology, architectures, and applications which is practiced in conducting research. Methodology is important because the prime goal is to be able to reliably, predictably develop new systems. Embedded computers is used to make a wide variety of systems, therefore methodology of designing an embedded system that enable assessment of a system requirements, develop an architecture, and implement the embedded system is very important. Architecture is used here in a broad sense: both software and hardware. Early decisions can make or break a design. It is important to get the structure of the software and hardware right at the architectural stage in order to avoid expensive problems later in the design process. This
HARWINDER SINGH
90510414068
DEPARTMENT OF ECE
generally means jointly considering the effects of architectural decisions on both the hardware and software sides of the implementation. Applications are the motivation for embedded computing. It is important to take application characteristics into account during the design of an embedded system, and also important to understand at least one application area well in order to do the best research in embedded computing.
In summary Embedded Computing research cluster involve in enhancing knowledge and creating technologies in hardware & software design techniques through a combination of related fundamental and applied research projects. So in nutshell, an embedded systerm is the relating of hardware part wiyh the software or programming portion .Embedded systems are designed to perform dedicated tasks.It basically has main components like microcontroller or a microprocessor. A microcontroller is a programmable logic and integrated circuit which can be used to do a number of tasks. It is possible to just control about anything with the program written by the user. Whereas a microcontroller differs from a microprocessor, which is a general purpose chip , used to create a multifunction computer or a device and requires multiple c hips to handle various tasks. A microcontroller is meant to be mire self contained and independant, and functions as a tiny dedicated computer.
Objective:
The objective is to explore the details of embedded computing aspects which are the Methodology, Architecture and Application. This will enable cutting edge technology development in hardware and software through embedded system applications development.
HARWINDER SINGH
90510414068
DEPARTMENT OF ECE
1.2WHAT IS A MICROCONTROLLER?
As the name suggests, microcontroller means small computers. Microcontrollers are used for embedded system i.e. system on a chip. They are like single chip computers that are often embedded into other systems to function as controlling unit. So a microcontroller can be called as an on chip computer. In an embedded system, the microprocessor or a microcontroller is assigned the duty of completing only one job at a time. So unlike a PC, it cannot do multi-tasking because it consists of a RAM memory and an operating system that loads the application software into the RAM, so that CPU can execute it. In an embedded system, only one applications software is burned onto the ROM. Examples of embedded system using microcontrollers are cell phones, camera, printers, video games etc.
microcontroller is an on chip true computer. It is optimized for specific applications. It vconsists of all the features of a microprocessor as well as the features required to build a complete computer.
HARWINDER SINGH
90510414068
DEPARTMENT OF ECE
The key features of microcontrollers include: High Integration of Functionality Microcontrollers sometimes are called single-chip computers because they have onchip memory and I/O circuitry and other circuitries that enable them to function as small standalone computers without other supporting circuitry. Field Programmability, Flexibility Microcontrollers often use EEPROM or EPROM as their storage device to allow field programmability so they are flexible to use. Once the program is tested to be correct then large quantities of microcontrollers can be programmed to be used in embedded systems. Easy to Use
Assembly language is often used in microcontrollers and since they usually follow RISC architecture, the instruction set is small. The development package of microcontrollers often includes an assembler, a simulator, a programmer to "burn" the chip and a demonstration board. Some packages include a high level language compiler such as a C compiler and more sophisticated libraries.
HARWINDER SINGH
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
10
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
11
90510414068
DEPARTMENT OF ECE
8051 is a 40 pin IC. It has 4 ports, port 0, port1, port2, port3 which can be assessed as I/O ports. Its pin description is given as:
Vcc: It is the supply voltage. GND: Ground Port 0: Port v0 is an 8 bit bidirectional I/O port. When 1s are written to port 0 pins, the
pins can be used as high impedance inputs. Port 0 also receives the code bytes during flash programming program verification.
Port 1: Port 1 is an 8 bit bidirectional I/O port with internal pull ups. When 1s are
written to port 1 pins are pulled high by the internal pull-ups and can be used as inputs. As inputs, port 1 pins that are externally being pulled low will source pull ups because of internal pull ups.
Port 2: Port 2 is an 8 bit bidirectional I/O port with internal pull ups. When 1s are
written to port 2 pins are pulled high by the internal pull-ups and can be used as inputs. As inputs, port 2 pins that are externally being pulled low will source pull ups because of internal pull ups.
Port 3: Port 2 is an 8 bit bidirectional I/O port with internal pull ups. Port 3 also serves
various other functions which are as follows:
P3.0: RXD (serial input port) P3.1: TXD (serial output port)
HARWINDER SINGH
12
90510414068
DEPARTMENT OF ECE P3.2: INT0 (external interrupt) P3.3: INT1 ((external interrupt) P3.4: T0 (Timer/Counter 0 external input) P3.5: T1 (Timer/Counter1external input) P3.6: WR (external data memory write strobe) P3.7: RD (external data memory read strobe) Port 3 also receives some control signals for flash programming and program verifications.
RST (reset input): a high on this input pin for two machine cycles, while the oscillator is
running resets the device. ALE/PROG: Address latch enable which is used to access the address locations from external memory. PSEN: Program store enable which is used for storing programming code into the external memory.
XTAL1: input to inverting oscillator amplifier and input to internal clock operating
circuit.
XTAL2: output from the inverting oscillator amplifier .a crystal may be connected
between XTAL1 and XTAL2 pins.
ARCHITECTURE OF 8051:
It consists of the following: 1. Eight bit registers A (accumulator) and Register B. 2. Arithmetic and Logic operations. 3. 16 bit Program counter (PC). 4. 8 bit Program Status Word (PSW). 5. 8 bit Stack Pointer (SP). HARWINDER SINGH 13 90510414068
DEPARTMENT OF ECE
6. 128 byte Internal RAM and $KB Internal ROM. 7. Four 8 bit ports: Port 0, Port1, Port 2, Port 3. 8. Two 16 bit Timer/Counter, serial port and interrupt control. 9. Control Registers. 10. On chip Oscillators.
HARWINDER SINGH
14
90510414068
DEPARTMENT OF ECE
1.9 SPECIAL FUNCTION REGISTERS: ACCUMULATOR (ACC): ACC is an 8 bit register. It is most versatile and holds source
operand and receives the result of arithmetic operations including addition, subtraction,
HARWINDER SINGH
15
90510414068
DEPARTMENT OF ECE
multiplication, division and Boolean bit manipulations. It is also used for data transfer between 8051 and external memory. Several functions like rotate, swap etc apply specifically on accumulator.
B REGISTER: The B register is used with A register for multiplication and division
operations. For other operations, it is used as a scratch pad register.
ARITHMETIC AND LOGIC UNIT: The ALU can perform arithmetic and logic
operations on eight bit data. It can perform operations like addition, subtraction, multiplication, division and logical operations like AND, OR, EX-OR, complement, rotate etc.
PROGRAM STATUS WORD (PSW) AND FLAGS: Many instructions affect the status
flags. In order to address these flags conveniently they are grouped as Program Status Word.
Figure 1.4: Program Status Word Register So it contains several status bits that reflect the current status of CPU. PSW resides in SFR space. It contains the carry bit, the auxiliary carry (for BCD operations), the two register bank select bits, the overflow flag, a Parity bit, and two user definable status flags. The carry bit, other than serving the function of carry bit, it also serves as the accumulator for a number of Boolean operations. The bits RS0 and RS1 are used to select one of the four register banks. The parity bit reflects the number of 1s in the accumulator: P=1 if the accumulator contains an odd number of 1s, and P=0 if the accumulator contains an even number of 1s. Thus the number of 1s in the accumulator plus P is even number. The two bits in the PSW are uncommitted and may be used as general purpose status flags.
DEPARTMENT OF ECE
the power supply is switched ON, the PC resets to 0000H. In case of instructions like jump, call, interrupt the contents of PC may change. PC is just a register. It does not have any internal address.
DATA POINTER: is a 16 bit register. It is used hold the address of a data in the memory. The
DPTR can be assessed separately as lower eight bits (DPL) and higher eight bits (DPH) . It can be used as a 16 bit data register or two independent 8 bit registers. The DPTR does not have a single internal address instead DPL and DPH are assigned a separate address.
STACK AND STACK POINTER: The stack pointer registers Is 8 bits wide. It is
incremented before the data is stored during PUSH and CALL executions. While the stack may reside anywhere in the ON CHIP RAM, the stack pointer is initialized to 07H after a reset. This causes the stack to begin at the location 08H.
HARWINDER SINGH
17
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
18
90510414068
DEPARTMENT OF ECE
I.
Four Register Banks Of 8 Bytes Each: There are four register banks which are
numbered from 0 to 3. Each bank is made up of eight registers R0 to R7. In total 32 bytes or 32 working g registers from address 00H to1FH organized as four register banks. For selecting a register bank two bits RS0 and RS1 are provided in PSW. If any of the register banks is not selected, then the programmer can use the area from 00H to 1FH as simple scratch pad RAM or general purpose RAM.
II.
III.
General Purpose Ram Area: This RAM is also called as SCRATCH PAD RAM. It
lies above the bit addressable area and has address 30H to 7FH. This RAM area can be used as data RAM. The memory in this area is byte addressable. The programmer may declare stack in this area provided sufficient numbers of bytes are available.
INTERNAL ROM:
The microcontroller has separate memory for the program and data. Both these memories have same address ranges. The internal ROM is used to store the internal program code. It occupies the address space ranging from 0000H to 0FFFH. For the addresses higher than 0FFFH, the 8051 will automatically fetch the code bytes from an external memory.
HARWINDER SINGH
19
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
20
90510414068
DEPARTMENT OF ECE
Now there are four types of addressing modes, which are as follows; 1. Immediate addressing mode 2. Register addressing mode 3. Direct addressing mode 4. Indirect addressing mode
1. IMMEDIATE ADDRESSING MODE: This method is the simplest method to get the
data. In this addressing mode, the source operand is a constant rather than a variable. As the data is a part of instruction, it is immediately available. The # sign indicates that the data is immediate operand. EXAMPLE:
HARWINDER SINGH
21
90510414068
DEPARTMENT OF ECE
3. DIRECT ADDRESSING MODE: Although the entire 128 bytes of RAM can be
accessed using direct addressing mode, it is often used to access the RAM location 30-7FH. EXAMPLE: MOV R0, 40H MOV 56H, A MOV A, 4
HARWINDER SINGH
22
90510414068
DEPARTMENT OF ECE
which holds the actual address that will be used in data move operation. The address may be 8 bit or 16 bit address. In this addressing mode, only R0 and R1 registers are used. The @ sign indicates the register acts as a pointer to the memory location. EXAMPLE: MOV R0, #05H MOV @R0, #30H 2.3Now the stepwise execution is shown in figures as below:
HARWINDER SINGH
23
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
24
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
25
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
26
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
27
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
28
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
29
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
30
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
31
90510414068
DEPARTMENT OF ECE
3 INTERFACING:
Interfacing means connecting the hardware devices like keyboard, seven segment display and relays etc to see if how they work on connection with the microcontroller. Some interfacings are as follows: 1. Keyboard interfacing 2. Seven segment display 3. LCD interfacing 3.1KEYBOARDS INTERFACING: It is a human oriented input peripheral. It is used to input data or program into the microcomputer. It consists of push button type switches. When a key is pressed, the microcontroller identifies key depression and then performs the appropriate operation. HUMAN FACTORS: The keyboard application program must guard against the following possibilities: More than one key pressed Key pressed and held Rapid key pressed All these conditions can be addressed by hardware as well as software which is more cost effective also. Hypothetical keyboard writing configurations are shown as below:
HARWINDER SINGH
32
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
33
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
34
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
35
90510414068
DEPARTMENT OF ECE
Seven segment display is of two types; Common cathode Common anode COMMON CATHODE: The cathodes of all LEDs are given as a common pin. In this case, the anode is connected to the port pins. This method requires port pins to source large current. But 8051 cannot source current beyond 2mA. COMMON ANODE: The anodes of all the LEDs are given as common pin. In this case the cathode is connected to the port pins. Hence port pins have to sink current of 20mA Hence we use common anode SSD and connect 8051 in this configuration.
HARWINDER SINGH
36
90510414068
DEPARTMENT OF ECE
FIGURE 19:COMMON CATHODE SEGMENT CIRCUIT Program For Seven Segment Display: org 00h Mov a, #00H Back: mov P0, a Inc a Acall delay Cjne a, #09h, back Sjmp back Delay: mov r0, #eff H Mov r1, #066H Mov r2, #0ffH Here: djnz r1, here Here 2: djnz r2, here2 Djnz r0, here1 Ret End
HARWINDER SINGH
37
90510414068
DEPARTMENT OF ECE
FIGURE 20:SEVEN SEGMENT DISPLAY CIRCUIT USED FOR SEVEN SEGMENT PROGRAM
3.3LCD INTERFACING: LCD displays are widely used because of low current consumption as compared to SSD. Also LCD can be used to display any character as it uses 5*7 dot matrix to display.
HARWINDER SINGH
38
90510414068
DEPARTMENT OF ECE
HARWINDER SINGH
39
90510414068
DEPARTMENT OF ECE Program To Display CDAC on LCD Org 00H Mov a,#34H Acall commwrt Acall datawrt Acall delay Mov a, #C Acall commwrt Acall datawrt Acall delay Mov a, #D Acall commwrt Acall datawrt Acall delay Mov a, #A Acall commwrt Acall datawrt Acall delay Mov a, #c Commwrt: mov P1, a Clr P2.0 Clr P2.1 Clr P2.2 Setb P2.1
HARWINDER SINGH
40
90510414068
DEPARTMENT OF ECE
Clr p2.2 Ret Datawrt: mov P1,a Clr P2.0 Clr P2.1 Setb P2.1 Clr p2.2 Ret Delay: mov a,82H
HARWINDER SINGH
41
90510414068