Project Report on MICROCONTROLLER BASED TRAINER KIT Developed at MCBS Pvt. Ltd.

B-138/139, GIDC Electronics Estate, Sector-25, Gandhinagar. Submitted By Shah Vrushank M. Rajan Rushvi T. May-June 2007 B.E. Sem VIII (Electronics and Communication)

Submitted To, Department of Electronics and Communication, Govt. Engineering College. Modasa-383 315.

Project Report on MICROCONTROLLER BASED TRAINER KIT AT MCBS Pvt. Ltd. B-138/139, GIDC Electronics Estate, Sector-25, Gandhinagar.

Internal Guide Name MR. C. R. PAREKH

Developed By Mr. Vrushank Shah Ms. Rushvi Rajan

May-June 2007 B.E. Sem VIII (Electronics and Communication) Submitted To, Department of Electronics and Communication, Govt. Engineering College. Modasa-383 315. Government Engineering College,

Modasa, (GUJARAT – INDIA) – 383 315. Date: C E R T I F I C A T E T O W H O M S O E V E R I T M A Y C O N C E R N /05/07

This is to certify that Mr. Vrushank M. Shah and Ms. Rushvi Rajan students of B.E. Semester VIII (Electronics and communication ) has completed their one full semester project training on Microcontroller Based Trainer Kit satisfactorily in partial fulfillment of requirement of Bachelor Of Engineering in stream Electronics and Communication from Hemchandracharya North Gujarat University, Patan in the year 2007.

(MR. C. R. PAREKH) Internal Project Guide GEC, MODASA Date: /05/07 PREFACE

(MR. H.O.D (EC Dept.) GEC, MODASA Date: /05/07

)

An engineer is a person who applies the knowledge of science for the welfare of society. Teaching technical studies can’t be perfect without project work. Hence, the project work is great valuable for the engineering students. This report contains the design and development of Microcontroller based Trainer Kit. This Trainer kit is designed with the purpose that engineering community become aware of, and enamored with, the 8-bit microcontroller such as 89c51. The main part of Trainer kit called its heart is 89c51 Microcontroller from 8051 family. These Trainer kit includes different types display devices such as LED, 7-segment and LCD. It has some basic converter circuits such ADC and DAC. It can work as a Digital Clock as we have interfaced Real Time Clock (RTC), along with EEPROM i.e., Electrically erasable and programmable ROM. This trainer kit is capable of sensing temperature of environment and also capable to communicate with computers using RS-232. It has some input device such as Keyboard. Thus, using this trainer kit, the design and interfacing of microcontroller-based embedded system can be explored. Some of its features make this trainer kit a robust application at industrial level. However, it is meant for use primarily by those who work in the area of electronic design and assembly language programming. No matter what the interest level, I hope all groups will enjoy using this trainer kit. For the people who are completely unaware about the use of microcontroller, a product manual is also provided in addition to this project report.

***********

ACKNOWLEDGEMENT I take this opportunity to humbly express my thankfulness to all those concerned with my project.. I am grateful to Shri G. C Jain (Managing Director) of Modern Communication and Broadcast Systems Pvt Ltd for giving me a chance to work in an esteemed organization under his administration. I am also grateful to the Head of the Department Mr. Ashok Vaghela for giving me guidance for my project in the esteemed organization like MCBS Pvt. Ltd. I express very sincere thanks to Mr. Ashok Vaghela for providing me an opportunity to work on such an interesting project, without whose help I could not have completed it satisfactorily. His invaluable guidance has proved to be a key to my success in overcoming challenges that I faced during the course of the project. I am also obliged to Mr. Chandresh Parekh for their guidance in my project in the organization who was right there from the first lap to the finishing line. Finally, I am thankful to all those people who have helped me directly or indirectly in completing this project successfully. With regards Mr. Vrushank Shah. Ms. Rushvi Rajan

Contents at a Glance

Company details Institute details Project details References and project timeline chart

Company details

1 . MCBS Profile. Modern Communication & Broadcast Systems Pvt. Ltd, popularly known as “MCBS” is headquartered at Ahmedabad, Gujarat, India. Instituted in 1985 by professionals and technocrats having engineering experience of more than 20 years from India’s pioneering space technology institutions, MCBS is in the service of Communication & Broadcast industry since past 20 years. MCBS has a wide experience in accomplishing projects in various communication areas like satcom, broadcasting, digital video compression based satellite uplink and downlink solutions, internet over cable and broadband networks, ground satellite network, distance and remote education, tele-conferencing and teletalking, microwave links. MCBS has collaborated with world leaders like Scientific Atlanta (S-A), Newtec, International Data Casting and others to provide state-ofthe-art solutions in various fields of communication and IT. KEY AREAS OF ACTIVITIES OF MCBS ARE AS FOLLOWS: Manufacturing of Communication & Broadcast equipments. Turnkey projects and systems integration. Marketing of HI-tech communication projects. Technical support services to its principal companies. MCBS STRENGTHS MCBS is an ISO 9001:2000 registered company. MCBS is a professionally managed company to provide products & services in the HI-tech areas of communication field. MCBS has a track record of 20 years of successful operations providing excellent products & services to all its customers. MCBS has highly skilled manpower to take care of its operations including

system design, consultancy and turnkey projects. MCBS has more than 150 field staff for technical support services and has more than 15 project offices throughout India. DEPARTMENTS IN MCBS There are different departments in MCBS. alphabetical order: They are mentioned below as per their

Broadcasting Router Switcher CCTV Modulation R & D Receiver CATV Mechanical Workshop Marketing Department Direct to Home System. COLLABORATION WITH FOREIGN COMPANIES BARCO N.V. (BELGIUM) TADIRAN SCOPUS (ISRAEL) TANDBERG TWL, ASA (NORWAY) DIVICOM IWC (USA) CHAPARRAL COMM. (USA) MOLYNX LTD. (UK) CSO INTERNATIONAL (BELGIUM) PROFLINE B.V. (HOLLAND) ASSOCIATED COMPANIES OF MCBS There are other companies associated with MCBS which also work in the same field of communication. Their entire products are either for MCBS or for same applications. These companies are as following: New Communication Technology Pvt. Ltd. (NCT) Space Communication Technology (SCT)

National Institute of Communication and Information Technology (NICIT)

2. Introducing NICIT The National Institute of Communication and Information Technology (NICIT) has been established with an objective to create a knowledge base in communication and its various applications. The Institute will be one of its kinds, with emphasis on hands-on-training to support theoretical aspects of Communication & IT. The Institute will cater to the industry demands hitherto unexplored and thus will benefit manufacturing units, entrepreneurs, system designers, operators, service maintenance engineers, Institutes/bodies in the field of Communication & Information technology etc. etc. Users even at the grassroots level will also be able to benefit from NICIT programme. The Institute is being affiliated with world's renowned companies, as well as education and research institutions, universities, government bodies, and professionals and intellectuals associated with communication and IT industry, for several years. The Institute possesses state-of-the-art infrastructure and training facilities. The Institute will nurture, preserve and improve upon the existing knowledge base of various users in this field. In a broad sense, the Institute will strengthen the communication infrastructure in India to enhance the benefits of IT. NICIT has a technical tie-up with Modern Communication and Broadcast Systems Ltd. (MCBS), a pioneering and leading Indian company in the field of Communication, Broadcasting and Information Technology. NICIT has a wide range of programmes and activities. This has been designed to provide adequate Knowledge and Skills to those who attend the course and undergo the training to face the challenges in the global world. NICIT PROGRAMMES AND ACTIVITIES ADDITIONAL FOCUS Inplant training & project work Personality development. Foundation courses & specialized courses Communication skills

Higher level training Training modules for technicians Diploma courses E-learning technology & tools Consultancy services NICIT PROGRAMME BENEFITS

Presentation skills Importance of English Language Hands-on PC and Internet Career guidance Preparation for Interview

Practical project work and inplant training are of vital importance in the advanced technology areas as most colleges and institutes do not have facilities to meet practical training needs. More than 2000 students have already benefited by our “Training Programmes & Projects” and are employed with various organizations of repute. Projects are based on advanced technology areas of ICT industry namely IT, Infocomm, Infotainment, Info media and Info education. Projects and training are based on latest subjects of technology and these are need-based for Indian industry, thereby providing immediate job and career opportunities. Special attention is given to develop student’s skills in required fields keeping in view the employment potential in various areas. NICIT has a data bank of organizations (India & abroad) to provide job opportunities and placement to students. Training modules have been designed for various levels starting from lower level (H.S.S. & I.T.I) to higher level (B.E. & M.E.) Covering basic understanding & awareness of technology, operation & maintenance, in-depth academic & practical knowledge. These modules are based on various curricula of diploma / degree & post graduate courses. NICIT also organizes Seminar / Courses on various subjects/ topics on the current ICT & related fields. ***********

Institute details

1. Introduction: Government Engineering College, Modasa was established in 1984 under the Directorate of Technical Education, Gujarat State, and Gandhinagar in North Gujarat region with a view of strengthening the industrial development in the region. The region consists of industrially potential areas of Panchmahal, Sabarkantha, Banaskantha, Mehsana and Patan district of Gujarat. The college is affiliated to Hemchandracharya North Gujarat University, Patan. It is also recognized by an apex body in technical education, All India Council for Technical Education (AICTE), New Delhi. The college is now entering in its 18th year and 15 batches have passed out up till now. Our students are well accepted in different fields i.e. Industries, Academic and for Higher studies within and outside the country. Each Department has well established laboratories, computer center and has well qualified staff. The institution is one of the centers for conducting a TECH-SAT programme run by Gujarat Council on Science & Technology (GUJCOST), Gandhinagar, with a concept of providing technical education through satellite. Students as well as faculty members taking full advantage of expertise available within and outside the state in different discipline. 2. Course and Study criteria: Courses Offered by the Institute: The college is presently offering Undergraduate courses leading to Bachelor of Engineering in the disciplines of Civil, Mechanical, Electrical, Electronics and Communication, Information Technology and Computer Engineering. Sr. No. Name of the Course Intake 1 Civil Engineering 30 2 Mechanical Engineering 120 3 Electrical Engineering 60 4 Electronics & Communication Engineering 60 5 Information Technology 60 6 Computer Engineering 60 Total 390 About Study and Discipline : All students will be required to get enrolled with Hemchandracharya North Gujarat University by filling prescribed form available in Students' Section. In addition, students passed from the Central Board and coming from the other states shall have to obtain eligibility certificate from Hemchandracharya North Gujarat University. The students will be required to abide by the rules and regulations along with instructions issued by the college authorities from the time to time. The students are instructed to act and behavior in a way to help and promote the name of the college in the field of academic, sports and cultural activities in the society such that one be proud of being a student of this college. Course Structure :

The undergraduate course offered the Institute in a various disciplines are of four duration and divided as : B.E. B.E. B.E. B.E. 3. 1st II III IV : : : Annual pattern consisting of two terms Sem. III & Sem. IV : Sem. V & Sem. VI Sem. VII & Sem. VIII

POSTAL ADDRESS:

Principal, Government Engineering College, Shamlaji Road, Modasa-383315, Dist.-Sabarkantha Phone: (02774) 242633 Website: www.gecmodasa.org

***********

Project Details Section-1 Embedded systems 1.1. Defination. 1.2. Features. 1.3. Characteristics. 1.4. Developing Embedded System. 1.5. Advantages and Disadvantages. 1.6. Applications. Section-2 The 8051 Microcontroller 2.1. Introduction. 2.2. Overview of 89c51 Microcontroller. 2.3. Timers and Counters. 2.4. Criteria for choosing 89c51 Microcontroller. Section-3 Trainer Kit 3.1. Introduction. 3.2 Block Diagram. 3.3. Circuit Diagram. 3.4 Parts of Trainer Kit. 3.5 Possible Designs. Section-4 4.2. Light emitting diode 4.1. Introduction. Advantages of LEDs.

4.3. 4.4.

Hardware Criteria. Flowchart of Program. Matrix Keyboard 5.1. Introduction. 5.2. Keyboard Configurations. 5.3. Scanning and Identifying Key press. 5.4. Hardware Criteria. 5.5. Flowchart of program.

Section-5

Section-6 Seven-segment Display 6.1. Introduction. 6.2. Hardware Criteria. 6.2.1 Non-Multiplexed Segment. 6.2.2 Multiplexed segment. 6.3. Flowchart of program . Section-7 External ROM 7.1. Introduction. 7.2. Advantages. 7.3. Pin Description of 24c02 EEPROM chip. 7.4. Device operation based on I2C protocol. 7.5 Hardware Criteria. 7.6 Flowchart of program. Section-8 Liquid crystal Display 8.1 LCD Features. 8.2 LCD Pin Descriptions. 8.3 LCD Timing waveform. 1. Read Timing waveform. 2. Write Timing waveform. 8.4 Hardware Connections. 8.5 Flowchart of program. Section-9 Real time clock 9.1. Introduction. 9.2. Features of DS1307 RTC chip. 9.3. Pin Descriptions. 9.4. Operation based on I2c protocol. 9.5. Hardware Criteria. 9.6. Flowchart of program. Section-10 10.3. 10.4. 10.5. Digital-Analog converter 10.1. Introduction. 10.2. Pin description. Operation of DAC. Hardware Criteria. Flowchart of program.

Section-11 Timer operation using 555 IC 11.1. Introduction. 11.2. Pin description. 11.3. Timing waveform. 11.4. Calculations. Section-12 Analog-Digital converter 12.1 ADC general overview. 12.2. ADC0808 pin descriptions.

12.3. Timing waveforms. 12.4. Hardware Criteria 12.5. Flowchart of program Section-13 Sensors 13.1. Introduction. 13.2. General description of LM35 sensor. 13.3. LM35 pin descriptions. 13.4. Hardware connections. Section-14 8255 14.1. 8255 features. 14.2. Mode selection of 8255. 14.3. Interfacing 8255 with 89c51. Section-15 Serial Communication 15.1. Difference between Serial and parallel 15.2. Basics of Serial communication 15.3. Hardware connections 15.4. Flowchart of program. Section-16 Testing and Troubleshooting communication

SECTION-1 EMBEDDED SYSTEMS

1.1 DEFINATION Embedded system is in almost every electronic device that are designed today. There is software hidden away inside our watches, microwaves, VCRs, cellular telephones, and pagers; the military uses embedded software to guide smart

