Implementation and Design of Calculator
Total Page:16
File Type:pdf, Size:1020Kb
Implementation and Design of Calculator Submitted To: Sir. Muhammad Abdullah Submitted By: Muhammad Huzaifa Bashir 2013-EE-125 Department of Electrical Engineering University of Engineering and Technology, Lahore Contents Abstract ........................................................................................................................................... 2 Introduction ..................................................................................................................................... 3 Input Unit: ................................................................................................................................... 3 Processing Unit: .......................................................................................................................... 3 Output Unit: ................................................................................................................................ 3 Interfacing and Implementation ...................................................................................................... 4 LCD: ........................................................................................................................................... 4 Hardware Interfacing: ............................................................................................................. 4 Problem and Solution of hardware interfacing: ...................................................................... 4 Software Interfacing: .............................................................................................................. 5 Problem and Solution for Software Interfacing: ..................................................................... 5 Keypad Interfacing: .................................................................................................................... 6 Hardware interfacing: ............................................................................................................. 6 Problem and Solution for Hardware Interfacing:.................................................................... 6 Software Interfacing: .............................................................................................................. 6 Data Transmission from Keypad to LCD: .................................................................................. 7 Problem and Solution:............................................................................................................. 7 Data Assembling: ........................................................................................................................ 8 Data Retrieving and Processing: ................................................................................................. 8 Result Display on LCD: .............................................................................................................. 8 Arithmetic Calculator: ................................................................................................................ 8 Scientific Calculator: .................................................................................................................. 8 Trigonometric Calculator: ........................................................................................................... 9 Limitation:................................................................................................................................... 9 Future Aspects .............................................................................................................................. 10 Incorporation of Floating Data: ................................................................................................ 10 Toggle Input: ............................................................................................................................. 10 Graph Plotter: ............................................................................................................................ 10 Bibliography ................................................................................................................................. 11 1 Abstract The report describes the design and implementation of software and hardware of a simple Calculator. The basic purpose of this project is to enhance our learning about the use of Microcontroller through practical demonstration. The basic task of this calculator, as described in proposal, is to get inputs from user through a 4x4 keypad, process that data for arithmetic operations through Tiva TM4C123G Microcontroller and show the input data and results on an LCD. However we had to deviate from interrupt based data acquisition from keypad because we learnt that it would not be a good technique. After successfully completing the proposed task, two other forms of calculators have also been introduced. They are Scientific and Trigonometric Calculators. The report focuses on the successful interference of LCD and Keypad with the microcontroller. Once the interference is done, remaining part is not much difficult. The report also describes the proper coding to implement a simple calculator. Problems faced while making this project have been discussed. Finally the future aspects of this project are also mentioned. 2 Introduction We start with absolutely basic steps. To make any calculation, we need operands, operators and then these are processed to give us the desired results. Now we have to implement all this through a simple calculator. This calculator will have three parts: 1. Input Unit 2. Processing Unit 3. Output Unit Input Unit: In calculator, input unit will be a simple 4x4 keypad. The keypad comprises of 16 switches basically. As soon as one of the switch is closed when the corresponding key is pressed, that key is detected as an input by the processing unit. Processing Unit: The brain of the system will be Tiva 4C123G Microcontroller. Input and output units will be interfaced with this microprocessor and data will be processed by it. The user code will be burnt to it. Output Unit: 20x4 LCD will be used as an output unit. It will represent all our data and results. Various commands are sent to it for its proper functioning and display. 3 Interfacing and Implementation Interfacing of all components with each other is the most important and basic requirement. As we have only LCD and Keypad, there interfacing is discussed one by one. LCD: The interfacing will be discussed in two parts. Hardware Interfacing: LCD Display used has 20x4 display size. It has 16 pins for interfacing. Their names are shown in figure. Hardware interfacing is quite easy. We just have to connect the microcontroller pins to the corresponding terminals of LCD. We can leave the VE pin connectionless because there is no contrast functionality being used. Register Select, Read/Write and Enable are collectively named as Control pins. These pins are responsible for controlling the functionalities of LCD. Then there are seven Data pins. Commands and data is sent through these pins. Then second last pin is for brightness control. It can be set in range from zero to five volts by a variable resistor. Problem and Solution of hardware interfacing: A problem may arise, is that data is not displayed on the LCD. Bright boxes appear in such case. This is because the ground of Microprocessor and LCD will be different. Common ground is essential for correct display of data. 4 Software Interfacing: Correct pin configuration is essential for interfacing. Three pins are allocated for Control purposes. RS pin is set high when data is to be sent. To send any command, it is set to low. Since we are using LCD as output unit so data will always be written to it and is not read from it. Then there is enable pin. Whenever data or command is to be sent, LCD is enabled through this pin. 8 bit data format is followed. Actually one character is sent at a time through its ASCII value. The character is then displayed on the LCD. There are various commands that we can send to perform various tasks such as clear, display on, move cursor to left and many others. They are shown in table as follows. Using these set of commands we can display data properly. The C code for LCD interfacing with TIVA microcontroller is discussed in detail in Course Book. Problem and Solution for Software Interfacing: If proper delays are not set in between the commands, data may not be sent properly. So, some delay is necessary so that data is sent properly. 5 Keypad Interfacing: Keypad interfacing is discussed as follows. Hardware interfacing: There are eight terminals for a 4x4 keypad. First four correspond to rows and next four are columns from left to right. The 16 buttons on keypad are basically 16 switches. When a button is pressed, switch is closed and a high signal is received by the micro controller. We set the columns high one by one. Now if a key is pressed the corresponding row becomes high also as the path gets completed. The intersection of this row and column tells microcontroller which key has been pressed. These rows act as input for microcontroller. In our design we have configured C7-C3 as four rows and PF1, PE2, PA7 and PA6 as four columns for microcontroller. Problem and Solution for Hardware Interfacing: One of the problems is that the keypad is not of good quality therefore sometimes, it is to be pressed quite hard and sometimes only one key is pressed and more than one row get high. Therefore keys are to be pressed carefully. Other problem is that due