You are on page 1of 51

Gyan-Vihar University

Summer Training Report On Embedded System & Microcontroller-8051


(Submitted to SURESH GYAN VIHAR UNIVERSITY in fulfillment of requirement of degree of Bachelor of Technology In Electronics & Communication Engineering) Session (2008-12)
Submitted To: Mr. Rashid Hussain Head of Department Electronics & Communication
Page | 1

Submitted By: Name Harshit Jain Roll No. 2233 Enrollment No. SGUV081020440
Electronics & Communication Dept.

Gyan-Vihar University

Department of Electronics & Communication

This is to certify that the project entitled, Metro-Train Proto-Type, which is being submitted herewith for the award of B.Tech., is the result of the work completed by Mr. Harshit Jain (VII Semester) from Suresh Gyan-Vihar University at Dynamica India under the supervision of the project manager Mr. Manoj Kumar and the same has not been submitted elsewhere for the award of any degree. Date: Place: Jaipur

Head Department Of Electronics & Communication Engineering (Mr. Rashid Hussain)

Page | 2

Electronics & Communication Dept.

Gyan-Vihar University

List of Contents
Preface Acknowledgement
1. Profile of Company 1.1 About Dynamica 1.2 Dynamica Philosophy 1.3 Company Training Partner - Ducat India 1.4 Services 1.5 Solutions 2. Embedded System 2.1 Embedded System 2.2 Variety of Embedded System 2.3 User Interface 3. Microcontroller 3.1 Introduction 3.2 Definition of a Microcontroller 3.3 Pin Configuration 3.4 Reset Circuit
Page | 3

1 2 3 3 4 4 4 5 6 7 7 8 9 9 9 11 13
Electronics & Communication Dept.

Gyan-Vihar University

3.5 Ram Architecture 3.6 Microcontrollers v/s Microprocessors 3.7 Central Processing Unit 3.8 Bus 3.9 Input Output Unit 3.10 Serial Communication 3.11 Timer Unit 4. LCD Interfacing 4.1 Pin description 4.2 DDRAM - Display Data RAM 4.3 BF - Busy Flag 4.4 Instruction Register (IR) and Data Register (DR) 4.5 Commands and Instruction set 4.6 Sending Commands to LCD 5. DC Motor Interfacing 5.1 Push-pull four channel driver 5.2 Block Diagram 5.3 Features 6. Keyboard Interfacing
Page | 4

14 18 18 19 20 20 22 24 24 25 25 25 25 26 27 27 27 28 29
Electronics & Communication Dept.

Gyan-Vihar University

6.1nterfacing the key board with 8051 6.2 Scanning & Identifying the Key 6.3 Grounding Rows & Reading the Columns 7. Project Description 7.1 Introduction of Project 7.2 Circuit Diagram of Metro Train Prototype 7.3 Project Methodology 7.4 Procedure 7.5 General Working 8. Future Scope 9. References and Bibliography 10. Appendix: List of diagrams 11. Coding

29 29 30 32 32 33 34 35 35 36 37 38 39

Page | 5

Electronics & Communication Dept.

Gyan-Vihar University

Preface
This training report is all about the embedded systems and its application in various fields of real world. We are living in the Embedded World. We are surrounded with many embedded products and our daily life largely depends on the proper functioning of these 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 embedded products. Now we can agree to the fact that these embedded products have successfully invaded into our world. What is this Embedded System? Theoretically, an embedded controller is a combination of piece of microprocessor based hardware and the suitable software to undertake a specific task. I have made a Project based on Microcontroller that is a Prototype of Metro Train. This training report covers all about introduction to Embedded System, the microcontroller 8051 and project description. In this project I have implemented the Prototype of Metro Train that is describing a small application of microcontroller.

Page | 6

Electronics & Communication Dept.

Gyan-Vihar University

Acknowledgement
I would like to express my sincere gratitude to DYNAMICA INDIA for giving me an opportunity to undergo my Industrial Training for six weeks (45 days) as well as DUCAT for providing me the knowledge of Embedded System. I would also like to thank to all the technical experts, engineers and executives for explaining practical aspects of the theoretical knowledge. My greatest debt in creating this project goes to the technical experts Miss Priyanka Priyadarshani and Mr. Manoj Kumar. I am deeply indebted to my HOD Mr. Rashid Hussain Sir whose help, stimulating suggestions and encouragements was always with me. Thank you to Sir for encouraging me every step of the way.

Page | 7

Electronics & Communication Dept.

Gyan-Vihar University

1) Profile Of The Company-DYNAMICA INDIA


DYNAMICA Company works on solutions in the scope of e-commerce, web site development, software development on multiple platforms, multimedia presentation design, and internet marketing. One of the most perspective directions in our company specialization is development of solutions for mobile commerce (m-commerce). We develop WAP sites and PDA compatible sites which become more and more needed year by year.

1.1) About DYNAMICA


1. "Quality Matters" The main direction of our companies activity is the development of high quality and efficient managing of web sites, convenient from user point of view, fully functional from administrating position, meeting all quality standards of modern IT industry and Internet standards in particular. We provide our clients with truly flexible solutions. Convenient and reliable in utilizing products that finally give them a real advantage compared to companies not paying enough attention to the quality of IT products used in their business process. 2. "We choose the best for you" Our activity is built on the outsourcing basis, or in other words, we involve specialized experts who have extensive experience working with technologies which are planned for project implementation. At the moment more than 200 various specialists and developer teams from India are working for our company. Among them a bigger part belongs to programmers and web designers as well as specialists in Internet advertising and Internet marketing. 3. "We do help!" Our clients are companies of any level interested in specialized software products development, increase of presence in high tech communication sectors or releasing ecommerce projects. 4. "We work internationally" In spite of the fact that our main developer's center is located in Noida (INDIA) we offer services worldwide. Our CRM system allows us to keep in touch with our clients very closely.
Page | 8 Electronics & Communication Dept.