missiles and detect enemy aircraft; communications satellites, space probes, and modern medicine would be nearly impossible without it. Of course, someone has to write all that software, and there are thousands of computer scientists, embedded engineers, and other professionals who actually do. Microprocessors and Microcontrollers are widely used in such embedded system products. Embedded systems are extremely important branch of modern digital technology. Each embedded system is unique and highly customized to the application at hand. In General, Embedded system can be defined as a system that has software embedded into hardware. As a result, embedded systems programming is a widely varying field that can take years to master. The main basics that includes in embedded programming are either Assembly programming or it may be high-level Languages such as C, C++ or JAVA. Basically embedded systems are the part of a large system but it need not be a computer. An embedded system is a special-purpose computer controlled electro-mechanical system in which the computer is completely encapsulated by the device it controls. An embedded system has specific requirements and performs pre-defined tasks, unlike a general-purpose personal computer. An embedded system is a computercontrolled system. The core of any embedded system is a microprocessor/microcontroller, programmed to perform a few tasks (often just one task). This is to be compared to other computer systems with general purpose hardware and externally loaded software. Embedded systems are often designed for mass production.

1.2 Features of Embedded Systems There are certain key features of embedded systems that differentiate them from other systems in the world. They have been discussed below: • Software The software used by embedded systems is called firmware and is stored in Read Only Memory or ROM or a Flash memory chip. Such software is efficient enough to work with the limited amount of hardware resources available. Typically, such software does not use a keyboard or if it does, it is small. There is very little RAM provided to such software. • User interfaces There are various types of user interfaces used in embedded systems. Some systems do not have any user interface at all. Devices such as PDAs provide interactive and complete user interfaces. Other devices, such as budget mobile phones have small screens that display only two colors and provide very limited (but enough) functionality. Some other systems have character-only screens such as that in digital railway timetables at stations. • CPU Platform Embedded systems use various CPU platforms or architectures that include ARM, X86, PowerPC, and PIC etc. embedded systems tend to use specifically purchased CPUs that are added to the embedded system which itself is put on a chip, that is, an integrated circuit (IC) specially designed for it. • Tools Embedded system designers use software ranging from compilers and assemblers to debuggers and emulators to develop software for embedded systems. These are usually scaled-down versions of their full software versions. • Start-up Embedded systems the world over begin with what is called the start-up process. At this point, a self-test is conducted by the system where the hardware,

peripherals, power supply etc. are tested for being in good condition. These tests are usually very short (usually, no more than 10 seconds) and determine the health of the system overall. 1.3 Characteristics of Embedded system Application specificSystem designed for a given application is known a prior before the system design begins and system flexibility is important for upgrades, design reuse which are usually achieved through reprogramming. Digital signal processing in ESSignals are represented as digitally as sequence samples. DSP processing occurs in system like averaging, filtering, device controls, encoding, decoding etc. Reactivity in Embedded SystemHaving increasingly higher performance with constraints which are important part of system functionality in building embedded computing system. Real-time application of Embedded systemA real time system consists of tasks under deadline constraints. It consist of two types- Hard real-time and Soft real-time. Hard Real time systems- In these systems the task must complete by specified deadlines e.g. - flight control. Soft Real time systems- in these system task executions may go beyond specific deadlines e.g. – connection establishment, updates etc. Power, cost & reliability are often important attributes that influence design of Embedded systems. 1.4 Developing Embedded System

Developing software and hardware for microcontroller based Embedded systems involves the use of a range of tools that can include editors, assemblers, compilers, debuggers, simulators, emulators and Flash/OTP programmers. To the newcomer to microcontroller development it is often not clear how all of these different components play together in the development cycle and what differences there are for example between Trainer kits, emulators and simulator. Figure shows a typical microcontroller software development cycle with some of the software and hardware components involved:

The basic operation that are involved in above microcontroller development cycle are: 1. 2. 3. Writing Microcontroller Code. Translating the Code. Debugging the code.

1. Writing microcontroller code : Software Code for a microcontroller is written in a programming language of choice (often Assembler or C). This source code is written with a standard ASCII text editor and saved as an ASCII text file. Programming in assembler involves learning a microcontroller's specific instruction set (assembler mnemonics), but results in the most compact and fastest code. A higher level language like C is for the most part independent of a microcontroller's specific architecture, but still requires some controller specific extensions of the standard language to be able to control all of a chip's peripherals and functionality. The penalty for more portable code and faster program development is a larger code size (20%...40% compared to assembler). 2. Translating the code: Next the source code needs to be translated into instructions the microcontroller can actually execute. A microcontrollers instruction set is represented by "op codes". Op codes are a unique sequence of bits ("0" and "1") that are decoded by the controller's instruction decode logic and then executed. Instead of writing opcodes in bits, they are commonly represented as hexadecimal numbers, whereby one hex number represents 4 bits within a byte, so it takes two hex numbers to represent 8 bits or 1 byte. For that reason a microcontroller's firmware in machine readable form is also called Hex-Code and the file that stores that code Hex-File. Assemblers, Compilers, Linkers and Librarians Assemblers or (C-) Compilers translate the human readable source code into "hex code" that represents the machine instructions (op codes). To support modular code and reusable libraries of code, most assemblers and compilers today come with Linkers and Librarians. Linkers, link code modules saved in different files together into a single final program. At the same time they take care of a chip's memory allocation by assigning each instruction to a microcontroller memory addresses in such a way that different modules do not overlap. Librarians help you to manage, organize and revision control a library of reusable code modules. Once the ASCII source code text file has been assembled (with an Assembler) or compiled (with a Compiler) and the files have been linked (with the Linker), the output results in a number of files that can be used for debugging the software and programming the actual microcontroller's memory. 3. Debugging the Code A debugger is a piece of software running on the PC, which has to be tightly integrated with the emulator that you use to validate your code. For that reason all emulator manufacturers ship their own debugger software with their tools, but also compiler manufacturers frequently include debuggers, which work with certain emulators, into their development suites. A Debugger allows you to download your code to the emulator's memory and then control all of the functions of the emulator from a PC. Common debugging features include the capability to examine and modify the microcontroller's on-chip registers, data- and program-memory; pausing or stopping program executing at defined program locations by setting breakpoints; single-stepping (execute one instruction at a time) through the code; and looking at a history of executed code (trace). So far we've talked about several different pieces of software: Text Editor, Assembler or Compiler, Linkers, Librarians and Debugger. You can easily imagine that it can become quite a time-consuming challenge to alternate back and forth between all of these programs during the debugging process (discover a bug, edit the source code, compile it again, link it again, download the modified code to the emulator, etc.). This is where an integrated development environment (IDE) comes in. An Integrated Development Environment puts all of the previously discussed

software components under one common unified user interface, so that it becomes possible to make a code change and get the modified code loaded into the emulator with a few mouse clicks, instead of dozens. A good IDE allows you for example to click on a syntax error message produced by the compiler and have the source code with the highlighted offending instruction pop up for editing in the text editor. One click of a button and the modified code gets retranslated, linked and downloaded to the emulator. An IDE allows you to store the configuration settings for a project - like compiler switches, or what flavor of chip to emulate - so you can easily recreate a project later on. Some IDEs are flexible enough to allow you to incorporate different choices of third party tools (like compilers and debuggers), others only work with a manufacturer's own tool chain. Debugging Tools When it comes to debugging your code and testing your application there are several different tools you can utilize that differ greatly in terms of development time spend and debugging features available. In this section we take a look at simulators Simulators try to model the behavior of the complete microcontroller in software. Some simulators go even a step further and include the whole system (simulation of peripherals outside of the microcontroller). No matter how fast your PC, there is no simulator on the market that can actually simulate a microcontroller's behavior in real-time. Simulating external events can become a time-consuming exercise, as you have to manually create "stimulus" files that tell the simulator what external waveforms to expect on which microcontroller pin. A simulator can also not talk to your target system, so functions that rely on external components are difficult to verify. For that reason simulators are best suited to test algorithms that run completely within the microcontroller (like a math routine for example). They are the perfect tool to complement expensive emulators for large development teams, where buying an emulator for each developer is financially not feasible. For our case we have used a simulator called “TOPVIEW”. Figure shows you the procedure that is involved in loading a program into the Targeted hardware system that is designed on basis of embedded technology. 1.5 Advantages & disadvantages ADVANTAGES: 1. One of the advantages of an embedded system is to decrease power consumption and space. 2. All embedded systems that are based on microcontroller have low power consumption in addition to some form of I/O, COM port and ROM all on a single chip. DISADVANTAGES: 1. Higher Hardware/Software development overhead. 2. Design, compilers, debuggers may result in delayed time to market.

1.6 APPLICATIONS Consumer electronics- e.g., cameras, camcorders etc. Consumer products, e.g., washers, microwave ovens. Automobiles (anti-lock braking, engine control). Industrial process controllers & avionics/defense applications Computer/Communication products, e.g., printers, FAX machines.

Emerging multimedia applications & consumer electronics e.g.,cellular phones, personal digital assistants, videoconferencing servers, interactive game boxes, TV set-top boxes. ********

SECTION-2 THE 8051 MICROCONTROLLER

2.1 Introduction This section begins with a discussion of the role and importance of Microcontroller in everyday life. Microcontrollers are not well known to the general public, or to many in the technical community, as are the glamorous microprocessor. However we are very well aware that “something” is responsible for all of the smart VCRs, clock radios, video games, Telephones, TVs, automobiles, Mobile phones, camcorder, security systems, instrumentation, printers and a myriad of other articles that are intelligent and “programmable”. These all things are due to a smart “Microcontroller”. Microcontrollers are widely used devices in embedded system. An embedded system product using Microcontroller has one and only one task. In such systems there is a only one application software that is typically burned into ROM. One such system is Our 89c51 Microcontroller based Trainer kit in which controller is its heart. For our trainer Kit, we have chosen 89c51 microcontroller which is an 8-bit microcontroller from the family of 8051 controllers. 2.2 OVERVIEW OF 89c51 Microcontroller

89c51 is introduced by Intel corporation is an 8-bit microcontroller. This

microcontroller has 128 bytes of RAM, 4K of on-chip ROM, two timers, one serial port, and four ports of 8-bits each all on a single chip. 89c51 is basically Flash ROM version of 8051 family. 89c51 is basically a 40 pin Dual-in-package. Block diagram of 89c51 is as shown in figure, which shows the microcontroller Hardware. The main features of 89c51 Hardware can be labeled as below: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. It has 8-bit CPU with registers A (the accumulator) and B. Sixteen-bit program counter (PC) and data pointer (DPTR). Eight-bit program status word (PSW). Eight-bit stack pointer (SP). Internal ROM of 0 to 4K. Internal RAM of 128 bytes. 32 I/0 pins arranged as four 8-bit ports: P0-P3 Two 16-bit Timer/Counters: T0 and T1 Full duplex serial data receiver/transmitter: SBUF Control registers: TCON, TMOD, SCON, PCON, IP, and IE. Two external and three internal interrupt sources. Oscillator and Clock circuits.

A pinout of the 89c51 packaged in a 40 pin DIP is as shown in figure:

Pin descriptions: 1. VSS (pin-20) Ground= 0 V reference 2. VCC (pin-40) This is the power supply voltage for normal, idle and power-down modes. 3. P.0-P0.7 (pin-39 to pin 32 i.e., port 0)

Port 0 is an open-drain, bidirectional I/O port. Pins of Port 0 on which there is a high logic will floats and can be used as an high impedance inputs. Port 0 is also the multiplexed low-order address and data bus during accesses to external program and data memory, In this application it uses strong internal pull-ups for emitting 1’s.

4.

P1.0-P1.7 (pin-1 to pin 8 i.e., port 1)

Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. Port 1 pins that have 1s written to them are pulled high by the internal pull-ups and can be used as inputs. As inputs, port 1 pins that are externally pulled low will source current because of the internal pull-ups. 5. P2.0-p2.7 (pin-21 to pin-28 i.e., port 2)

Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. Port 2 pins that have 1s written to them 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 current because of the internal pull-ups. Port 2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that uses 16-bit addresses (MOVX @DPTR). In this application, it uses strong internal pull-ups when emitting 1s. During accesses to external data memory that use 8-bit addresses (MOV @Ri), port 2 emits the contents of the P2 special function register. 6. P3.0-p3.7 (pin-10 to pin-17 i.e., port 3)

Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. Port 3 pins that have 1s written to them are pulled high by the internal pull-ups and can be used as inputs. As inputs, port 3 pins that are externally being pulled low will source current because of the pull-ups. Port 3 also serves the special features of the 89C51, as listed below: RxD (P3.0): Serial input port. TxD (P3.1): Serial output port. INT0 (P3.2): External interrupt. INT1 (P3.3): External interrupt. T0 (P3.4): Timer 0 external input. T1 (P3.5): Timer 1 external input. WR (P3.6): External data memory write strobe. RD (P3.7): External data memory read strobe. 6. RESET (pin-9)

A high on this pin for two machine cycles while the oscillator is running, resets the device. An internal diffused resistor to VSS permits a power-on reset using only an external capacitor to VCC 7. ALE (pin-30)

Output pulse for latching the low byte of the address during an Access to external memory. In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator frequency, and can be used for external timing or clocking. Note that one ALE pulse is skipped during each access to external data memory. ALE can be disabled by setting SFR auxiliary.0. With this bit set, ALE will be active only during a MOVX instruction. 8. PSEN (pin-29)

The read strobe to external program memory. When executing code from the external

program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to external data memory. PSEN is not activated during fetches from internal program memory. 9. EA/VPP (pin-31)

EA must be externally held low to enable the device to fetch code from external program memory locations 0000H to the maximum internal memory boundary. If EA is held high, the device executes from internal program memory unless the program counter contains an address greater than 0FFFH for 4 k devices, 1FFFH for 8 k devices, 3FFFH for 16 k devices, and 7FFFH for 32 k devices. The value on the EA pin is latched when RST is released and any subsequent changes have no effect. This pin also receives the 5V/12V programming supply voltage (VPP) during FLASH programming.

10.

XTAL1 and XTAL2 (pin-18 and pin-19)

