Introduction: TIVA Based Digital Calculator
Hi There,
This is Tahir Ul Haq bringing you another tiva based project.
This project is aimed at making an LCD based Digital Calculator performing various functions.
A Calculator is an electronic device which will evaluate various mathematical expressions and calculations. The calculator of this particular project was designed using Tiva TM4c1233GXL micro-controller. The calculator first gives the user various operations to be performed. The user selects the particular operation to be performed, enters the desired arguments and the calculator evaluates the operation and displays the result on the LCD Screen. This particular calculator can perform the following operations:
Arithmetic Functions.
Trigonometric Functions.
Conversion of numbers between different bases.
Evaluation of Infix Expressions
Factorial of a number
Calculation of the nth power of a number.
Step 1: Components Required:
Here are the components required for the Project:
Tiva TM4C1233GXL:
An ARM based microcontroller which can perform various jobs and processes. These
processes must be defined by the user in the form of a code, in either C language or Assembly Language. The code is written using Keil Software. Keil Software converts the corresponding code into Machine Code and downloads it in the flash memory of the Tiva Microcontroller. The code can then be run on the microcontroller.
LCD Display:
An LCD Display of 20x4 characters was used to display the output of this project. The LCD Display was directly interfaced to the Tiva microcontroller. It will output any data fed to it on its data lines.
Keypad:
A Keypad of 4x4 dimensions was used. The Keypad in total contains 16 keys, each of which can be used to send a particular input to the microcontroller as required by the user.
This is a simple coding based project that requires minimum hardware components but a lot of programming depending on how much advanced calculator you want.
Step 2: Procedure
LCD Interfacing:
An LCD contains the following pins:
1. Vdd : The supply voltage of the LCD. 5V DC is supplied from the Tiva Microcontroller to this pin to turn on the LCD.
2. Vss : The Ground Connection of the LCD. It is connected to the ground.
3. Vcc : The Contrast Control Pin. Its sets the contrast for the display.
4. R/W pin: This pin is used to select between the Read and Write Option of the LCD. When this pin is made logic low, a write operation is performed and data is sent from the microcontroller to the LCD using the D0-D7 pins. When this pin is set high, a read operation is performed and data is sent from the LCD to the microcontroller using the D0-D7 pins on the LCD.
5. Register Select pin: This pin is used to select whether we desire to send some data to the LCD to display or we desire to perform some command on the LCD. Various commands can be performed on the LCD including clear display, cursor movement, or turning the display on/off. When this pin is set high, a write operation will send data onto the data register for displaying on the LCD. When this pin is set low, a write operation will send some LCD specific command to be performed on the LCD.
6. Enable Pin: This pin is used to enable the LCD. It is operated on the rising edge of a pulse. When data is fed onto the data lines and the R/W pin set, application of a short pulse will result in data being sent to the LCD.
7. Data pins: These 8 pins are used as a bus to send or receive data between the microcontroller and the LCD. In its default configuration, the LCD is programmed is send data using a data width of 8 bits. However, to save pins on the Tiva Microcontroller, it can also be programmed to send 8 bits using two 4 bit data transfer.
The following steps are performed to interface an LCD:
1. LCD Initialization:
Before use, the LCD module needs to be configured and initialized.
The four steps of initialization are:
a) Function setting: This sets the data bus width selection, number of display lines and the display font type
b) Display and Cursor Control: This command is used to turn the display and cursor on/off.
c) Entry Mode Setting: It allows us to enable cursor movement and display shift.
d) Clearing of display: Clears the display by using 0x01 command to the LCD module.
2. LCD Write Operation:
To perform a write operation to the LCD, send the data onto the data lines. Then the R/W pin and the RS pins are set to logic low. A pulse is then applied on the Enable Pin to send the data on the data lines which is displayed on the LCD Screen.
Keypad Interfacing:
The 4x4 keypad consists of 4 rows and 4 columns. Each row and column has a separate pin which is connected to separate pin on the Tiva Microcontroller. A Key Press is detected using Polling Based Method. Initially, all the rows and columns are logic high. Each row is made logic low one by one. And the corresponding column which is made logic low, by a key press, is detected. The detected row and column numbers are scanned in the array which return the corresponding number entered assigned to the pressed key
Step 3: Operations:
This calculator can perform various arithmetic operations which are:
1. Binary operations:
Addition, subtraction, multiplication or division of two numbers.
2. Stopwatch:
Count up timer which can keep track of time as required. Reset operation of stopwatch is also included.
3. Trigonometric Functions:
Calculate the sine, cosine and tangent of the given angle in degrees. It can also calculate the reciprocal of the said functions
4. Miscellaneous Functions:
These include calculation of the nth power of a number, calculation of the factorial of a number and base conversions.
5. Evaluation of Infix Expressions:
Calculate long infix expressions which include the functions of addition, subtraction, multiplication and division.
Step 4: Project Design:
The micro-controller is places in a box after making connections and the LCD and the Keypad is placed outside the box for operation.
For LCD control pins PA5, PA6 and PA7 pins of the icro-controller are used.
For the LCD interfacing Port B pins are used for the pins D0-D7 of the LCD. Details are in the images attached.
For Keypad interfacing Port C pins are used for rows and Port F pins are used for the columns. For complete understanding of the interfacing you can go through the slides attached here.
Attachments
Step 5: Coding:
All the project codes have been coded in Keil Microvision 4, which can be downloaded from the website of Keil.
For complete understanding of various lines of code, you are encouraged to go through the datasheet of the micro-controller at http://www.ti.com/lit/ds/symlink/tm4c123gh6pm.pdf
Step 6: Special Thanks:
My special thanks to the project members for sharing their project details with me.
Qasim Elahi, Ansar Rasool, Abdullah Usman Khan, Asad Ali
Department of Electrical Engineering
University of Engineering & Technology Lahore, Pakistan
.
.
Hope to bring some more even sooner!!! Take care :)
Thanks and Regards
Tahir Ul Haq(UET Lahore)