Gyan-Vihar University

1.2) Dynamica Philosophy in their own words


Apply the principle "Discovering Opportunity" by letting us bring the future closer to you, so that when major and unexpected changes occur you are ready for them, even welcoming them with a peaceful smile on your face.

1.3) Company Training Partner DUCAT INDIA


Ducat is a technology training partner, whose projects are focused on providing an extensible development platform and application frameworks for building software. Ducat provides extensible tools and frameworks that span the software development lifecycle, including support for modeling, language development environments for Java, .NET, ABAP/4, IBM Mainframe, AS/400, RTO-Linux, C/C++ and others, testing and performance, business intelligence, rich client applications and Embedded development. Resulting from the profound combination of DUCAT's training and development experience, and its customer relationship processes, Ducat INDIA offers a complete tailored and personalized framework for supporting its existing and future customers, be it locally or globally.

1.4) Services
At DYNAMICA, we offer you a myriad of services. Whatever be your requirement, we have a solution for you. You could be an IT company or a non-IT company; a large business house with a number of group companies or a small and medium scale enterprise (SME), we can cater to all your IT requirements. Through our services we help you to implement enterprise-wide technology advances that enhance your core processes. We aim to provide solutions to your business and technology needs in a manner that it adds value to your enterprise as well as adheres to a fixed-price and fixed-time frame. DYNAMICA brings together strategic and technological expertise, a flexible and costeffective global delivery model and rich domain experience to provide solutions that fit your needs.

We provide following services


1. Application Development and Maintenance 2. Enterprise Quality Services 3. Packaged Application Services 4. Product Engineering 5. Systems Integration

Page | 9

Electronics & Communication Dept.

Gyan-Vihar University

1.5) Solutions
What makes us the obvious choice as a information technology outsourcing consultant and provider, apart from our evident knowledge, expertise and sheer devotion to our work, is the fact that our solutions go beyond being a mere means to an end. We believe that any solution will be effective only when it perfectly complements existing business strategies, practices, structures and vision. Each project is unique in its requirements and our approach subsequently differs.

We specialize in 3 core areas:


1) Web Application development 2) Custom Application Development 3) Mobile Software Programming

The other areas we cater to are:


1) ERP Solutions 2) .NET/ASP Programming 3) Linux Programming 4) Java Programming 5) IBM Mainframe 6) C++ ,C 7) UNIX 8) TESTING 9) oracle 10) Embedded System

Page | 10

Electronics & Communication Dept.

Gyan-Vihar University

2) Embedded System
One of the first recognizably modern embedded systems was the Apollo Guidance Computer, developed by Charles Stark Draper at the MIT Instrumentation Laboratory. At the project's inception, the Apollo guidance computer was considered the riskiest item in the Apollo project as it employed the then newly developed monolithic integrated circuits to reduce the size and weight. An early mass-produced embedded system was the Autonetics D-17 guidance computer for the Minuteman missile, released in 1961. It was built from transistor logic and had a hard disk for main memory. When the Minuteman II went into production in 1966, the D-17 was replaced with a new computer that was the first high-volume use of integrated circuits. This program alone reduced prices on quad nand gate ICs from $1000/each to $3/each, permitting their use in commercial products. Since these early applications in the 1960s, embedded systems have come down in price and there has been a dramatic rise in processing power and functionality. The first microprocessor for example, the Intel 4004, was designed for calculators and other small systems but still required many external memory and support chips. In 1978 National Engineering Manufacturers Association released a "standard" for programmable microcontrollers, including almost any computer-based controllers, such as single board computers, numerical, and event-based controllers. As the cost of microprocessors and microcontrollers fell it became feasible to replace expensive knob-based analog components such as potentiometers and variable capacitors with up/down buttons or knobs read out by a microprocessor even in some consumer products. By the mid-1980s, most of the common previously external system components had been integrated into the same chip as the processor and this modern form of the microcontroller allowed an even more widespread use. The integration of microcontrollers has further increased the applications for which embedded systems are used into areas where traditionally a computer would not have been considered. A general purpose and comparatively low-cost microcontroller may often be programmed to fulfill the same role as a large number of separate components. Although in this context an embedded system is usually more complex than a traditional solution, most of the complexity is contained within the microcontroller itself. Very few additional components may be needed and most of the design effort is in the software. The intangible nature of software makes it much easier to prototype and test new revisions compared with the design and construction of a new circuit not using an embedded processor.

Page | 11

Electronics & Communication Dept.

Gyan-Vihar University

2.1) Embedded System


An embedded system is a computer system designed to do one or a few dedicated and/or specific functions often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs. Embedded systems control many devices in common use today. Embedded systems are controlled by one or more main processing cores that are typically either microcontrollers or digital signal processors(DSP).The key characteristic, however, is being dedicated to handle a particular task. Since the embedded system is dedicated to specific tasks, design engineers can optimize it to reduce the size and cost of the product and increase the reliability and performance. Some embedded systems are mass-produced, benefiting from economies of scale. Physically, embedded systems range from portable devices such as digital watches and MP3 players, to large stationary installations like traffic lights, factory controllers, or the systems controlling nuclear power plants. Complexity varies from low, with a single microcontroller chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or enclosure.