Crystal 1: Input to the inverting oscillator amplifier and input to the internal clock generator circuits. Crystal 2: Output from the inverting oscillator amplifier. OSCILLATOR CHARACTERISTICS: XTAL1 and XTAL2 are the input and output, respectively, of an Inverting amplifier. The pins can be configured for use a an On-chip oscillator. To drive the device from an external clock source, XTAL1 should be driven while XTAL2 is left unconnected. There are no requirements on the duty cycle of the external clock signal, because the input to the internal clock circuitry is through a divide-bytwo flip-flop. However, minimum and maximum high and low times specified in the data sheet must be observed. RESET: A reset is accomplished by holding the RST pin high for at least two machine cycles (24 oscillator periods), while the oscillator is running.To insure a good power-on reset, the RST pin must be high long enough to allow the oscillator time to start up (normally a few milliseconds) plus two machine cycles. At power-on, the voltage on VCC and RST must come up at the same time for a proper start-up. Ports 1, 2, and 3 will asynchronously be driven to their reset condition when a voltage above VIH1 (min.) is applied to RST. The value on the EA pin is latched when RST is deasserted and has no further effect. Accumulator: The A (Accumulator) is the versatile of the two CPU registers and is used for many operations, including addition, subtraction, division, integer multiplication and Boolean bit manipulations. The A register is also used for data transfers between the 8051 and any external memory.. B Register: The B register is used during multiply and divide operations. For other instructions it can be treated as another scratch pad register.

Program Status Word The PSW register contains program status information as detailed in Table below: The PSW consists of math flags, user program flag F0, and the register bank select bits that identify which of the four general register banks is currently in use by the program.

Stack Pointer The Stack Pointer register is 8 bits wide. It is incremented before data is stored during PUSH and CALL executions. While the stack may reside anywhere in on-chip RAM, the Stack Pointer is initialized to 07H after a reset. This causes the stack to begin at locations 08H. Data Pointer The Data Pointer (DPTR) consists of a high byte (DPH) and a low byte (DPL). Its intended function is to hold a 16-bit address. It may be manipulated as a 16-bit register or as two independent 8-bit registers. Serial Data Buffer The Serial Buffer is actually two separate registers, a transmit buffer and a receive buffer. When data is moved to SBUF, it goes to the transmit buffer and is held for serial transmission. (Moving a byte to SBUF is what initiates the transmission.) When data is moved from SBUF, it comes from the receive buffer. Timer Registers Register pairs (TH0, TL0), and (TH1, TL1) are the 16-bit Counting registers for Timer/Counters 0 and 1, respectively. Control Register Special Function Registers IP, IE, TMOD, TCON, SCON, and PCON contain control and status bits for the interrupt system, the Timer/Counters, and the serial port. They are described in later sections.

2.3

TIMERS AND COUNTERS : Timer 0 and Timer 1

The “Timer” or “Counter” function is selected by control bits C/T in the Special Function Register TMOD. These two Timer/Counters have four operating

modes, which are selected by bit-pairs (M1, M0). In TMOD. Modes 0, 1, and 2 are the same for both Timers/Counters. Mode 3 is different. The four operating modes are described in the following text: Mode 0: Timer, which is an 8-bit Counter with a divide-by-32 prescaler. Figure shows the Mode 0 operation as it applies to Timer 1. In this mode, the Timer register is configured as a 13-bit register. As the count rolls over from all 1s to all 0s, it sets the Timer interrupt flag TF1. The counted input is enabled to the Timer when TR1 = 1 and either GATE = 0 or INT1 = 1. (Setting GATE = 1 allows the Timer to be controlled by Putting either Timer into Mode 0 makes it look like an 8048 external input INT1, to facilitate pulse width measurements). TR1 is a control bit in the Special Function Register TCON (Figure 3). GATE is in TMOD. The 13-bit register consists of all 8 bits of TH1 and the lower 5 bits of TL1. The upper 3 bits of TL1 are indeterminate and should be ignored. Setting the run flag (TR1) does not clear the registers. Mode 0 operation is the same for the Timer 0 as for Timer 1. Substitute TR0, TF0, and INT0 for the corresponding Timer 1 signals in Figure 2. There are two different GATE bits, one for Timer 1 (TMOD.7) and one for Timer 0 (TMOD.3). Mode 1: Mode 1 is the same as Mode 0, except that the Timer register is being run with all 16 bits. Mode 2: Mode 2 configures the Timer register as an 8-bit Counter (TL1) with automatic reload, as shown in Figure 4. Overflow from TL1 not only sets TF1, but also reloads TL1 with the contents of TH1, which is preset by software. The reload leaves TH1 unchanged. Mode 2 operation is the same for Timer/Counter 0. Mode 3: Timer 1 in Mode 3 simply holds its count. The effect is the same as setting TR1 = 0. Timer 0 in Mode 3 establishes TL0 and TH0 as two separate counters. The logic for Mode 3 on Timer 0 is shown in Figure 5. TL0 uses the Timer 0 control bits: C/T, GATE, TR0, and TF0, as well as the INT0 pin. TH0 is locked into a timer function (counting machine cycles) and takes over the use of TR1 and TF1 from Timer 1. Thus, TH0 now controls the “Timer 1” interrupt. Mode 3 is provided for applications requiring an extra 8-bit timer on the counter. With Timer 0 in Mode 3, an 80C51 can look like it has three Timer/Counters. When Timer 0 is in Mode 3, Timer 1 can be turned on and off by switching it out of and into its own Mode 3, or can still be used by the serial port as a baud rate generator, or in fact, in any application not requiring an interrupt. TCON and TMOD are the two registers used for setting the above modes. The format of these registers are as shown in figure: TMOD is dedicated solely to the timers and can be considered to be two duplicate 4-bit registers, each of which controls the action of one of the timers. TCON has control bits and flags for the timers in the upper nibble, and control bits and flags for the external interrupts in the lower nibble. Figure shows the bit assignments for TMOD and TCON.

2.4 Criteria for choosing 89c51 Microcontroller 1. The first and foremost criterion in choosing a microcontroller is that it must meet the task at hand efficiently and cost effectively. In our project we have chosen an 8-bit microcontroller which can handle the computing needs of the task most effectively. 2. The highest speed this microcontroller can support is 12MHZ 3. To fulfill our requirements in terms of space, assembling, we have chosen the 40-pin DIP. 4. To support the memory requirement we have chosen it as it includes 4K ROM and 128byte RAM. 5. As there are 32 I/O pins and 2 timers, it supports our input-output requirement greatly. 6. We have used the battery power product like an RTC the power consumption is critical for it. 7. In choosing this controller we have considered the availability of an assembler, debugger, simulator etc. 8. The ready availability in needed quantities both now and in the future. currently, of the leading 8-bit microcontrollers , the 8051 family has the largest number of diversified suppliers.

*******

SECTION-3 TRAINER KIT OVERVIEW

3.1. INTRODUCTION The trainer kit is a microcontroller based Embedded system through which students can understand different types of interfacings such as LEDs, 7-segment, keyboard, ADC, DAC, Sensors, EEPROM, RTC, LCD, 8255 etc. using these kit one can easily understands the hardware and software details of above mentioned devices. We have use all fundamental devices, knowledge of them enable the user to easily switch on to other complex and advance technology. Our project also includes some industrial applications like ‘Digital Clock’, ‘ Temperature Monitoring System’ , ‘Communication System’ etc. The simple design of our project can be easily extended into other application such as Access Control system, Digital Function Generator, Temperature monitoring and controlling kit, General purpose sensor kit, Graphical LCD Display etc. 3.2. FEATURES OF TRAINER KIT 1. Following are some feature which make our Trainer Kit unique. Simple Design:

We have designed our Trainer Kit in such a manner that all its modules works independently as well as in combination with other modules. We have provided various pin connectors so that the connections can be made as per User’s requirement. We have designed PCBs of various modules and then combined them to give the Hardware an aesthetic appearance. As various modules are independent, the troubleshooting become easier. 2. User Friendly:

We have provided a User’s Manual for operating Trainer kit. This manual will help user to understand each section thoroughly. The manual enables the user to understand hardware connections and Troubleshooting. As we have provided various pin connectors the user can easily connect as per manual description. As we have include some very simple interfacings such as 1 LEDs, 4 LEDs etc., the user who are new to the system can easily access and move further to keyboard, sevensegment, RTC and so on. To reduce the connections complexity, we have used 8255 PPI. So we could keep some of the connections as permanent one. For observing waveforms user can easily connect to the CRO. 3. Flexibility:

Our simple trainer kit design make the system portable. We have interfaced some display devices such as LCDs and 7-segments, so that the output of various devices can be easily viewed on such displays. The output of DAC can be easily viewed by connecting CRO. Similarly, key detection can be displayed on either LEDs or 7segments. As our Trainer Kit is enclosed inside a wooden box, it is completely unaffected by external parameters. 4. Versatility:

As in the Trainer kit, we have included RTC, it can works as a Digital Clock. Temperature can be measured with the help of temperature sensor of Trainer Kit, which makes it a Temperature-monitoring system. It can be used as a multi controller communication system. By interfacing RS-232 with Trainer Kit, we can easily make communication between PC and Trainer kit. We have included all fundamental devices interfacing such as LEDs, LCD,7-segment, keyboard, ADC, DAC, Sensors etc. which make the students to understand the control system thoroughly. 5. Cost Effective:

In our Trainer Kit we have used 2 Microcontroller IC’s and one 8255 Ic. With the help of 3 Ic’s we are able to interfaced a number of different modules. We have used various components that are easily available in the local market. This makes our Trainer Kit Cost-Effective.

6. Multiple function in one device: In this trainer kit also students can get knowled about different modules and has useful applications. Using 4*4 matrix keyboard it can be used as calculater. Using RTC it can work as digital clock. Using DAC various waves like square wave, triangle wave, sine wave are generated. Using LM35 temperature sensor it can monitor temperature and on this basis we can design temperature security system. Using RS-232 communication between computer and controller is done. 7. Simple modules: This trainer kit is designed very simply. As students can understand different modules we avoid to use complicate modules. Instead using other more advantageous controller we use 89c51. Also programming is done in assembly. We start from basic level so students understand easily. 3.3. BLOCK DIAGRAM OF TRAINER KIT Figure 3.1 shows the block diagram of Microcontroller based Trainer Kit. The main parts included inside the Trainer Kit can be listed as below: 1. Two 89c51 Microcontrollers from 8051 family. In which one act as a Transmitter while other as a Receiver while employing Serial Communication. 2. Four selection switches which defines which particular modules which be executed at a given time. There are specific codes given to each and every practical. On the basis of switch status, particular practical is selected. 3. One 8255 PPI, In order to expand Microcontroller port pins and to make

system design simpler. 4. 5. Matrix keyboard with 16 keys arranged as 4 rows and 4 columns. Four LEDs, for understanding basics of display.

6. ADC (Analog-to-Digital Converter) o deal with real-world physical quantities. 7. 8. 9. 10. Temperature sensor, For temperature monitoring system. EEPROM, To access the ROM for reading and Writing data. RTC (Real Time Clock), to make digital Clock. LCD,for displaying various practical names.

11. DAC (Digital-to-Analog Convetor) for generating various waves such as square, sine and triangular. 12. Seven-segments for displaying the key detection.

3.4. CIRCUIT DIAGRAM OF TRAINER KIT

3.5.

APPLICATIONS

Apart from the trainer kit, this project can be used as a digital clock temperature monitoring system. It can also be used for various types of wave generation and serial communication. By extending some of its features it can be used as a digital Function generator, control access system, general purpose sensor kit, home automation System etc. 1.3.1 TRAINER KIT: The trainer kit is used for giving the explanation of various types of Interfacings to the students. By using this trainer kit the student can learn the interaction between the hardware and software of the particular device. In our trainer kit we have included the display devices like LCD, seven segment so

through them can check the out put of the other interfacings like key board, DAC, ADC, E2PROM, RTC ,sensors etc. 1.3.2 DIGITAL CLOCK: In our trainer kit the combination of RTC and LCD works as a digital clock. We have used an RTC DS-1307, which works on battery mode also so it fulfills the requirement of real time applications. To display the time we have used the LCD, so user can view the time on it. Only limitation is that the user can not set the time according to his/her requirement. To set the time, changes must be made in software. 1.3.3 TEMPRATURE MONITORING SYSTEM: In our trainer kit the combination of ADC, temperature sensor and LCD interfacing can be used as a temperature monitoring system. It will sense the temperature of its surrounding and display it on an LCD .the temperature will be measured in Celsius. Here an ADC is used for converting the analog output of the sensor in the digital one.

1.3.4 WAVE GENERATION: In our trainer kit if the DAC interfacing module is connected with the CRO then Sine wave, square wave and triangle wave can be generated. Some other types of wave forms like saw tooth, staircase can also be generated by modifying the software. 1.3.5 SERIAL COMMUNICATION: The communication link for the multi processor and multi Controller can be established. Same way the RS-232 interfacing is used for establishing the communication link with the PERSONAL COMPUTER. 1.3.6 PROSPECTIVES: By modifying the trainer kit it can be used as a control access system, digital function generator, general purpose sensor kit, temperature controlling system , home automation system etc. SOFTWARE DETAILS The software used for making the programs in the assembly language is Topview simulator. The software provides the utility to convert the assembly program to be converted into the hex file that can be then loaded to the controller. Further detail about it is as follows TOPVIEW SIMULATOR INTRODUCTION: Topview Simulator gives an excellent simulation environment for the Industry's

most popular 8 bit microcontroller family, MCS 51. It gives all the required facilities to enable the system designers to start projects right from the scratch and finish them with ease and confidence. Topview Simulator is the total solution giving many state of art features meeting the needs of the designers possessing different levels of expertise. If you are a beginner, then you can easily learn about 8031 based embedded solutions without any hardware. If you are an experienced designer, you may find most of the required facilities built in the simulator that enable you to complete your next project without waiting for the target hardware. The simulator is designed by the active feedback from the demanding designers and when you use this in your next 8031 project, you are assured of definite savings in time and increase in productivity.

The features of the simulator are briefly tabulated here. DEVICE SELECTION Topview simulator provides a wide range of device selection, including generic 8031 devices and Atmel's AT89CXX series 8031 microcontrollers. PROGRAM EDITING Topview simulator provides Powerful editing feature for generating your programs and the facility to call an external assembler to process input programs. CLEARVIEW GUI ENVIRONMENT ClearView GUI facility gives all the internal architectural details in the strategically placed windows. Information about the Program, Data Memory, Registers, Peripherals, SFR Bits, and Memory Bits are clearly presented in many windows to make user understand the program flow very easily. PROGRAM EXECUTION A variety of program execution options include Single Stroke full speed execution, SingleStep, StepOver and BreakPoint execution modes give you total control over the target program. ClearView updates all the windows with the correct and latest data and it is a convenient help during your debugging operations. User may find how this Topview Simulator simplifies the most difficult operation of the program development, debugging, into a most simple task. SIMULATION FACILITIES Powerful simulation facilities are incorporated for I/O lines, interrupt lines and the clock sources meant for Timers/Counters. Many external embedded building blocks can be simulated: Range of Plain Point LED's and Seven Segment LED Display options. LCD modules in many configurations. Momentary ON keys, Toggle Switches. A variety of keypads upto 4 X 8 key matrix. All modes of on-chip serial port communication facility. IIC components including RTC, E2PROMs. SPI Bus based E2PROM devices. CODE GENERATION FACILITIES Powerful and versatile code generating facility enables user to generate the exact and compact assembly code for many possible application oriented interfacing options. User can simply define his exact needs and get the target assembly code at a press of button at anywhere in his program flow. The code gets embedded into his application program automatically. User is assured trouble free working of final code in the real time. • All modes of the serial port. • Interfacing IIC, SPI Bus devices.

• • 3.5.

Range of keypads. Many LED/LCD interfacing possibilities. Flowchart of Program.

3.6

POSSIBLE DESIGNS :

MICROCONTROLLER KIT FOR DIGITAL INVERTER

Features Intelligent battery management Automatic change over PIC16F73 based CC-CV charging Overload shut down LCD display [optional] PWM based PIC16F73 based digital inverter is an excellent microcontroller kit to demonstrate the working of a power electronic system. The output waveform is modified square and the system can have rated load of 500 VA. The charging mechanism used is constant current –constant voltage. This will ensure better battery management. Overload and short circuit is provided both in firmware and hardware. The output voltage is regulated within a range of 210-250 V. The kit runs on a 12V dc bus and is designed to get high efficiency.

Signal Generator Mini-Kit

In the field of electronics, there are many applications with the need to generate signals to assist with circuit experiment, alignment, and troubleshooting. This simple signal generator mini-kit MK105 from Velleman could be the economical solution you need for generating those simple AC electronic signals. This kit outputs a fixed 1 KHz sine wave, triangle wave, square wave, and integrator signals that are selectable through jumper configuration. Output level is adjustable from 0 to 100 mV RMS with the onboard Level potentiometer.

Features Signal (selectable Signal Output Signal

output : sine wave, triangle wave, square wave and integrator through jumper) generator frequency : about 1kHz (fixed) level : adjustable from 0 to 100mVrms (LEVEL potentiometer) generator mini-kit assembly is required ***********

SECTION-4 LED INTERFACING

4.1 Introduction When you need to add light to a model, an ordinary filament lamp is the first thing that springs to mind. But if you don’t need a high light output, or you need light as an indicator, an LED has many advantages over a lamp. LEDS are basically the single light display that include incandescent and are treated as single binary points to be switched on and off by programme instruction. The individual light display are easy to use. A port present a bit or a character and then strobe the device. 4.2 Advantages of LEDs Shapes and Sizes: LEDs are available in many shapes and sizes, some of which are shown in the selection below. The 'standard' LED shape is the 5mm diameter domed type, and the smaller 3mm domed type is also popular. 1. Tri-LED array 2. 10 segment bar displays 3. Domed LED sizes 3, 5 ,8, 10mm 4. Panel mounting LED 5. PCB mounting LED 6. 26mm red & green LED cluster Colours LEDs have traditionally been red, orange, yellow, or green, but advances in LED

technology mean that blue and white LEDs are now available, though at a much higher price. These LEDs are considerably brighter than standard LEDs so they could be used for lighting, but you will find the ones described as 'white' still have a blue tinge. Also available are LEDs described as 'bi-color' and 'tri-colour'. Bi-colour LEDs typically incorporate one red and one green LED in the same package. Since they have only two leads, only one LED can be on at any time. Tri-colour LEDs also have two LEDs in one package, but because they have three leads, both LEDs can be switched on together, their light combining to make a third colour, typically orange. The central lead of such a package is the common for both LEDs. Some manufacturers produce true 'tri-colour' LEDs incorporating red, green, and blue LEDs, so in theory it is possible to create light of any colour. The physical colour of an LED package does not necessarily indicate the colour it will be when switched on. Some LEDs have a clear plastic package, while others may have a diffused plastic package. 1. Standard red, green and yellow LEDs 2. Bi-colour LEDs 3. Tri-colour LEDs

Current Consumption LEDs consume much less current than lamps - usually only 20mA - so they are ideal for battery powered models. Long Life LEDs rarely fail (unless you supply them with the wrong voltage!) so are handy in parts of a model that are hard to reach.

Which Way Around? How can you tell which lead on an LED is which? Figure 2 shows a standard domed LED. If brought new, you will find that the longest lead is the positive lead, or 'anode', and the shortest lead is the negative lead, or 'cathode'. If the leads have been cut there are a few other ways to find out the polarity: • The plastic package nearest the cathode will be flattened slightly. • When holding the LED up to a light, the largest triangular section inside will be nearest the cathode. You can also connect up the LED (as in Figure 1) both ways around to see which is correct - reverse biasing the LED won't do it any harm. 4.3 Hardware connections For interfacing a single Led to 89c51 microcontroller, we connect the anode(+) end of LED to the designated port pin via a pull-up resistor. While the cathode end of LED is connected to GND. Connection of 1 LED to 89c51 port pins is as shown in figure. For glowing a LED, a high logic is required at the anode(+), so port pin is set to high for glowing LED. One end of single LED is connected to port pin of 89c51 via a pull up resistor and other one is grounded. In Switch, One end is connected to port pin of 89c51, while other one is Grounded. 4.4 Flowchart of program. 1. For 1 LED and 1 Switch program

2. For 4 LED and 4 Switch program

***********

SECTION-5 KEYBOARD INTERFACING

5.1 Introduction The predominant interface between humans and computers is the keyboard. Keyboard range in complexity from the “up-down” buttons used for elevators to the personal computer multimedia keyboard layout, with the addition of function keys and numeric keypads. One of first requirement was to interface keyboard with microcontroller and with the main processor in personal computers. Industrial and commercial applications fall somewhere in between these extremes, using layouts that might feature from six to twenty keys. One of the most basic requirements in configuring a keypad is to accommodate need of human user. Human beings are irritable. They have little tolerance for machine failure. You have seen the behavior of people at the elevator. Even if the “up” light is lit when we arrive, we will push it again to let the machine know that “I’m here too.” Thus the hardware designer has to select keys that will survive in the intended environment. The programmer must write the code that will anticipate and defeat deliberate attempts by human to confuse program. The software must be such that the keyboard application must guard against following Human Factors: 1. 2. 3. More than one key pressed. Key pressed and held. Rapid key press and release.

5.2 Keyboard Configurations Keypads are often used as a primary input device for embedded microcontrollers. At the lowest level keypads are arranged as a matrix of rows and columns which are for by using number of switches as shown in Fig 5.1 and Fig 5.2 shows how it looks on real hardware. The CPU accesses both rows and columns through ports; therefore, with one bit ports a 4×4 matrix keys can be connected to a microcontroller. When a key is

pressed the row makes a contact with column. Otherwise there is no connection between rows and columns. Microcontroller itself makes a continuous check of all rows and columns with the help of program stored in its ROM to see whether a key is pressed or not, It takes care of both hardware and software.

In order for the microcontroller to scan the keypad, it outputs a nibble to force one (only one) of the rows and then reads the columns. If any keys in that column have been pressed. The rows are pulled up by the internal weak pull-ups in the 8051 ports. Consequently, as long as no buttons are pressed, the microcontroller sees a logic high on each of the pins attached to the keypad rows. The nibble driven onto the columns always contains only a single 0. The only way the microcontroller can find a 0 on any row pin is for the keypad button to be pressed that connects the column set to 0 to a row. The controller knows which column is at a 0-level and which row reads 0, allowing it to determine which key is pressed. For the keypad, the pins from left to right are: R1, R2, R3, R4, C1, C2, C3, and C4. Next section shows you how to detect a key press using 89C51.

5.3 SCANNING AND IDENTIFYING KEYPRESS Here we have used 4×4 matrix keyboard. Its interfacing to 89C51 is as shown in figure. Rows are connected to the output port and columns are connected to input port. If no key is pressed then the status of all columns will be high at Vcc. If all rows are grounded and a key is press, then the status of one of the column will goes low since the key provides path to ground. Using the above procedure Microcontroller scans continuously and detects a key press. To detect key press, the microcontroller grounds all rows by providing 0 to the output latch, then it reads the columns, If date read is p0.4-p0.7=1111, no key is pressed and process continues until a key press is detected. When a key press occurs, one of the columns will go zero. For example, if p0.4-p0.7=1101 this means that key of column-3 that is connected to p0.6 is pressed. After the key press is detected than microcontroller goes for identifying a key. Starting with the top rows microcontroller continuously ground each of the row and check corresponding column. If the column status is all high then no key is press and process is moved to next row. 5.4 HARDWARE CRITERIA

Figure shows interfacing of 89c51 with 4 x 4 matrix keyboard. Here rows are connected from p0.0-p0.3. while columns are connected from p0.4-p0.7.

TO DETECT MATRIX KEYBOARD USING 4 LEDs. Display Keypad Data to LED In this lesson we are like to design, how to scan keypad 4 x 4, and then display it to LED. In this hardware 4*4 keyboard is connected to eight port pins. And 4 LEDS are connected to four other port pins. All cathodes of LEDS are shorted and grounded while anode of each LED is connected to port pin via pull up resistor. Which key is pressed on key board (0 to f keys) hex value of this key digit is displayed on four LEDS. If 0 key is pressed all four LEDS are off. If 1 key digit pressed 0001 pattern will be displayed on LEDS.

5.5

Flowchart of program

*********** SECTION-6 INTERFACING OF 7-SEGMENT DISPLAY

6.1 Introduction One common requirement for many different digital devices is a visual numeric

display. Individual LEDs can of course display the binary states of a set of latches or flip-flops. However, we're far more used to thinking and dealing with decimal numbers. To this end, we want a display of some kind that can clearly represent decimal numbers without any requirement of translating binary to decimal or any other format. One possibility is a matrix of 28 LEDs in a 7×4 array. We can then light up selected LEDs in the pattern required for whatever character we want. Indeed, an expanded version of this is used in many ways, for fancy displays. However, if all we want to display is numbers, this becomes a bit expensive. A much better way is to arrange the minimum possible number of LEDs in such a way as to represent only numbers in a simple fashion. This requires just seven LEDs (plus an eighth one for the decimal point, if that is needed). A common technique is to use a shaped piece of translucent plastic to operate as a specialized optical fiber, to distribute the light from the LED evenly over a fixed bar shape. The seven bars are laid out as a squared-off figure "8". The result is known as a seven-segment LED. We've all seen seven-segment displays in a wide range of applications. Clocks, watches, digital instruments, and many household appliances already have such displays. In this experiment, we'll look at what they are and how they can display any of the ten decimal digits 0-9 on demand Seven segments display a single character. Seven segments Display commonly contains LED segments arranged as an 8 with one common Lead that is either anode or cathode and seven individual leads for its segment. Figure shows the pattern and equivalent circuit representation of common cathode display. If more than one display is to be used then they can be time-multiplexed. The human eye cannot detect the blinking if each display is relit every 10ms or so. The 10ms is divided by number of displays used to find intervals between updating each display. Schematic Diagram As shown in the two schematic diagrams above, the LEDs in a seven-segment display are not isolated from each other. Rather, either all of the cathodes, or all of the anodes, are connected together into a common lead, while the other end of each LED is individually available. This means fewer electrical connections to the package, and also allows us to easily enable or disable a particular digit by controlling the common lead. (In some cases, the common connections are made to groups of LEDs, and the external wiring must make the final connections between them. In other cases, the common connection is made available at more than one location for convenience in laying out printed circuit boards. When laying out circuits using such devices, you simply need to take the specific connection details into account.) There is no automatic advantage of the common-cathode seven-segment unit over the common-anode version, or vice-versa. Each type lends itself to certain applications, configurations, and logic families. We'll learn more about this in later experiments. For the present, we will use a common-cathode display as our experimental example. Seven-Segment Display Layout The illustration to the right shows the basic layout of the segments in a sevensegment display. The segments themselves are identified with lower-case letters "a" through "g," with segment "a" at the top and then counting clockwise. Segment "g" is the center bar. Most seven-segment digits also include a decimal point ("dp"), and some also include an extra triangle to turn the decimal point into a comma. This improves readability of large numbers on a calculator, for example. The decimal point is shown here on the right, but some display units put it on the left, or have a

decimal point on each side. In addition, most displays are actually slanted a bit, making them look as if they were in italics. This arrangement allows us to turn one digit upside down and place it next to another, so that the two decimal points look like a colon between the two digits. The technique is commonly used in LED clock displays.

Seven-segment displays can be packaged in a number of ways. Three typical packages are shown above. On the left we see three small digits in a single 12-pin DIP package. The individual digits are very small, so a clear plastic bubble is molded over each digit to act as a magnifying lens. The sides of the end bubbles are flattened so that additional packages of this type can be placed end-to-end to create a display of as many digits as may be needed. The second package is essentially a 14-pin DIP designed to be installed vertically. Note that for this particular device, the decimal point is on the left. This is not true of all seven-segment displays in this type of package. One limitation of the DIP package is that it cannot support larger digits. To get larger displays for easy reading at a distance, it is necessary to change the package size and shape. The package on the right above is larger than the other two, and thus can display a digit that is significantly larger than will fit on a standard DIP footprint. Even larger displays are also available; some digital clocks sport digits that are two to five inches tall. Seven-segment displays can be constructed using any of a number of different technologies. The three most common methods are fluorescent displays (used in many line-powered devices such as microwave ovens and some clocks and clock radios), liquid crystal displays (used in many battery-powered devices such as watches and many digital instruments), and LEDs (used in either line-powered or batterypowered devices). However, fluorescent displays require a fairly high driving voltage to operate, and liquid crystal displays require special treatment that we are not yet ready to discuss. Therefore, we will work with a seven-segment LED display in this experiment. 6.2 Hardware Criteria