2.2) Variety of Embedded System


Embedded systems span all aspects of modern life and there are many examples of their use. Telecommunications systems employ numerous embedded systems from telephone switches for the network to mobile phones at the end-user. Computer networking uses dedicated routers and network bridges to route data. Consumer electronics include personal digital assistants (PDAs), mp3 players, mobile phones, videogame consoles, digital cameras, DVD players,GPS receivers, and printers. Many household appliances, such as microwave ovens, washing machines and dishwashers, are including embedded systems to provide flexibility, efficiency and features. Advanced HVAC systems use networked thermostats to more accurately and efficiently control temperature that can change by time of day and season. Home automation uses wired- and wireless-networking that can be used to control lights, climate, security, audio/visual, surveillance, etc., all of which use embedded devices for sensing and controlling. Transportation systems from flight to automobiles increasingly use embedded systems. New airplanes contain advanced avionics such as inertial guidance systems and GPS receivers that also have considerable safety requirements. Various electric motors brushless DC motors, induction motors and DC motors are using electric/electronic motor controllers.

Page | 12

Electronics & Communication Dept.

Gyan-Vihar University

Automobiles, electric vehicles, and hybrid vehicles are increasingly using embedded systems to maximize efficiency and reduce pollution. Other automotive safety systems include anti-lock braking system (ABS), Electronic Stability Control (ESC/ESP), traction control (TCS) and automatic four-wheel drive. Medical equipment is continuing to advance with more embedded systems for vital signs monitoring, electronic stethoscopes for amplifying sounds, and various medical imaging (PET, SPECT, CT, MRI) for non-invasive internal inspections. Embedded systems are especially suited for use in transportation, fire safety, safety and security, medical applications and life critical systems as these systems can be isolated from hacking and thus be more reliable. For fire safety, the systems can be designed to be have greater ability to handle higher temperatures and continue to operate. In dealing with security, the embedded systems can be self sufficient and be able to deal with cut electrical and communication systems.

2.3) User Interface


Embedded systems range from no user interface at all dedicated only to one task to complex graphical user interfaces that resemble modern computer desktop operating systems. Simple embedded devices use buttons, LEDs, graphic or character LCDs (for example popular HD44780 LCD) with a simple menu system. More sophisticated devices use graphical screen with touch sensing or screen-edge buttons provide flexibility while minimizing space used: the meaning of the buttons can change with the screen, and selection involves the natural behavior of pointing at what's desired. Handheld systems often have a screen with a "joystick button" for a pointing device. Some systems provide user interface remotely with the help of a serial (e.g. RS232, USB, IC, etc.) or network (e.g. Ethernet) connection. In spite of the potentially necessary proprietary client software and/or specialist cables that are needed, this approach usually gives a lot of advantages: extends the capabilities of embedded system, avoids the cost of a display, simplifies BSP, allows to build rich user interface on the PC. A good example of this is the combination of an embedded web server running on an embedded device (such as an IP camera) or a network routers. The user interface is displayed in a web browser on a PC connected to the device, therefore needing no bespoke software to be installed.

Page | 13

Electronics & Communication Dept.

Gyan-Vihar University

3) MICROCONTROLLERS
3.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 hundreds of 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.

3.2 Definition of a Microcontroller


Microcontroller, as the name suggests, are small controllers. They are like single chip computers that are often embedded into other systems to function as processing/controlling unit. For example, the remote control you are using probably has microcontrollers inside that do decoding and other controlling functions. They are also used in automobiles, washing machines, microwave ovens, toys ... etc, where automation is needed. The key features of microcontrollers include: High Integration of Functionality Microcontrollers sometimes are called single-chip computers because they have on-chip 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.

Page | 14

Electronics & Communication Dept.

Gyan-Vihar University

Most microcontrollers will also combine other devices such as:


A Timer module to allow the microcontroller to perform tasks for certain time periods. A serial I/O port to allow data to flow between the microcontroller and other devices such as a PC or another microcontroller. An ADC to allow the microcontroller to accept analogue input data for processing.

Figure 3.1: Showing a typical microcontroller device and its different subunits

Page | 15

Electronics & Communication Dept.

Gyan-Vihar University

3.3 PIN CONFIGURATION

Vcc

P1 P0

RESET RXD TXD INT0 INT1 T0 T1 RD WR XTAL1 XTAL2 GND P2 EA PSEN ALE

P3

figure 3.2 Pin configuration of Microcontroller

Page | 16

Electronics & Communication Dept.

Gyan-Vihar University

We have 4 ports in 8051 micro controller. They are port0, port1, port2, port3 which can be accessed as i/o ports. The pins of the micro controller are explained below.

Reset: It resets total 8051 micro controller. RXD: TXD: INT0: INT1: T0: T1: RD: WR: It receives data in serial communication. It transmits data in serial communication. External interrupt for timer 0. External interrupt for timer1 Timer0. Timer1. To read into external memory. To write into external memory.

XTAL1 & XTAL2: To connect the crystal oscillator. ALE: Address latch enable which is used to access the address locations from external memory. PSEN: memory. EA: External Access: 64 KB of ROM is the limit for external memory. Program store enable which is used for storing programming code into the external

Page | 17

Electronics & Communication Dept.

Gyan-Vihar University

3.4 RESET CIRCUIT

Figure 3.3 : Reset circuit of microcontroller

Capacitor is storing charge permanently until we use it. Crystal Oscillator is used to generate a carrier signal with stable frequency. With the help of this oscillator we will deduce the execution speed in terms of bytes/ sec.It generates 12 clock pulses /machine cycle. Capacitors provide charge for crystal oscillator. If we are not connecting any external memory to micro
Kl,kljljljlkjlk