Multiplex seven segment display When there is need of more than one seven segment they can be time multiplexed. In the connection segment information is output on any port of 89c51 and the cathode selection is done by portpins. Transistor must be used to handle the currents required by the leds, typically 10 milliamperes for each segment and 70 milliamperes for each cathode. These are average current values, the peak currents will be four times as high for the 2.5 milliseconds each display is illuminated. In multiplexed segment transistors are required as number of segments. Enable lines also required as much as segments, high logic on any of the one port pins select the segment. All data lines or segment lines of different segments are shorted first. As an segment line “a” of the for first segment is shorted with all segments’ line a. Finally for any number of segments there are eight segment lines. Each of the segment is selected by the enable lines connected to port pins by transistor. At ones only one segment can be lit. Advantage of this kind of connection or multiplexing is the minimum use of port pins. For two segments no need of 16 port pins but only 8 pins required. The difference is only time multiplexing. All segments not lit at ones but time between two is hardly observed by human eyes. That’s why it is more in use. Inter facing of four multiplexed seven segment to 89c51

Figure: As key is pressed using look up table scan code is given to segment and character or number is displayed. Only difference is that segment lit one by one.

Non multiplexed seven segment Here more than one segment can be used but they are not multiplexed. At once multiple segments lit and no time sharing between two segments. In short, segment lines a,b,c…..dp of different segments are not shorted. For connection of two segments 16 segment lines (8 per one)are required. Controller has not so much port pins to effort. Due to lack of port pins or saving the pins multiplexing is the better choice over non multiplexing. Only advantage is many segments can be lit at a time. Here we show connection of single sevan segment to controller. Keyboard is iput device and dislay is output device. If switch is pressed on keyboard after detecting which key is pressed, we get scan code (a pattern of zero’s and one’s to which can lit a segment and form a character or digit) using look up table. This pattern is given to segment lines appropriate digit according to key is displayed on segment. To enable segment one port pin is used to which (we use pnp transistor and common cathode) transistor base is connected and emitter is grounded While collector is connected to segment. For common anode and npn transistor connecton is reversed

This is example of single sevan segment. For non multiplex another segment is connected to remaining eight port pins. 6.3 Flowchart of program

FLOW CHART OF KEYBOARD AND SINGLE 7 SEGMENT

FLOW CHART OF KEYBOARD AND MULTIPLEXED 7 SEGMENT

*********

SECTION-7 INTERFACING OF EEPROM

7.1 Introduction As we know, ROM is a memory that does not lost its contents when the power is turned off. For this reason ROM is also called Non-Volatile Memory. There are different types of ROM such as PROM, EPROM, EEPROM, Flash EPROM and Mask ROM. In which PROM refers to the Kind of ROM that the user can burn information into. PROM is a user programmable memory. PROM is referred to as OTP (One time programmable). EPROM was invented to allow making changes in the contents of PROM after it is burned. In short, one can program the memory chip and erase it thousands of time. This is especially necessary during development of microcontroller based project. EEPROM is electrically erasable programmable ROM. EEPROM has several advantages over EPROM. EEPROM does not requires external eraser and programming device. Flash EPROM has become a popular user programmable memory chip. The reason behind that is the eraser of entire content takes less than a second that why it is named Flash memory. When flash memory contents are erased the entire device is erased whether in EEPROM one can erased a desired section or byte. In masked ROM, the contents are programmed by the IC manufacturer.It is not a user programmable ROM. Masked ROM is used when the needed volume is high and the contents will not change. It is cheaper than other kind of ROM.

FEATURES:1000000 erase/write cycles minimum with over 10 years data retention. Single 3V to 5.5V supply voltage. Two wire serial interface, fully I2C BUS compatible. Byte and multibyte write (upto 4 bytes) Page write (upto 8 bytes). Byte, random and sequential read modes. Self timed programming cycle. Automatic address incrementing 7.2 Pin Description

AT24c02 provides bits of serially erasable and programmable Read Only memory (EEPROM) organized as 256 words of 8-bits each. The device is optimized to be used in many industrial and commercial applications wher low power and low voltage operation are essential. 24c02 EEPROM IC is available in 8-pin DIP and is accessed via two-wire serial Interface. Figure shows pin Description of 24c02 EEPROM IC. SERIAL CLOCK (SCL): The SCL input is used to positive edge clock data into each EEPROM device and negative edge clock data out of each device. SERIAL DATA (SDA): The SDA pin is bidirectional for serial data transfer. This pin is open-drain driven and may be wire-ORed with any number of other open-drain or open-collector devices. DEVICE/PAGE ADDRESSES (A2, A1, A0): The A2, A1 and A0 pins are device address inputs that are hard wired for the AT24C02. As many as eight 1K/2K devices may be addressed on a single bus system (device addressing is discussed in detail under the Device Addressing section). WRITE PROTECT (WP): The AT24C02 has a Write Protect pin that provides hardware data protection. The Write Protect pin allows normal Read/Write operations when Connected to ground (GND). When the Write Protect pin is connected to VCC, the write protection feature is enabled and operates as shown in Table 2. WP pin status At VCC At GND Part of 24c02 Array Protected

Full (2K) Array Normal Read/Write Operations

The ST24C02A is a 2k bit electrically erasable programmable memory, organized as 256x8 bits. The memory is compatible with the I2C bus standard, two data bus and serial clock. The STA240C2A carries a built in a bit unique device information code corresponding to the I2C bus definition. This is used together with a 3-bit chip enable input to form a 7-bit memory select signal. In this way upto 8 ST24C02A’S may be connected to the I2C bus and selected individually. The ST24C02A behaves as a slave device in the I2C protocol with all memory operations synchronized by the serial clock. Read and write operations are initiated by start condition generated by the bus master. The start condition is

followed by a stream of 7 device select bit plus one read/write bit and terminated by an acknowledge bit. When writing data to the memory it respond to the 8 bits received by asserting an acknowledge bit during the ninth bit time. Data transfers are terminated with a stop condition. OPERATING MODES:There are both read and write modes. Each is entered by the correct sequence of serial bits sent to the device on the SDA line. For some write modes the status of the mode input is also used to set the operating mode. The 8 bits sent after a start condition are made up of a bits that identify the device type, 3 chip enable bits and one direction indicator bit. Whether the controller wants to read from the device or write to the device is decided by the very first byte sent to it on the SDA line. The last bit of very first sent to E2PROM is directional indicator. If this bit is ‘Zero’ the direction of data flow is from controller to the E2PROM and if ‘One’ it is from E2PROM to the controller. Following are the different modes for reading or writing from the E2PROM. 1). Byte Write: In this mode a device select is sent with the R/W bit at ‘0’ followed by the address of the byte. This is followed by the 8 bit data to be written during the programming cycle. 2). Multibyte Write And Page Write: In these modes upto 4 or 8 bytes respectively may be written in one programming cycle. Multi-byte write mode is activated when the mode pin is at V/H level and page write when mode is at V/L. A device select is sent with the R/W bit at ‘0’ followed by the data bytes to write. The bytes are written in the programming cycle 8 bytes written in the page write mode must have the same five upper address bits 3). Current Address:

In this mode device select is sent with the R/W bit at ‘1’. The address of various byte accessed is automatically incremented and the new byte read. 4). Random Address Read: This mode allows random access to the memory. A device select is sent with R/W bit at ‘0’(write) followed by the address. Then a new start condition is forced with the same device select is sent with the R/W bit at ‘1’ (read) and the byte is read. 5). Sequential Read: This mode starts with either a current address or random address read sequence it reads consecutive bytes as long as the bus master acknowledges each one without generating a stop condition.

7.3 Device operation based on I2c protocol: The 24C02 family uses two I/O lines for interfacing: SCL (Serial Clock) and SDA (Serial Data). SCL edges have different functions, depending on whether a device is being read from or written to. When clocking data into the device, the positive edges of the clock latch the data. The negative clock edges clock data out of the device.

The SDA signal is bi-directional, and is physically an open-drain so that multiple EEPROMs or other devices can share the pin. Both SCL and SDA must be pulled high externally. The protocol used by the EEPROM is based in part on an ACK (acknowledge) bit sent by the EEPROM, if the data sent to it has been received. All addresses and data are sent in 8-bit words. The EEPROM sends the ACK as a low bit period during the ninth clock cycle. The EEPROM looks for specific transitions on the SCL and SDA pins to qualify READ and WRITE. Data on the SDA pin may change only during the time SCL is low. Data changes during SCL high periods indicate a START or STOP condition. A START condition is a high-to-low transition of SDA with SCL high. All data transfers must begin with a START condition. A STOP condition is a low-to-high transition of SDA with SCL high. All data transfers must end with a STOP condition. After a READ, the STOP places the EEPROM in a standby power mode. Refer to Figure 1 for START and STOP conditions.

Figure 1. START and STOP conditions. Device Addressing The 24C02 has 3 physical pins, designated A2, A1, and A0, which are tied to logic 1 or 0 levels. This allows eight unique hardware addresses, so that up to eight 24C02s can share the SCL and SDA lines without conflict. There is an internal address comparator that looks for a match between the address sent by the master controller and the 24C02's unique 7-bit address, determined in part by A2, A1, and A0. Refer to Table 1below. Table 1. 24C02 Device Address MSB LSB 1 0 1 0 A2 A1 A0 R/~W The device address is sent immediately after a START condition. The first four bits are the sequence "1010", which is a simple "noise filter" which prevents a random noise burst on the lines from accessing the device. The last bit sent is a 1 for READ and a 0 for WRITE. The code example below is for random READ/WRITE operations. The part can also perform Page Write/Sequential Read with slight code modifications. See the 24C02 data sheet for more information. Byte Write to Memory The Byte Write sequence is shown in Figure 2. After receiving a START condition and a device address, the EEPROM sends an ACK if the device address matches its own unique address. The MAX7651 waits for the ACK and aborts communication if it is not present. Next, an 8-bit byte address is sent, followed by another ACK. The MAX7651 then sends the 8-bit data byte, waits for the third ACK, and sends a STOP condition. WRITE operation. It is important to note that after the STOP condition is received, the EEPROM internally waits for the data to be stored into its internal memory array. This can take as long as 10ms. The 24C02 will ignore attempted accesses while the internal EEPROM is being programmed. The part can be polled for completion of the internal write cycle. This involves sending another START condition (also called a REPEATED START), followed by the device address byte. Note, in this case, there is no STOP condition sent. The EEPROM will send an ACK if the internal programming cycle is completed. The MAX7651 can also be programmed to wait 10ms before proceeding. Byte Read from Memory Reading a byte from the 24C02 EEPROM at a random address requires that a dummy WRITE operation be performed before the READ. See Figure 3.

The sequence is: • START condition • Send device address with R/~W = 0 'dummy WRITE' command • Wait for ACK • Send byte memory address • Wait for ACK • Send REPEATED START condition • Send device address with R/~W = 1 (READ command) • Wait for ACK • Read the 8 data bits into the MAX7651, MSB first • No ACK • STOP condition This sequence is quite involved! The total number of SCL transitions required for a READ is 38.

Waveform for data

7.4 Hardware connection EEPROM is based on i2c protocol ,two wired serial protocol. For that we need two pins. We use p3.6 for SCL and p3.7 for SDA . a0,a1,a2 are address lines to select eeprom chip. That is hard wired and fix for each eeprom. To send address, data, start-stop condition data we use SCL and SDA. 7.5 Flowchart of program

***********

SECTION-8 LCD INTERFACING

8.1 LCD Features LCD stands for Liquid Crystal Display are the most widely used output devices for 89c51 type microcontroller. Nowadays LCDs is finding widespread use compared to LEDs and 7-segment. This is due to following specific features : 1. The declining prices of LCDs make its use cost-effective. 2. The ability to display numbers, characters and graphics. This is contrast to LEDs, which has limited to numbers and few characters. Incorporation of a refreshing controller into LCD, thereby relieving the CPU of the task of refreshing the LCD. In contrast, the LED must be refreshed by the CPU to keep displaying data. 3. Ease of programming for characters and graphics. 8.2 LCD Pin Descriptions The LCD which we have used in our TRAINER KIT is discussed in this section. It has 14 pins. Figure shows the position of various pins.

1. VCC, VSS, and VEE While VCC and VSS provide +5V and ground, respectively, VEE is used for controlling LCD contrast. 2. RS (Register Select) There are two very important registers inside the LCD. The RS pin is used for their selection as follows. If RS=0, the instruction command code register is selected, allowing the user to send a command such as clear display, cursor at home, etc. If RS=1, the data register is selected, allowing the user to send data to be displayed on LCD. 3. R/W (Read/Write) R/W input allows the user to write information to LCD or read information from it. R/W=1 when reading; R/W=0 when writing. 4. E (Enable) The enable pin is used by the LCD to latch information presented to its data pins.

When data is supplied to data pins, a high-to-low pulse must be applied to this pin in order for the LCD to latch in the data present the data pins. This pulse must be a minimum of 450 ns wide. 5. D0-D7 (8-bit Data bus) The 8-bit data pins, D0-D7, are used to send information to the LCD or read the contents of the LCD’s Internal registers. To display letters and numbers, we send ASCII codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making RS=1. There are also instruction command codes that can be sent to LCD to clear the cursor to the home position or blink the cursor. Table lists some of the instruction command codes.

Code (Hex) 1 2 4 6 5 7 8 A C E F 80 C0

Command to LCD Instruction Register Clear Display screen Return home Shift cursor left Shift cursor right Shift Display right Shift Display left Display off, cursor off Display off, cursor on Display on, cursor off Display on, cursor blinking Display on, cursor blinking Force cursor to beginning of 1st line Force cursor to beginning of 2nd line

8.3

LCD Timing Waveform

This section shows you the details about how to control enable, register select, read/write and data lines of LCD for its proper operation. Figure shows you read timing waveform and figure shows write timing waveform.

8.4

Connection of LCD with 8255

The main purpose of LCD in our Trainer kit is to display the name of the practical which is going to perform by the user and so LCD is programmed according. Figure shows various connection required to interfaced an LCD to 89c51. Here data lines of LCD are connected to 8 port of 89c51 microcontroller. On this data lines, various command codes for LCD settings and data codes which are required to display are sent. There are three controlling lines for LCD viz, RS, R/W and E. RS that is register select is connected to designated port pin of 89c51 and set or reset as required.

Similarly remaining two lines R/W that is Read/Write and E that is Enable are connected to designated 89c51 port pins and set or reset as required. Given figure shows connection of 8255 with LCD

Circuit diagram: 8.5 Flowchart of program