controller, EA is connected to Vcc in case of 8051.

Page | 18

Electronics & Communication Dept.

Gyan-Vihar University

3.5 RAM Architecture

figure 3.4: Ram Architecture

The 8051 has a bank of 128 bytes of Internal RAM. This Internal RAM is found on-chip on the 8051 so it is the fastest RAM available, and it is also the most flexible in terms of reading, writing, and modifying its contents. Internal RAM is volatile, so when the 8051 is reset this memory is cleared. The 128 bytes of internal ram is subdivided as shown on the memory map. The first 8 bytes (00h - 07h) are "register bank 0". These alternative register banks are located in internal RAM in addresses 08h through 1Fh.Bit memory actually resides in internal RAM, from addresses 20h through 2Fh. The 80 bytes remaining of Internal RAM, from addresses 30h

Page | 19

Electronics & Communication Dept.

Gyan-Vihar University

through 7Fh, may be used by user variables that need to be accessed frequently or at high-speed. This area is also utilized by the microcontroller as a storage area for the operating stack.

Register Banks
The 8051 uses 8 "R" registers which are used in many of its instructions. These "R" registers are numbered from 0 through 7 (R0, R1, R2, R3, R4, R5, R6, and R7).These registers are generally used to assist in manipulating values and moving data from one memory location to another. The concept of register banks adds a great level of flexibility to the 8051.

Bit Memory
The 8051, being a communication oriented microcontroller, gives the user the ability to access a number of bit variables. These variables may be either 1 or 0. There are 128 bit variables available to the user, numbered 00h through 7Fh. The user may make use of these variables with commands such as SETB and CLR. It is important to note that Bit Memory is really a part of Internal RAM. In fact, the 128 bit variables occupy the 16 bytes of Internal RAM from 20h through 2Fh.

Special Function Register (SFR) Memory


Special Function Registers (SFRs) are areas of memory that control specific functionality of the 8051 processor. For example, four SFRs permit access to the 8051s 32 input/output lines. Another SFR allows a program to read or write to the 8051s serial port .SFR is a part of Internal Memory. This is not the case. When using this method of memory access (its called direct address), any instruction that has an address of 00h through 7Fh refers to an Internal RAM memory address; any instruction with an address of 80h through FFh refers to an SFR control register.

Page | 20

Electronics & Communication Dept.

Gyan-Vihar University

Registers
The Accumulator 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 "R" registers The "R" registers are a set of eight registers that are named R0, R1, etc. up to and including R7. These registers are used as auxiliary registers in many operations. 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. 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. 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. 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.

Page | 21

Electronics & Communication Dept.

Gyan-Vihar University

Addressing Modes
An "addressing mode" refers to how you are addressing a given memory location. The addressing modes are as follows, With an example of each: Immediate Addressing MOV A, #20h Direct Addressing MOV A, #30h Indirect Addressing MOV A, @R0 External Direct MOVX A, @DPTR Code Indirect MOVC A, @A+DPTR Each of these addressing modes provides important flexibility.

Interrupts
An interrupt is a special feature which allows the 8051 to provide the illusion of "multitasking," although in reality the 8051 is only doing one thing at a time. .

Timers
Timers are one of the categories of hardware time delays. Time delays are used to keep a system into halting System or sleepy mode. We have two timers- timer0, timer1.Hardware time delays are used to generate exact time delays.

Page | 22

Electronics & Communication Dept.

Gyan-Vihar University

3.6 Microcontrollers versus Microprocessors


Microcontroller differs from a microprocessor in many ways. First and the most important is its functionality. In order for a microprocessor to be used, other components such as memory, or components for receiving and sending data must be added to it. In short that means that microprocessor is the very heart of the computer. On the other hand, microcontroller is designed to be all of that in one. No other external components are needed for its application because all necessary peripherals are already built into it. Thus, we save the time and space needed to construct devices.

3.7 Central Processing Unit


Let add 3 more memory locations to a specific block that will have a built in capability to multiply, divide, subtract, and move its contents from one memory location onto another. The part we just added in is called "central processing unit" (CPU). Its memory locations are called registers.

Figure3.5: Simplified central processing unit with three registers

Registers are therefore memory locations whose role is to help with performing various mathematical operations or any other operations with data wherever data can be found. Look at the current situation. We have two independent entities (memory and CPU) which are interconnected, and thus any exchange of data is hindered, as well as its functionality. If, for example, we wish to add the contents of two memory locations and return the result again back to memory, we would need a connection between memory and CPU. Simply stated, we must have some "way" through data goes from one block to another.

Page | 23

Electronics & Communication Dept.

Gyan-Vihar University

3.8 Bus
That "way" is called "bus". Physically, it represents a group of 8, 16, or more wires. There are two types of buses: address and data bus. The first one consists of as many lines as the amount of memory we wish to address and the other one is as wide as data, in our case 8 bits or the connection line. First one serves to transmit address from CPU memory, and the second to connect all blocks inside the microcontroller.

Figure3.6: Showing connection between memory and central unit using buses

As far as functionality, the situation has improved, but a new problem has also appeared: we have a unit that's capable of working by itself, but which does not have any contact with the outside world, or with us! In order to remove this deficiency, let's add a block which contains several memory locations whose one end is connected to the data bus, and the other has connection with the output lines on the microcontroller which can be seen as pins on the electronic component.

Page | 24

Electronics & Communication Dept.

Gyan-Vihar University

3.9 Input-output unit