********** SECTION-9 RTC INTERFACING

9.1

INTRODUCTION

The real time clock is most widely device that provides accurate time and date for many applications. RTC chip has the capability of providing time components of hour, minute and second, in addition to date/calendar components of year, month, and day. The RTC chip uses an internal battery, which keeps the time and date even when power is off. Although some 8051 microcontrollers come with RTC embedded into the chip, we have to interfaced vast majority of them external to the 8051 chip. One of most widely used RTC chip is DS1307 from Dallas Semiconductor/Maxim Corp. This RTC chip has a specific features of Two-wire Serial Interface. The DS1307 Serial Real-Time Clock is a low-power, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially via a 2-wire, bi-directional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. The DS1307 has a builtin power sense circuit that detects power failures and automatically switches to the battery supply. Next section describes you some of the features of DS1307 RTC chip. 9.2 FEATURES

1. Real-time clock (RTC) counts seconds, minutes, hours, date of the month, month, day of the week, and year with leap-year compensation valid up to 2100 years. 2. 56-byte, battery-backed, nonvolatile (NV) RAM for data storage. 3. Two-wire serial interface.. 4. Programmable squarewave output signal. 5. Automatic power-fail detect and switch circuitry. 6. Consumes less than 500nA in battery backup mode with oscillator running. 7. Optional industrial temperature range: -40°C to +85°C. 8. Available in 8-pin DIP or SOIC. 9.3 Pin Descriptions These Section describes you DS1307 pins. See Figure 9.1 VCC, GND – DC power is provided to the device on these pins. VCC is the +5V input. When 5V is applied within normal limits, the device is fully accessible and data can be written and read. When a 3V battery is connected to the device and VCC is below 1.25 x VBAT, reads and writes are inhibited. However, the timekeeping function continues unaffected by the lower input voltage. As VCC falls below VBAT the RAM and timekeeper are switched over to the external power supply (nominal 3.0V DC) at VBAT. VBAT – Battery input for any standard 3V lithium cell or other energy source. Battery voltage must be held between 2.0V and 3.5V for proper operation. The nominal write protect trip point voltage at which access to the RTC and user RAM is denied is set by the internal circuitry as 1.25 x VBAT nominal. A lithium battery with 48mAhr or greater will back up the DS1307 for more than 10 years in the absence of power at 25ºC. UL recognized to ensure against reverse charging current when used in conjunction with a lithium battery. SCL (Serial Clock Input) – SCL is used to synchronize data movement on

serial interface.

SDA (Serial Data Input/Output) – SDA is the input/output pin for the 2-wire serial interface. The SDA pin is open drain which requires an external pullup resistor. SQW/OUT (Square Wave/Output Driver) – When enabled, the SQWE bit set to 1, the SQW/OUT pin outputs one of four square wave frequencies (1Hz, 4kHz, 8kHz, 32kHz). The SQW/OUT pin is open drain and requires an external pull-up resistor. SQW/OUT will operate with either Vcc or Vbat applied. X1, X2 – Connections for a standard 32.768kHz quartz crystal. The internal oscillator circuitry is designed for operation with a crystal having a specified load capacitance (CL) of 12.5pF. The DS1307 can also be driven by an external 32.768kHz oscillator. In this configuration, the X1 pin is connected to the external oscillator signal and the X2 pin is floated.

9.4 Operation Based on I2C protocol The DS1307 supports a bi-directional, 2-wire bus and data transmission protocol that is called I2C protocol. A device that sends data onto the bus is defined as a transmitter and a device receiving data as a receiver. The device that controls the message is called a master. The devices that are controlled by the master are referred to as slaves. The bus must be controlled by a master device that generates the serial clock (SCL), controls the bus access, and generates the START and STOP conditions. The DS1307 operates as a slave on the 2-wire bus. A typical bus configuration using this 2-wire protocol is show in Figure 4. Figures 5, 6, and 7 detail how data is transferred on the 2-wire bus. Data transfer may be initiated only when the bus is not busy. During data transfer, the data line must remain stable whenever the clock line is HIGH. Changes in the data line while the clock line is high will be interpreted as control signals. Accordingly, the following bus conditions have been defined:

Bus not busy: Both data and clock lines remain HIGH. Start data transfer: A change in the state of the data line, from HIGH to LOW, while the clock is HIGH, defines a START condition. Stop data transfer: A change in the state of the data line, from LOW to HIGH, while the clock line is HIGH, defines the STOP condition. Data valid: The state of the data line represents valid data when, after a START condition, the data line is stable for the duration of the HIGH period of the clock signal. The data on the line must be changed during the LOW period of the clock signal. There is one clock pulse per bit of data. Each data transfer is initiated with a START condition and terminated with a STOP condition. The number of data bytes transferred between START and STOP conditions is not limited, and is determined by the master device. The information is transferred byte-wise and each receiver acknowledges with a ninth bit. Within the 2-wire bus specifications a regular mode (100 kHz clock rate) and a fast mode (400 kHz clock rate) are defined. The DS1307 operates in the regular mode (100 kHz) only. Acknowledge: Each receiving device, when addressed, is obliged to generate an acknowledge after the reception of each byte. The master device must generate an extra clock pulse which is associated with this acknowledge bit. A device that acknowledges must pull down the SDA line during the acknowledge clock pulse in such away that the SDA line is stable LOW during the HIGH period of the acknowledge related clock pulse. Of course, setup and hold times must be taken into account. A master must signal an end of data to the slave by not generating an acknowledge bit on the last byte that has been clocked out of the slave. In this case,the slave must leave the data line HIGH to enable the master to generate

the STOP condition. DATA TRANSFER ON 2-WIRE SERIAL BUS

Depending upon the state of the R/W bit, two types of data transfer are possible: 1. Data transfer from a master transmitter to a slave receiver. The first byte transmitted by the master is the slave address. Next follows a number of data bytes. The slave returns an acknowledge bit after each received byte. Data is transferred with the most significant bit (MSB) first. 2. Data transfer from a slave transmitter to a master receiver. The first byte (the slave address) is transmitted by the master. The slave then returns an acknowledge bit. This is followed by the slave transmitting a number of data bytes. The master returns an acknowledge bit after all received bytes other than the last byte. At the end of the last received byte, a “not acknowledge” is returned. The master device generates all of the serial clock pulses and the START and STOP conditions. A transfer is ended with a STOP condition or with a repeated START condition. Since a repeated START condition is also the beginning of the next serial transfer, the bus will not be released. Data is transferred with the most significant bit (MSB) first. The DS1307 may operate in the following two modes: 1. Slave receiver mode (DS1307 write mode):

Serial data and clock are received through SDA and SCL.After each byte is received an acknowledge bit is transmitted. START and STOP conditions are recognized as the beginning and end of a serial transfer. Address recognition is performed by hardware after reception of the slave address and *direction bit (See Figure 6). The address byte is the first byte received after the start condition is generated by the master. The address byte contains the 7 bit DS1307 address, which is 1101000, followed by the *direction bit (R/ W) which, for a write, is a 0. After receiving and decoding the address byte the device outputs an acknowledge on the SDA Line. After the DS1307 acknowledges the slave address + write bit, the master transmits a register address to the DS1307 this will set the register pointer on the DS1307. The master will then begin transmitting each byte of data with the DS1307 acknowledging each byte received. The master will Generate a stop condition to terminate the data write. 2. Slave transmitter mode (DS1307 read mode):

The first byte is received and handled as in the slave receiver mode . However, in this mode, the *direction bit will indicate that the transfer direction is reversed. Serial data is transmitted on SDA by the DS1307 while the serial clock is input on SCL. START and STOP conditions are recognized as the beginning and end of a serial transfer (See Figure 7). The address byte is the first byte received after the start condition is generated by the master. The address byte contains the 7-bit DS1307 address, which is 1101000, followed by the*direction bit (R/ W) which, for a read, is a 1. After receiving and decoding the address byte the device inputs an acknowledge on the SDA line. The DS1307 then begins to transmit data starting with the register address pointed

to by the register pointer. If the register pointer is not written to before the initiation of a read mode the first address that is read is the last one stored in the register pointer. The DS1307 must receive a “not acknowledge” to end a read. 9.5 Hardware Criteria

RTC is based on i2c protocol which is two wired protocol. So we required only two pins to send address, to set rtc. This two pins serial data line and serial clock line are connected to any of two port pins. In our hardware connection we use p3.6 for SCL and p3.7 for SDA. To keep always on, RTC even in off supply 3v bettry is connected to pin3 of DS-1307. VCC and GROUND is applied to rtc. Fig:

9.6

Flowchart of program

*********

SECTION-10 DAC INTERFACING

10.1 Introduction In electronics, a digital-to-analog converter (DAC or D-to-A) is a device for converting a digital (usually binary) code to an analog signal (current, voltage or electric charge). Digital-to-analog converters are interfaces between the abstract digital world and analog real life. This section will show you how to interface a DAC to 89c51 microcontroller. Then we will demonstrate how to generate various waves such as sine, triangular and square on a scope using DAC. The DAC0808 is an 8-bit monolithic digital-to-analog converter (DAC) featuring a full scale output current settling time of 150 ns while dissipating only 33 mW with ±5V supplies. No reference current (IREF) trimming is required for most applications since the full scale output current is typically ±1 LSB of 255 IREF/256. Relative accuracies of better than ±0.19% assure 8-bit monotonicity and linearity while zero level output current of less than 4 μA provides 8-bit zero accuracy for IREF³2 mA. The power supply currents of the DAC0808 is independent of bit codes, and exhibits essentially constant device characteristics over the entire supply voltage range. Features: 1.relative accuracy: +0.19% error maximum. 2. full scale current match: + 1 lsb typical 3.fast setting time: 150 ns typical 4.noninverting digital inputs are ttl and cmos compatible 5.high speed multiplying input slew rate:8 ma/microsecond 6.powersuply voltage range:+ 4.5v to + 18v 7.low power consumption: 33 mw@ + 5v 10.2 Pin description

DAC 0808 is 16 pin dual in package ic. To know how it works, detail description of pins is given below. A1-A8 : These eight pins are digital inputs. For which digital input we want analog output, it’s eight bits are given to A0-A8 pins. VDC: It is power supply voltage range between 4.5v to 5.5v. Typically 5v supply is given. VREF(+) AND VREF(-): It is referance voltage to get an output voltage. As an example we take 5v vref(+) than for 00h digital input we get 0v and for FFh we get 5v analog output. For different levels of digital inputs between 00h to FFh we get fraction of vref(+) 5v. Digital input 00h to FFh Analog output 0V to 5v to status of vref(-), vref(+) vref(-) is grounded and 5v given vref(+) by resistor

00h to FFh

-5v to 0v

vref(+) is grounded and -5v is given to vref(-)

Compensation : Capacitor’s value increases with increasing resistor value r14 to make proper phase margin. It is connected to compensation pin and other end is connected to ground or vee. VEE: Using vee with capacitor increase negative supply rejection in case of vref (-) is connected. Negative reference voltage should be 4v lower than vee.

10.3 Operation of DAC DAC 0808 work on r/2r network.We are going to build a 8-bit digital to analog conveter with parallel input, a circuit that will take as input a digital number from 0 (00000000) to 255 (11111111), and output the relative value on a scale from 0 to 5v. An 8 bit converter will divide the 5 volts into 255 steps, each step having a value of: 5/255 = 0.019v Output voltage converter should be equal to the binary input multiplied by the step value, e.g. for an input of 129 (1000 0001 in binary) the output voltage should be: 129 X 0.019 = 2.451V

In dac digital to analog conversion is done by r/2r resistor network. The basic problem in converting a digital signal into an analog signal is to change the n digital voltage levels into one analog voltage.it is achieved by designing resistie network which chages each of the digital levels into an equivalent binary weight voltage.this binary weighted resistive network has some drawbacks. 1. each resistance in the network has different value. Their cost fector increases. 2. the resistance in msb required to handle much larger current than the lsb resistor. That’s why we use r/2r network. The most common types of electronic DACs are the R-2R ladder and binary weighted. We have used R 2R ladder. The Binary Weighted DAC, which contains one resistor or current source for each

bit of the DAC connected to a summing point. These precise voltages or currents sum to the correct output value. This is one of the fastest conversion methods but suffers from poor accuracy because of the high precision required for each individual voltage or current. Such high-precision resistors and current-sources are expensive, so this type of converter is usually limited to 8-bit resolution or less. BINARY WEIGHTED NETWORK: The R-2R Ladder DAC, which is a binary weighted DAC that uses a repeating cascaded structure of resistor values R and 2R. This improves the precision due to the relative ease of producing equal valued matched resistors (or current sources). However, wide converter performs slowly due to increasingly large RC-constants for each added R-2R link. FOUR-BIT D/A CONVERTER One way to achieve D/A conversion is to use a summing amplifier.

This approach is not satisfactory for a large number of bits because it requires too much precision in the summing resistors. This problem is overcome in the R-2R network DAC. The digital data entering thought the 8 lines (D0 to D7) are going to be converted to an equivalent analog voltage (V out) by the mean of the R/2R resistor network. Actually most of the commercial Digital to Analog converter ICs are based on this same principle. The R/2R network is build by a set of resistors of 2 values, with one of them double the other (example 10K and 20K). for example , one can use 1M ohm and 470K ohm resistors, which is quite near to the R/2R ratio, and this small difference didn't cause any detectable errors in most applications. However, if you want to build a very precise DAC, be precise when choosing the values of the resistors that will exactly match the R/2R ratio. One last note here, you can build a DAC with any number of bits you want, simple by enlarging the resistor network, by adding more R/2R branches (like the one shaded in green), but you must keep the 2R resistance connected to ground. R-2R LADDER DAC: The summing amplifier with the R-2R ladder of resistances shown produces the output Where the D's take the value 0 or 1. The digital inputs could be TTL voltages which close the switches on a logical 1 and leave it grounded for a logical 0. This is illustrated for 4 bits, but can be extended to any number with just the resistance values R and 2R. We are going to build an 8-bit digital to analog converter with parallel input. If you don't know what this means, well its simply a circuit that will take as input a digital number from 0 (00000000) to 255 (11111111), and output the relative value on a scale from 0 to 5v. DESIGN AND CALCULATION OF WAVEFORMS By using the DAC we have generated square wave, triangular wave and sine wave. SQUARE WAVE: For generating the square wave we have made the samples low and high