Those locations we've just added are called "ports". There are several types of ports: input, output or bidirectional ports. When working with ports, first of all it is necessary to choose which port we need to work with, and then to send data to, or take it from the port.

Figure3.7: Simplified input-output unit communicating with external world

When working with it the port acts like a memory location. Something is simply being written into or read from it, and it could be noticed on the pins of the microcontroller.

3.10 Serial Communication


Beside stated above we've added to the already existing unit the possibility of communication with an outside world. However, this way of communicating has its drawbacks. One of the basic drawbacks is the number of lines which need to be used in order to transfer data. What if it is being transferred to a distance of several kilometers? The number of lines times number of kilometers doesn't promise the economy of the project. It leaves us having to reduce the number of lines in such a way that we don't lessen its functionality. Suppose we are working with three lines only, and that one line is used for sending data, other for receiving, and the third one is used as a reference line for both the input and the output side. In order for this to work, we need to set the rules of exchange of data. These rules are called protocol. Protocol is therefore defined in advance so there wouldn't be any misunderstanding between the sides that are communicating with each other. For example, if one man is speaking in French, and the other in English, it is highly unlikely that they will quickly and effectively understand each other. Let's suppose we have the following protocol. The logical unit "1" is set up on the transmitting line
Page | 25 Electronics & Communication Dept.

Gyan-Vihar University

until transfer begins. Once the transfer starts, we lower the transmission line to logical "0" for a period of time (which we will designate as T), so the receiving side will know that it is receiving data, and so it will activate its mechanism for reception. Let's go back now to the transmission side and start putting logic zeros and ones onto the transmitter line in the order from a bit of the lowest value to a bit of the highest value. Let each bit stay on line for a time period which is equal to T, and in the end, or after the 8th bit, let us bring the logical unit "1" back on the line which will mark the end of the transmission of one data. The protocol we've just described is called in professional literature NRZ (Non-Return to Zero).

Figure3.8: Serial unit sending data through three lines only

As we have separate lines for receiving and sending, it is possible to receive and send data (info.) at the same time. So called full-duplex mode block which enables this way of communication is called a serial communication block. Unlike the parallel transmission, data moves here bit by bit, or in a series of bits what defines the term serial communication comes from. After the reception of data we need to read it from the receiving location and store it in memory as opposed to sending where the process is reversed. Data goes from memory through the bus to the sending location, and then to the receiving unit according to the protocol.

Page | 26

Electronics & Communication Dept.

Gyan-Vihar University

3.11 Timer unit


Since we have the serial communication explained, we can receive, send and process data.

Figure2.9: Timer unit generating signals in regular time intervals

However, in order to utilize it in industry we need a few additionally blocks. One of those is the timer block which is significant to us because it can give us information about time, duration, protocol etc. The basic unit of the timer is a free-run counter which is in fact a register whose numeric value increments by one in even intervals, so that by taking its value during periods T1 and T2 and on the basis of their difference we can determine how much time has elapsed. This is a very important part of the microcontroller whose understanding requires most of our time.

Figure2.10: Physical configuration of the interior of a microcontroller

Page | 27

Electronics & Communication Dept.

Gyan-Vihar University

Figure2.11: Microcontroller outline with basic elements and internal connections

For a real application, a microcontroller alone is not enough. Beside a microcontroller, we need a program that would be executed, and a few more elements which make up interface logic towards the elements of regulation (which will be discussed next).

Page | 28

Electronics & Communication Dept.

Gyan-Vihar University

4) LCD INTERFACING
4.1 Pin Configuration

GND

Vcc

16

15 4

80 C0

81 C1

82 83 C2 C 3 H ->A

84 C4

85 C5

86 C6

87 C7

88 C8

89 C9

8A CA

8B CB

8C CC

8D CD

8E CE

8F CF 5

10

11

12

13

14

figure : 16x2 LCD Pin configuration

3- >VARISTOR 4-> RS 5-> RW 6-> EN 7-14-> DATA LINE INPUTS


Page | 29 Electronics & Communication Dept.

Gyan-Vihar University

LCD stands for Liquid Crystal Display. The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 Line LCDs which have only 1 controller and support at most of 80 characters.

4.2 DDRAM - Display Data RAM


Display data RAM (DDRAM) stores display data represented in 8-bit character codes. Its extended capacity is 80 X 8 bits, or 80 characters. The area in display data RAM (DDRAM) that is not used for display can be used as general data RAM. So whatever you send on the DDRAM is actually displayed on the LCD.

4.3 BF - Busy Flag


Busy Flag is a status indicator flag for LCD. When we send a command or data to the LCD for processing, this flag is set (i.e. BF =1) and as soon as the instruction is executed successfully this flag is cleared (BF = 0). This is helpful in producing and exact amount of delay. For the LCD processing. To read Busy Flag, the condition RS = 0 and R/W = 1 must be met and The MSB of the LCD data bus (D7) act as busy flag. When BF = 1 means LCD is busy and will not accept next command or data and BF = 0 means LCD is ready for the next command or data to process.

4.4 Instruction Register (IR) and Data Register (DR)


There are two 8-bit registers controller Instruction and Data register. Instruction register corresponds to the register where you send commands to LCD e.g. LCD shift command, LCD clear, LCD address etc. and Data register is used for storing data which is to be displayed on LCD. When send the enable signal of the LCD is asserted, the data on the pins is latched in to the data register and data is then moved automatically to the DDRAM and hence is displayed on the LCD.

4.5 Commands and Instruction set


Only the instruction register (IR) and the data register (DR) of the LCD can be controlled by the MCU. Before starting the internal operation of the LCD, control information is temporarily stored into these registers to allow interfacing with various MCUs, which operate at different speeds, or various peripheral control devices. The internal operation of the LCD is determined by signals sent from the MCU.

Page | 30

Electronics & Communication Dept.

Gyan-Vihar University

4.6 Sending Commands to LCD


To send commands we simply need to select the command register. Everything is same as we have done in the initialization routine. But we will summarize the common steps and put them in a single subroutine. Following are the steps: Move data to LCD port Select command register Select write operation Send enable signal Wait for LCD to process the command

Page | 31

Electronics & Communication Dept.

Gyan-Vihar University

5) DC MOTOR INTERFACING
In this project the d.c motor interfacing consists of two motors .One motor is used to open & close the car door and the other is used to move the car forward. This interfacing is shown in fig. This uses L293D IC interfacing.

5.1 Push-Pull Four Channel Driver


Description
Output current to 1A or 600mA per channel respectively. Each channel is controlled by a TTL-compatible logic input and each pair of drivers (a The L293 and L293D are quad push-pull drivers capable of delivering full bridge) is equipped with an inhibit input which turns off all four transistors. A separate supply input is provided for the logic so that it may be run off a lower voltage to reduce dissipation. Additionally the L293D includes the output clamping diodes within the IC for complete interfacing with inductive loads. Both devices is available in 16-pin Batwing DIP packages. They are also available in Power S0IC and Hermetic DIL packages.

5.2 Block Diagram

Page | 32

Electronics & Communication Dept.

Gyan-Vihar University

5.3 FEATURES:
Output Current 1A Per Channel (600mA for L293D) Peak Output Current 2A Per Channel (1.2A for L293D) Inhibit Facility High Noise Immunity Separate Logic Supply Over-Temperature Protection

ABSOLUTE MAXIMUM RATINGS:


Collector Supply Voltage, VC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36V Logic Supply Voltage, VSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36V Input Voltage, VI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7V Inhibit Voltage, VINH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7V Peak Output Current (Non-Repetitive), lOUT (L293) . . . . . . . . . . . . . . . . . . . . . . . . . .. 2A lOUT (L293D) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 1.2A

Total Power Dissipation


At T ground-pins = 80C N Batwing pkg, (Note) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5W Storage and Junction Temperature, Tstg, TJ . . . . . . ... . . . .. . . . . . . -40 to +150C

Page | 33

Electronics & Communication Dept.

Gyan-Vihar University

6) Keyboard Interfacing
6.1 Interfacing the Keyboard to the 8051
At the lowest level, keyboards are organized in a matrix of row and columns. The CPU accesses both rows and column through ports; therefore, with two 8-bit ports, an 8*8 matrix of key can be connected to a microprocessor .When a key pressed, a row and column make a connect; otherwise there is no connection between row and column .In IBM PC keyboard, a single microcontroller (consisting of microprocessor, RAM and EPRROM and several ports all on a single chip) take care of software and hardware interfacing of keyboard. In such a system it is the function of programs stored in the EPROM of microcontroller to scan the keys continuously, identity which one has been activated, and present it to the motherboard. In this section we look at the mechanism by which the 8051 scans and identify the key.

6.2 Scanning and identifying the key


Figure shows a 4*4 matrix connected to two ports.

Figure 4*4 Matrix Keyboard

Page | 34

Electronics & Communication Dept.

Gyan-Vihar University

The rows are connected to an output port and the columns are connected to an input port and the columns are connected to an input port. If no key has been pressed, reading the input ports will yield 1s for all column since they are all connected to high (Vcc) If all the rows are grounded and a key pressed, one of the column will have 0 since the key pressed provides the path to ground. It is the function of the microcontroller to scan the keyboard continuously to detect and identify the key pressed.

6.3 Grounding Rows & Reading Columns


To detect a pressed key , the microcontroller grounds all rows by providing 0 to the output latch, and then it reads the columns. If the data read from the columns is D3-D0=1111, no key has been pressed and the process continues until a key press is detected. However, if one of the column bits has a zero, this means that a key press has occurred. For example, if D3D0=1101, this means that a key in the D1 column has been pressed. After a key press is detected, the microcontroller will go through the process of identifying the key. Starting with the top row, the microcontroller grounds it by providing a low to row D0 only; then it reads the columns. I f the data read is all1s, no key in that row is activated and the process is moved to the next row. It grounds the next row, reads the columns, and checks for any zero. This process continues until the row is identified. After identification of the row in which the key has been pressed, the next task is to find out which column the pressed key belongs to. This should be easy since the microcontroller knows at any time which row and column are being accessed. Assembly language program for detection and identification of key activation is given below. In this program, it is assumed that P1 and P2 are initialized as output and input, respectively. Program13.1 goes through the following four major stages: 1. To make sure that the preceding key has been released, 0s are output to all rows at once, and the columns are read and checked repeatedly until all the columns are high. When all columns are found to be high, the program waits for a short amount of time before it goes to the next stage of waiting for a key to be pressed. 2. To see if any key is pressed, the columns are scanned over and over in an infinite loop until one of them has a 0 on it. Remember that the output latches connected to rows still have their initial zeros (provided in stage 1), making them grounded. After the key press detection, it waits 20ms for the bounce and then scans the columns again. This serves two functions: (a) it ensures that the first key press detection was not an erroneous one due to spike noise, and(b) the 20ms delay prevents the same key press from being interpreted as a multiple key press. If after the 20-ms delay the key is still pressed, it goes to the next stage to detect which row it belongs to; otherwise, it goes back into the loop to detect a real key press.