alternatively and through DAC we have got the following waveforms, which can be easily observed through CRO. TRIANGLE WAVE: For generating triangle waves we have incremented the samples from low to high. Once it becomes high we have decremented the samples from high to low. Thus, we have generated the triangle wave forms, which can be easily observed through CRO.

SINE WAVE: For generating the sine wave we have incremented samples up to 64 (40h) and then decremented it to 0 .then we have repeated the same process for –ve part. To understand it more clearly… 1. The total no. of samples are 256.then 128 of them is used for +ve part and the rest of the 128 samples are used for –vet part. 2. Out of those 128 samples the 64th (40h) sample indicates the peak point. There will be two peak points. One for negative and one for positive. So it makes 128 (80h).which is taken as a base value in calculation. 3. We have taken the memory addresses from 00 h to ff h. Then angle. Further we have taken the sine value of that angle and a binary value and finally we have added that binary value in of 80h.the reason for adding it to 80h is that it is the base point 2). EXAMPLE: 1. MEMORY ADDERESS 0ah Find the angle: angle is symboled as a Q Q = (360/256)*memory address Hence memory adderess is 0ah and its decimal value is 10 we have found the then converted it to to the binary value value(refer the

Q = (360/256) *10 = 1.411*10 = 14.11 sinQ = sin (14.11) = 0.243

for bits, 0.243* 128=31 so bits = 0001 1111

base adderess 80h 1000 0000 + 0001 1111= 1001 1111 =9F same way address can be calculated from 00h to ffh.

10.4 Hardware criteria In hardware connection of DAC first we give eight digital input by controller and also vcc and supply.to convert input reference voltage into current r14 resistor is connected and vref(+) is given for positive output voltage. While vref(-) is grounded. At pin 16 compensation capacitor is connected and other end is grounded with vee. Equation:

10.5 Flowchart of program

*******

SECTION-11 HOW TO GENERATE CLOCK USING 555 Timer ?

11.1. Introduction One of the most versatile linear integrated circuits is the 555 timer. The 555 is a monolithic timing circuit that can produce accurate and highly stable time delays or oscillation. The timer basically operates in one of the two modes: either as a mono-stable multivibrator or an astable multivibrator. The device is available as an 8-pin metal can, an 8-pin mini DIP or a 14-pin DIP. FEATURES: 1. It operates on +5V to +18V supply voltage in both free running and monostable modes 2. It has an adjustable duty cycle; timing is from microsecond through hours. 3. It has a high current output; it can source or sink 200mA 4. The output can drive TTL and has a temperature stability of 50 parts per million per degree Celsius change in temperature . 5. Like general-purpose op-amps ,the 555 timer is reliable ,easy to use and low cost. 11.2. Pin Descriptions The 555 timer IC can be used as a monostable multivibrator, an astable multivibrator, and also in FSK demodulator. It is an 8-pin IC, its pin description is given below.

Pin 1 Ground: All voltages are measured with respect to this terminal. . Pin 2 Triggered: The output of the timer depends on the amplitude of the external trigger pulse applied to this pin. Pin3 Output: There are two ways a load can be connected to the output terminal: either between pin3 and ground or between pin3 and Vcc. Pin4 Reset: The 555timer can be reset (disabled) by applying a negative pulse to this Pin. Pin5 Control Voltage: An external voltage applied to this terminal changes the threshold as well as the trigger voltage.

Pin6 Threshold: This is the noninverting terminal of comparator 1, which moniters the voltage across external capacitor. Pin7 Discharge: This pinis connected internally to the collector of the transistor Q1. Pin8 +Vcc: The supply voltage of +5v to +18v is applied to this pin with respect to ground. 11.3. Timing Waveforms Waveform for astable multivibrator

11.4. CALCULATION CHARGING TIME tc: the time during which the capacitor charges from1/3 Vcc 2/3Vcc is equal to the time the output is high and is given by tc = 0.69(RA+RB) C DISCHARGING TIME td: The time during which capacitor discharges from 2/3 to 1/3 Vcc is equal to the time the output is low and is given by td =0.69(RB) C TOTAL TIME : The total period of the output waveform is T = tc + td = 0.69(RA+2RB) C FREQUENCY OF OSCILLATION: the frequency of oscillation is independent of supply voltage Vcc. F0 = 1/T = 1.45/{(RA+2RB) DUTY CYCLE: the duty cycle is the ratio of the time tc during which the output is high to the total time period T. it is generally expressed as a percentage. %duty cycle = (tc/T)*100 = {(RA+RB)/(RA+2RB)}*100 to

*********

SECTION-12 ADC INTERFACING

12.1 ADC General Overview Analog-to-digital converters are among the most widely used devices or data acquisition type of application. Digital computers use binary (discrete) values, but in the physical world everything is analog (continuous). Temperature, Pressure, Light, humidity and velocity are the few examples of physical quantities that we have to deal in our day-to-day life. Therefore we need Analog-to-digital converter to convert real world applications into digital form that digital computers can understand.

The ADC0808, ADC0809 data acquisition component is a onolithic CMOS device with an 8-bit analog-to-digital converter, 8-channel multiplexer and microprocessor compatible control logic, the 8-bit A/D converter uses successive approximation as the conversion technique.. The ADC0808 offers high-Speed, high accuracy, minimal temperature dependence, excellent long-term accuracy and repeatability, and consumes minimal power. These features make this device Ideally suited to applications from process and machine control to consumer and automotive applications. The ADC 0808 is an 8-bit A-to-D converter, having data lines D0-D7. It works on the principle of successive approximation. It has a total of eight analogue input channels, out of which any one can be selected using address lines A, B and C. Here, in this case, input channel IN0 is selected by grounding A, B and C address lines. Usually the control signals EOC (end of conversion), SC (start conversion), ALE (address latch enable) and OE (output enable) are interfaced by means of a. microcontroller.. The ADC 0808 IC requires clock signal of typically 550 kHz, which can be easily derived from 555 timer circuit. Which is explained as above. Features : 1.Easy interface to all microprocessors 2 Operates ratiometrically or with 5 VDC or analog span adjusted voltage ref. 3.No zero full-scale adjust required 4.8-channel multiplexer with address logic 5.0V to VCC input range 6.Outputs meet TTL voltage level specifications Key specification Resolution 8 Bits Total Unadjusted Error ±½ LSB and ±1 LSB Single Supply 5 VDC Low Power 15 mW Conversion Time 100 μs 12.2 pin description: IN0 TO IN7: eight analog input channel A,B,C: selection lines. Eight analog channel is selected by three selection lines. They define address for input. Soc: start of conversion. To start conversion into digital low to high pulse is given. Eoc: end of conversion. To verify completion of conversion check eoc for high status. ALE: address latch enable. To latch the address from address lines low to high pulse is given to ale before starting conversion. Clock: Typically 640 khz clock frequency is given. Clock does not given directly from controller.ADC0808 is not self clocking. The speed of conversion depends on the frequency of clock. It should not be faster than 100 microseconds. Vcc and ground : 5v power supply is given. Vref(+), vref(-): Oe: output enable. To latch 8 bit digital output from buffer low to high pulse is given after end of conversion. So that we get digital output fromeight output pins. 12.3. Timing Diagram:

CONVERSION ANALOG TO DIGITAL: The heart of this single chip data acquisition system is its 8-bit analog-to-

digital converter. The converter is designed to give fast, accurate, and repeatable conversions over a wide range of temperatures. The converter is partitioned into 3 major sections: the 256R ladder network, the successive approximation register, and the comparator. The converter’s digital outputs are positive true. The 256R ladder network approach was chosen over the conventional R/2R ladder because of its inherent monotonicity, which guarantees no missing digital codes.Monotonicity is particularly important in closed loop feedback control systems. A non-monotonic relationship can cause oscillations that will be catastrophic for the system. Additionally, the 256R network does not cause load variations on reference voltage. The bottom resistor and the top resistor of the ladder network are not the same value as the remainder of the network. The first output transition occurs when the analog signal has reached +1⁄2 LSB and succeeding output transitions occur every 1 LSB later up to full-scale. The successive approximation register (SAR) performs 8 iterations to approximate the input voltage. For any SAR type converter, n-iterations are required for an nbit converter. The A/D converter’s successive approximation register (SAR) is reset on the positive edge of the start conversion start pulse. The conversion is begun on the falling edge of the start conversion pulse. A conversion in process will beinterrupted by receipt of a new start conversion pulse. Continuous conversion may be accomplished by tying the end-of-conversion (EOC) output to the SC input. If used in this mode, an external start conversion pulse should be applied after power up. End-of-conversion will go low between 0 and 8 clock pulses after the rising edge of start conversion. In this technique given unknown input voltage vin is compared with a fraction of reference voltage which is taken by lader network.

If vin is greater than the set fraction of Vr the bit is set to 1. If vin is less than set fraction of Vr the bit is set to 0. The fraction is give by ( ∑ bi *2-I ) vref for i=1 to n. As an example, first step unknown voltage is compared with ½ Vref. If Vin ≥ ½ Vref , MSB of output set to 1.in next step Vin is compared with ( ½ b1+ ¼ ) Vref. Where b1 is value of MSB. Thus eight times comparision is done and 8 bits output is stored in buffer one by one bitwise. The most important section of the A/D converter is the comparator. It is this section which is responsible for the ultimate accuracy of the entire converter. It is also the comparator drift which has the greatest influence on the repeatability the device. The chopper-stabilized comparator converts the DC input signal into an AC signal. This signal is then fed through a high gain AC amplifier and has the DC level restored. This technique limits the drift component of the amplifier since the drift is a DC component which is not passed by the AC amplifier. This makes the entire A/D converter extremely insensitive to temperature, long term drift and input offset errors. 12.4 Hardware criteria ADC 0808 is not self locking so we have to give clock externally. For that we use 555 timer because 0808 requires around 500khz clock frequency. From 555 timer ic clock is given to ADC 0808 clock pin. Control signals SOC, EOC, OE, ALE are

connected to 89c51 port pins. Vcc and ground is given from 89c51. to select analog input channel we take 3 switch which are connected to A, B, C address lines and by using these switches particular input is selected. 5v is given to Vref (+) and Vref(-) is grounded.The pins of ADC0808 from 2-1 to 2-8 are the digital outputs. These digital output can be find out using formula: Dout= Vin \ Step size Where Dout =digital data output, Vin= Analog input voltage, and step size and be determine on the basis of Vref and Vin. Step size for various Vin and Vrefis shown in following table: Vref (V) Vin (V) Step Size (mV) Not connected 0 to 5 5/256 =19.53 4.0 0 to 4 4/255 =15.62 3.0 0 to 3 3/256 =11.71 2.56 0 to 2.56 2.56/256 =10 2.0 0 to 2 2/256 = 7.81 1 0 to 1 1/256 =3.90

Figure shows circuit connection of ADC0808 with 89c51.

12.5 Flowchart of program ********

SECTION-13 SENSOR INTERFACING

13.1

Introduction

Transducers convert physical data such as Temperature, light intensity, flow and speed to electrical signal. Depending on the transducers the output produced is in the form of voltage, current, resistance or capacitance. In other term transducers are also called as sensors. We need to convert the output of sensors to voltage in order to send input to an A/D converter. This conversion is commonly called Signal conditioning. Signal conditioning can be current to voltage conversion or may be simply signal amplification. Sensors can be of many kinds such as Temperature sensor, motion sensor, light sensor etc. next section gives you a brief introduction on LM35 Temperature sensor. 13.2 General Description:The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in ° Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The LM35 does not require any external calibration or trimming to provide typical accuracies of ±1.4°C at room temperature and ±3.4°C over a full -55 to +150°C temperature range. Low cost is assured by trimming and calibration at the wafer level. The LM35’s low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws only 60 µA from its supply, it has very low self-heating, less than 0.1°C in still air. It outputs 10mV for each degree of centigrade temperature.

Features:1. 2. 3. 4. 5. 6. 7. 8. 9. Calibrated directly in ° Celsius (Centigrade), Linear + 10.0 mV/°C scale factor, 0.5°C accuracy guaranteeable (at +25°C), Rated for full -55° to +150°C range, Suitable for remote applications, Low cost due to wafer-level trimming, Operates from 4 to 30 volts, Less than 60 µA current drain, Low self-heating, 0.08°C in still air,

13.3. Pin description

Basic Centigrade Temperature Sensor (BOTTOM VIEW) to +150°C)

(+2°C

V OUT=+1,500 mV at +150°C = +250 mV at +25°C = -550 mV at -55°C

Supply Voltage : +35V to -0.2V Output Voltage : +6V to -1.0V Output Current : 10 mA Temp Range. : -55°C to +150°C Lead Temp. : (Soldering, 10 seconds) 260°C 13.4. Hardware connections:

Here +Vs pin of LM35 is provided +5V Vcc, and the output pin is connected to one of the eight inputs of ADC0808. ADC0808 Has a 8-bit resolution with maximum of 256 steps, and Lm35 produce 10mV for every degree of temperature change. We can condition Vin of the ADC0808 to produce a Vout of 2560mV, for Full-scale output. Therefore, to produce a full-scale Vout of 2.56 V for ADC0808, we need to set Vref(+) = 2.56 V. this makes Vout of ADC0808 corresponds directly to the temperature as monitored by LM35. In out Trainer Kit, we use LM35 to sense temperature. This temperature is converted into digital form via ADC0808. Finally, using 89c51 microcontroller these data can be displayed on LCD.

**********

SECTION-14 8255 INTERFACING

14.1 8255 features: In this section we study the 8255 chip, one of the most widely used I/O chips. The 8255 is a 40-pin DIP chip(see figure 14.1). It has three separately accessible ports. The ports are each 8-bit, and are named as A, B, and C. The individual ports of 8255 can be programmed to be input of output, and can be changed dynamically. In addition, 8255 ports have handshaking capability, therby allowing interface with the devices that also have handshaking signals, such as printers. The handshaking capability of 8255 is not discussed since it is no long used. PA0-PA7 The 8-bit port A can be programmed as all input, of as all output, or all bit as bidirectional input/output. PB0-PB7 The 8-bit port B can be programmed as all input or as all output . Port B cannot be used as a bidirectional port.

PC0-PC7 This 8-bit port C can be all input or all output. It can also be split into two parts, CU(upper bits PC4-PC7) and CL(lower bits PC0-PC3). Each can be used for input and output. RD and WR These two active low control signals are the input to 8255 chip. The RD and WR signals from 89c51 are connected to these inputs. D0-D7 data pin The data pins of 8255 are connected to the data pins of the microcontroller allowing it to send data back and forth between the controller and 8255 chip. RESET This is an active-high signal input into the 8255 used to clear the control register. When RESET is activated, all ports are initialized as input ports. In many designs this pin is connected to the RESET output of the system bus of grounded to make it inactive. Like all IC input pins, it should not be left unconnected A0, A1, and CS While CS(chip select) selects the entire chip, it is A0 and A1 that selects specific ports. These three pins are used to access ports A, B, and C or the control register as shown in table 14.1. Note that CS is active-low.

CS 0 0 0 0 1 14.2

A1 0 0 1 1 X

A0 0 1 0 1 X

Selection Port-A Port-B Port-C Control Register 8255 not Selected

Mode selection of 8255

While port A, B and C are used to input or output data it is the control register that must be programmed to select the operation mode of 3 ports. The ports of 8255 can be programmed in any of the following modes 1. MODE-0 Simple I/O mode In this mode any of the port A, B, CL and CU can be programmed as input or output . In these mode all are out or all are in. The vast majority of applications involving 8255 use these I/O mode. 2. MODE-1 In this mode port A and port B can be used as 8-bit input port or 8-bit output port with handshaking capability. Handshaking signals are provided by bits of port C. 3. MODE-2 In this mode port A can be used as a Bi-directional I/O port with handshaking capabilities whose signals are provided by port C. Port B can be used either in simple I/O mode or handshaking Mode-1 4. Bit Set-Reset Mode In this mode only the individual bits of port C can be programmed.

1=I/O Mode Lower 0=BSR Mode 1=Mode 1 0=Output Mode Selection 00=Mode 0 01=Mode 1 1X=Mode 2

Port A 1=Input 0=Output

Mode Selection 0=Mode 0

Port C PC3-PC0 1=Input

Port C Upper PC7-PC4 1=Input 0=Output

Port B 1=Input 0=Output

Figure- 2

8255 CONTROL WORD FORMAT

14.3

Interfacing with 89c51:

Here we used 8255 for the purpose of expanding I/O pins of 89c51 microcontroller. We connect various modules to 8255 port pins due to lack of I/O pins of 89c51, so we just want to convey data between controller and devices. That is why, we have used 8255 in Mode-0 i.e, Simple I/O Mode without Handshaking. Figure shows connection of 8255 with 89c51. Hardware connection: 1. The port of 89c51 which requires expansion is connected to the data pins of 8255 i.e, D0-D7. As shown in figure, here we have connected port p2 of 89c51 to the data lines D0-D7 of 8255. 2. CS (chip Select) of 8255 is active low, so we make it ground.

3. WR and RD signals of 8255 are connected to port pins of 89c51.If we want to use 8255 ports as input we require to make WR signal Low. Similarly for output ports, RD signal is made low. As shown in figure RD and WR is connected to P3.2 and P3.3 of microcontroller. 4. A1-A0 are also connected to 89c51 port pins. This pins are used to select any of the port and control register. Here A1 and A0 are connected to P3.4 and P3.5 respectively.

********

SECTION-15 SERIAL COMMUNICATION

In our project we have established the communication link between two microcontrollers. in serial communication a single data line is used instead of the 8-bit data line of parallel communication. for serial data communication to work ,the byte of data must be converted to serial bit using a parallel-in-serialout shift register; then it can be transmitted over a single data line. This also means that at the receiving end there must be a serial-in-parallel-out shift register to receive the serial data and pack them in to byte.

SERIAL TRANSFER

PARALLAL TRANSFER

METHODS USED IN SERIAL DATA COMMUNICATION: SERIAL data communication uses two methods Asynchronous Synchronous The synchronous method transfers a block of data (characters) at a time, while the asynchronous transfers a single byte at a time. It is possible to write software to use either of this method but the program can be tedious and long. For this reason there are special ic chips are made by manufacturer. DUPLEX TRANSMISSION: In this transmission mode the data can be transferred and received. if data is transmitted one way at a time it is referred to as half duplex. if the data can go both ways at same time it is full duplex. Full Duplex required two wire conductors for the data lines in addition to signal and ground, one for transmission and one for reception, in order to transmit and receive data simultaneously.

FULL DUPLEX HALF DUPLEX SIMPLEX TRANSMISSION: In our project we have used the simplex transfer. In which only transmitter can send and receiver can receive. The data transfer is always one way. At the transmitter side we have connected input device and at the receiver side we have

connected the display, from which output can be observed easily.

SERIAL COMMUNICATION: The data coming in at the receiving end of the data line in a serial data transfer is all 0s and 1s; it is difficult to make sense of the data unless the sender and receiver agree on a set of rules,”protocol”, on how the data is packed, how many bits constitute a character and when data begins and ends. START AND STOP BITS: Asynchronous serial data communication is widely used for character oriented transmission while block oriented transmission use the synchronous method. In asynchronous transmission each character is placed in between start and stop bits. This is called framing. in data framing for synchronous communication the data such as a ASCII characters are packed in between start bit and stop bit. the start is always one bit the stop bit can be one or two bits. the start bit is always 0 and the stop bit is 1.for example, the ASCII characters “A”(0100 0001)is framed between the start bit and a single stop bit. The LSB is sent out first. When there is no transfer the signal is 1 which is referred to as a MARK. The 0 referred to as a space. The transmission begins with a start bit followed by Do, the LSB then rest of the bits until the MSB D7 And finally, the one stop bit indicating the end of character “A”. SERIAL COMMUNICATION: The AT89C51 has two pins that are used specifically for transferring and receiving data serially. These two pins are called TxD and RxD ,they are the part of the port3 group(p3.0 and p3.1). pin 11 of the AT89C51 is assigned to TxD and pin 10 (p3.0) is designated as RxD. This pin is TTL compatible; so if one wants to make it RS232 compatible then they require a line driver. e.g MAX232 chip. In our project we have established the communication link between two microcontrollers. Here one microcontroller works as a transmitter and the other works as a receiver. At the transmitter end we have connected an input device and at the receiver end we have connected the display device. The transfer takes place here is a simplex transmission, in which data transfer always remains one way transfer. Here one has to set the TCON and SCON register and define the baud rate is to set the data transfer rate.

Flowchart of program

********

SECTION-15 TROUBLESHOOTING & TESTING TRAINER KIT

15.1. Testing Trainer Kit. 15.2. Trouble shooting Trainer Kit. 15.1. Testing Trainer Kit 1. One LED and One SWITCH: By making the selection switch position to 0000, One led & One switch Program will be selected and the practical name will be displayed on LCD. Here a single led is connected along with the switch to microcontroller. As the switch has been pressed a led glows. After keeping it on, again the switch has been pressed then the led becomes off.

2.

Four LEDS and Four Switches:

By making the selection switch position to 0001, four leds & four switches program will be selected and the practical name will be displayed on LCD. Here 4 led are connected along with 4 switches to microcontroller. As switch 1 is pressed the first led becomes on. Then as the switch 2 is pressed the second led becomes on. Same with the third and fourth led. Note that, when switch is pressed the only the corresponding LED remains on, While remaining gets off. 3. Eight LEDS and 4×4 Matrix Keyboard:

By making the selection switch position to 0010, Eight leds & Matrix Keyboard program will be selected and the practical name will be displayed on LCD. Here 8 led are connected to microcontroller along with matrix keyboard. As key-0 is pressed all LEDs remains off to show that Key-0 is pressed. Similarly, for key-15, LED1, LED3 and LED5 glows to show that data is 00010101 i.e., key-15. In this manner all keys are detected. 4. Single Seven-segment and 4×4 Matrix Keyboard:

By making the selection switch position to 0011, Single seven segment and 4×4 matrix keyboard program will be selected and the practical name will be displayed on LCD. Here single segment is connected with the keyboard so the number has been displayed according to key pressed. If key 1 is pressed then 1 will be displayed on seven segment. 5. Multiplexed Seven-segment and 4×4 Matrix Keyboard:

By making the selection switch position to 0100, multiplexed seven segments and 4×4 matrix keyboard program will be selected and the practical name will be displayed on LCD. Here two segments have been connected with the key board to microcontroller. Key 1 and key 0 pressed then it shows 10 on the multiplexed seven segments. . 6. EEPROM Write: By making the selection switch position to 0101, EEPROM Write Program has been selected and the practical name will be displayed on LCD. In this case a switch is connected to microcontroller. When the switch is pressed, LCD will display the data written at a particular location e.g. 00H. 7. EEPROM Read: By making the selection switch position to 0110, EEPROM Read Program has been selected and the practical name will be displayed on LCD. In this case also, a switch is connected to microcontroller. When switch is pressed, LCD will display the data which is read out from EEPROM. 8. RTC:

By making the selection switch position to 0111, Real Time Clock Program has been selected and the practical name will be displayed on LCD. In real time clock as we pressed the switch it will shows us the time in terms of second, minute and hour. e.g. 11:30:02 on LCD. 9. 8255:

By making the selection switch position to 1000, 8255 Program will be selected and the practical name will be displayed on LCD. In this case, a switch is given when

the switch is pressed LCD will shows you the data and port p2 which is read off, via 8255 10. ADC0808:

By making the selection switch position to 1001, Analog-Digital conversion program will be selected and the practical name will be displayed on LCD. As the switch is pressed, LCD will display the output of ADC0808. 11. ADC0808 and Temperature Sensor:

By making the selection switch position to 1010, ADC and Temperature sensor program will be selected and the practical name will be displayed on LCD. In these, case the output of temperature sensor is converted into Digital via ADC0808 and is display on LCD. E.g. 38 °C . 12. DAC0808:

By making the selection switch position to 1011, DAC0808 program will be selected and the practical name will be displayed on LCD. Here there are 4 switches from switch0- switch3. As the switch 0 is pressed it gives the analog voltage of given digital data. This data is observed with the help of multimeter. When, Switch 1 is pressed then it shows square wave on CRO. When, Switch 2 is pressed then it shows triangular wave on CRO. And finally when, Switch 3 is pressed then it shows sine wave on CRO. 13. Serial communication:

By making the selection switch position to 1100, Serial communication program will be selected and the practical name will be displayed on LCD. In serial communication whatever has been transferred from the transmitter microcontroller is observed on seven segment at the receiver microcontroller.. 14. Lcd:

Here lcd is connected with all the devices. By using the selection switch the topic which has been selected, is displayed on LCD. If selection switch position is 1011 then it will displays as follows: “TOPIC” “DAC INTERFACING” 15.2 Troubleshooting Trainer kit LED: Once you make led ON and if it doesn’t glow then follow the steps given below for trouble shooting of the circuit. 1. Check the supply and ground are given properly or not 2. Check the anode and cathode connection ,ideally anode is connected with Vcc and cathode with the ground. 3. Check the IC AT89C51 on ic tester.

4. Check the led. and pull up resistor 5. Check the software. Keyboard: Through the key board if you are not able to detect the key then follow the steps given below for trouble shooting of the circuit. 1. check 2. check the supply and ground are given properly or not. the connections of rows and columns

3. Chec the switches. 4. Check the IC AT89C51 5. Check the other devices which are connected with the key board. 6. Check the software seven segment: if you will not get the desired display on seven segment then follow the steps ,given below for trouble shooting of this circuit. 1. check the supply and ground are given properly or not

2.check the anode and cathode of the segment 3.check its connections with the transistor and pull-up resistor. 4.check the segment and its connections 5.check the IC AT89C51. 6.check the other devices which are connected with it. 7.check the software. EEPROM: If you are not able to write and read through the eeprom then follow the steps given below for trouble shooting of the circuit. 1.check the supply and ground are given properly or not.

2.check the connection of all master and slave devices. 3.check all the pin connection of IC24C02 and the IC itself 4.check the IC AT89C51. 5.check the other devices which are connected with the eeprom 6.check the software. LCD: If you won’t get desired display on LCD then follow the steps given below for troubleshooting of the circuit.

1.check the supply and ground are given properly or not. 2.check the lcd and its pin connection. 3.check the IC 8255 4.check the other devices which are connected with it 5.check the IC AT89C51. 6.check the software.

RTC: From an RTC if you are not getting the exact output then folloe the steps given below for trouble shooting of this circuit. 1.check the supply and ground are given properly or not. 2.check the RTC DS1307 and its pin connection . 3.check the other devices which are connected with it. 4.check the IC AT89C51 5.check the software. DAC:

If you are not getting the exact analog waveform through the DAC then follow ,the steps given below for the trouble shooting of the circuit. 1.check the supply and ground are given properly or not. 2.check the pin connections of DAC0808 and also the IC itself. 3.check the other devices ,which are connected with it. 4.check the IC AT89C51. 5.check the software. ADC: If you are not getting the exact digital data through ADC0808 then follow the the steps given below for trouble shooting of this circuit. 1.check the supply and ground are given properly or not. 2.check the ADC0808. and its pin connections.

3.check the other devices which are connected with it. 4.check the IC AT89C51.

5.check the software. Sensor: If you are not able to sense the exact temperature through the LM35 then follow the steps given below for the trouble shooting of this circuit. 1.check the supply and ground are given properly or not. 2.check the LM35 and its connections. 3.check the other devices which are connected with it. 4.check the IC AT89C51. 5.check the software. 8255:

if yor not getting the exact output of the devices which are connected with 8255 then follow the steps given below for the trouble shooting of this circuit. 1 .check the supply and ground are given properly or not. 2.check the 8255 and its connections. 3.check the other devices which are connected with it. 4.check the IC AT89C51. 5.check the software. Serial communication: If you are not able to transmit or receive the through transmitter and receiver then follow the steps given below for the trouble shooting of this circuit. 1 .check the supply and ground are given properly or not. 2.check the transmitter and reciver connections.

3.check the other devices which are connected with it. ******** References and project timeline chart

References: Books: 1. 8051 Microcontroller and Embedded systems- Mazidi. 2. The 8051 Microcontroller- Ayala 3. Embedded systems- Raj Kamal

Websites: 1. 2. 3. 4. www.wikipedia.com www.chip&cheap.com www.digchip.com www.sunrom.com

Project time line chart:

WEEK

1 2 3 4 5 6

7 8 9 10 11 12 13 14 15 16 Activity January Project Understanding Analysis Learning Process Implementing and Designing Testing and developing Final Documentation February March April

*******