Page | 35

Electronics & Communication Dept.

Gyan-Vihar University

3. To detect which row the key press belongs to, it grounds one row at a time, reading the columns each time. If it finds that all columns are high, this means that the key press cannot belong to that row; therefore, it grounds the next row and continues until it finds the row the key press belongs to. Upon finding the row that the key press belongs to, it sets up the starting address for the look-up table holding the scan codes (or the ASCII value) for that row and goes to the next stage to identify the key. 4. To identify the key press, it rotates the column bits, one bit at a time, into the carry flag and checks to see if it is low. Upon finding the zero, it pulls out the ASCII code for that key from the look-up table; Otherwise, it increments the pointer to point to the next element of the look-up table.

While the key press detection is standard for all keyboards, the process for determining which key is pressed varies. The look-up table method shown in program can be modified to work with any matrix up to 8*8.

Page | 36

Electronics & Communication Dept.

Gyan-Vihar University

7) Description of Project
7.1 Introduction
The Need
Delhi, the National Capital with a population of about 12 million is, perhaps, the only city of its size in the world, which depends almost entirely on buses on it sole mode of mass transport.bus services are inadequate and heavily over-crowded.. The result of extreme congestion on the road, ever slowing speeds, increasing accident rate, fuel wastage and environmental pollution. Delhi has now become the fourth most city in the world, with automobiles contributing more than two thirds of the total atmospheric pollution. Pollution related health problems are reaching disconcerting levels. Immediate steps are, therefore, needed to improve both the quality and availability of mass transport service. This is possible only if a rail-based mass transit system, which is nonpolluting, is introduced in the city without further delay.

Delhi MRTS Project


With a view to reducing the problems of Delhis commuter, the launching of an Integrated Multi Mode Mass Rapid Transport System for Delhi had long been under consideration. The first concrete step in this direction was, however, taken when a feasibility study for developing such a multi-modal MRTS system was commissioned by GNCTD (with support from GOI) in 1989 and completed by RITES in 1991.

My Prototype of metro train


I have made the prototype of Metro train using Microcontroller 89C51.The basic function of this project is given later. I have used a toy car to implementing it which has two DC motors. One is used for opening and closing the door and other is used for moving the car forward. The complete description of project is given below.

Page | 37

Electronics & Communication Dept.

Gyan-Vihar University

7.2 Circuit Diagram of Metro Train Prototype

Following figure shows the complete Metro Train Prototype

Figure 71: diagram of Metro Train Prototype

Page | 38

Electronics & Communication Dept.

Gyan-Vihar University

7.3 PROJECT METHODOLOGY


7.3(a) Components: Component Name
1. Microcontroller Section Microcontroller IC (AT89C51) with base Crystal Oscillator (11.0592 MHz) Capacitor (30pF) Capacitor (10F) Resistor (8.2K) LCD Connector 2. 3. 4. 5. 6. 7. 8. Buzzer LCD(16x2) Load Driver (L293D) with base A Car (toy-driven by a DC motor) General Purpose Card Single Core Connecting Wires Reset Switch (Push-on) 2 1 1 1 1 1 1 1 4 1

Quantity
1 1

7.3(b) Softwares used:


1. Keil Vision3. 2. Top-View Simulator

7.3(c) Equipments used:


1. Soldering iron, solder, flux. 2. Hex Blade

Page | 39

Electronics & Communication Dept.

Gyan-Vihar University

7.4 Procedure of building the Prototype of Metro Train

Step 1: Circuit diagram of the proposed system is designed and finalized.(Refer to Figure 6.1 ) Step 2: All the components and software platform to be used are selected which are also mentioned above. Step 3: All the hardware components are soldered on their respective printed circuit boards with the help of soldering ion, solder and flux according to the hardware schematic shown in the Figure Step 4: Code/program of the proposed system is developed using assembly language with the help of software platform (Keil u vision3).The coding could be seen in section Step 5: The hex code of the program being created by the software platform is burnt into the flash code memory of our microcontroller IC 89C51. Step 6: Testing is done at various levels to finalize the appropriate program for the most proper working of the system

7.5 General Working


When the power is turned on a message (welcome to metro) is displayed on LCD. Then a message Current station is Kishan Ganj is displayed and door is opened also. A buzzer is also turned on when door opens. After some delay the door is closed and car is started to move forward. A message current station is Kishan Ganj is displayed also on LCD. After some delay a message next station is Pratap nagar is displayed. After some time the train stops and a message current station is Pratap nagar is displayed. This process is continued for five stations. In the end a message End of line is displayed on LCD. This whole process is repeated until we turned off the power supply.

Page | 40

Electronics & Communication Dept.

Gyan-Vihar University

8) FUTURE SCOPE

The new cars would feature the following:


Stainless steel exteriors instead of an aluminium car body. Thinner, stronger stainless steel seats that offer more leg room. Each car would have 64 cloth-padded, taller seats with seat-back grab handles. A total end to carpeting. Floors would be rubberized. Interactive maps on LCD screens that would also likely display advertisements Automated station announcements. So no more "Judishuwary Square". Security cameras on all rail cars.

The 7000 series won't be ready for service for at least five years. The latest models are in the 6000 series, which were introduced last year.

Page | 41

Electronics & Communication Dept.

Gyan-Vihar University

9) REFRENCES AND BIBLOGRAPHY


THE 8051 MICROCONTROLLER AND EMBEDDED SYSTEM by Muhammad Ali Mazidi , Janice Gillispie Mazidi, Rolin D. Mckinlay. The 8051 MICROCONTROLLER by K. J. Ayala. "Advanced Microprocessors and Microcontrollers" by B.P. Singh & Renu Singh. "Let Us C" by Yashwant Kanitkar. "Data Structure through C" by Yashwant Kanitkar.

NET LINKS:
1. www.8051projects.net 2. www.atmel.com 3. www.electronicsforyou.com 4. www.encyclopedia.com 5. www.wikipedia.com

Page | 42

Electronics & Communication Dept.

Gyan-Vihar University

10) Appendix
List of Essential Diagrams: 1. Figure 3.1: showing a typical microcontroller device and its different subunits 2. Figure 3.2: Pin configuration of Microcontroller 3. Figure 3.3: Reset circuit of Microcontroller 4. Figure 3.4: Ram Architecture 5. Figure 3.5: Simplified central processing unit with three register 6. Figure 3.6: Showing connection between memory and central unit using buses 7. Figure 3.7: Simplified input-output unit communicating with external world 8. Figure 3.8: Serial unit sending data through three lines 9. Figure 3.9: Timer unit generating signals in regular time intervals 10 .Figure 3.10 : Physical configuration of the interior of A Microcontroller 11 .Figure 3.11: Microcontroller outline with basic elements And internal connections 12 .Figure 4.1: 16x2 LCD pin configuration 13 .Figure 5.1: Block diagram of load driver L293D 14 .Figure 6.1: 4*4 Matrix keyboard 15 .Figure 7.1: Circuit diagram of Metro train prototype

10 11 13 14 18

19 20 21 22 22 23 24 27 29 33

Page | 43

Electronics & Communication Dept.

Gyan-Vihar University

11) Coding METRO TRAIN PROTO-TYPE


$mod51 lcdport equ p0 rs equ p3.2 en equ p3.3 ;rw equ p3.1 org 00h mov p0,#00h mov p2,#00h mov p3,#0ffh welcome: acall initialise1 ;lcd initialise mov dptr,#330h ;welcome to metro mov r7,#16 acall display acall delay station1: acall initialise1 mov dptr,#197h ;current station mov r7,#15 acall display acall delay acall initialise2 mov r7,#12 mov dptr,#183h ;noida sec-15

Page | 44

Electronics & Communication Dept.

Gyan-Vihar University

acall display acall train station2: acall initialise1 acall next acall initialise2 mov dptr,#229h ;noida sec-16 mov r7,#12 acall display acall train station3: acall initialise1 acall next acall initialise2 mov dptr,#243h ;new ashok nagar mov r7,#15 acall display acall train station4: acall initialise1 acall next acall initialise2 mov dptr,#260h ;mayur vihar ext. mov r7,#16 acall display acall train staion5: acall initialise1
Page | 45 Electronics & Communication Dept.

Gyan-Vihar University

acall next acall initialise2 mov dptr,#289h ;akshardham mov r7,#10 acall display acall train station6: acall initialise1 acall next acall initialise2 mov dptr,#300h ;rajiv chowk mov r7,#11 acall display acall train ljmp last delay: mov r1,#225 l0: mov r2,#223 l2: djnz r2,l2 djnz r1,l0 ret next: mov dptr,#215h ;next station mov r7,#12 acall display ret
Page | 46 Electronics & Communication Dept.

Gyan-Vihar University

train: mov dptr,#275h mov r7,#9 acall initialise1 acall display clr p3.4;door n train working clr p3.5 clr p3.6 clr p3.7 mov p1,#0fh acall delay_1sec acall delay_1sec acall delay_1sec mov dptr,#315h mov r7,#10 acall initialise1 acall display setb p3.7 setb p3.4 setb p3.5 setb p3.6 acall delay_1sec mov p2,#05h acall delay_1sec
Page | 47

;move for 5 sec


Electronics & Communication Dept.

Gyan-Vihar University

acall delay_1sec acall delay_1sec acall delay_1sec acall delay_1sec mov p2,#00h acall delay_1sec acall delay_1sec ret initialise1: mov lcdport,#38h ;initiate the lcd in5*7 matrix acall cmd acall delay mov lcdport,#01h ;clear the display acall cmd acall delay mov lcdport,#0eh ;cursor blinking acall cmd acall delay mov lcdport,#80h ;cursor at fst line fst postn acall cmd acall delay ret initialise2: mov lcdport,#38h acall cmd
Page | 48 Electronics & Communication Dept.

Gyan-Vihar University

acall delay mov lcdport,#0eh acall cmd acall delay mov lcdport,#0c0h acall cmd acall delay ret display: clr a movc a,@a+dptr mov lcdport,a acall read inc dptr djnz r7,display ret cmd: clr rs setb en acall delay clr en ret read:

Page | 49

Electronics & Communication Dept.

Gyan-Vihar University

setb rs setb en acall delay clr en ret delay_1sec: mov r5,#14 mov tmod,#10h rpt: mov th1,#00h mov tl1,#00h clr tf1 setb tr1 chk: jnb tf1,chk clr tr1 clr tf1 djnz r5,rpt ret org 183h db 'noida sec-15' org 197h db 'current station' org 215h db 'next station' org 229h
Page | 50 Electronics & Communication Dept.

Gyan-Vihar University

db 'noida sec-16' org 243h db 'new ashok nagar' org 260h db 'mayur vihar ext.' org 275h db 'door open' org 289h db 'akshardham' org 300h db 'rajiv chowk' org 315h db 'door close' org 330h db 'welcome to metro' last: end

Page | 51

Electronics & Communication Dept.

You might also like