Calculator with Pic 16f877 microcontroller is a comprehensive project. Comprehensive in the way that code is lengthy and logical. It will be hard for newbies to understand the code and circuit components interface with pic microcontroller. I will try to explain each and every thing about code and circuit thoroughly. The project covers all the aspects of programming and interfacing of 16x2 character lcd and 4x4 numeric keypad and pic16f877 microcontroller. One should already know about 16x2 lcd working and 4x4 numeric keypad interface with microcontroller before beginning with the project. I have a good tutorial on 16x2 lcd pin out and working. You must first go with this tutorial if you don't know about 16x2 lcd pin out, working principle and interface with microcontrollers.
What pic microcontroller calculator offers?
I am going to build a 2-Digit calculator with pic microcontroller. Four functions addition, subtraction, multiplication and division(+,-,/,*) can be performed on single digit numbers using the calculator made with pic microcontroller. User Inputs the numbers and operator using 4x4 numeric keypad and pic microcontroller after manipulating the numbers displays result on 16x2 lcd.
Calculator with pic microcontroller - Working
When you turn on/power the system. A message will be displayed on the 16x2 lcd first row "Enter First No = ". You enter the number. As soon as you enter number it will be displayed on the 16x2 lcd screen. Then a second message will appear on 16x2 lcd first row asking to "Enter Operator = ". You entered the operator. Then a third message will prompt up saying "Enter Second No= ". You entered the second number. When you are done with entering the second number. Result will be displayed on 16x2 lcd. Calculator arithmetic operation result is shown below.
Pic16f877 microcontroller calculator - Project requirements
- Pic16f877 Microcontroller
- 16x2 lcd
- 4x4 keypad
- Crystal 20 MHz
- Potentiometer/variable resistor (For setting Lcd Contrast)
- Bread board or PCB for Circuit Designing
- Power Supply
Two digit calculator with pic microcontroller - Circuit diagram
Lcd data pins are connected to Port-B of PIC16f877 Microcontroller. Lcd Controlling pins RS(Register Select) and EN(Enable) are connected to Port-D Pin# 6 & 7. Keypad is interfaced with Port-C of pic microcontroller. Rows of keypad are connected to lower nibble of Port-C. Coulombs are connected to upper nibble of Port-C. Apply 5 volts at VDD & VCC Pins of microcontroller and 16x2 lcd display. Ground VSS Pins of pic microcontroller and lcd display. Crystal is connected to Pin# 13 & 14 of PIC16f877 microcontroller. Circuit diagram of pic microcontroller calculator project is given below.
Calculator using pic microcontroller - Project code
Code portion is little bit difficult. But if you are familiar with syntax of C++ language and did some good work in c++ then the code below is easy for you to understand and to modify. First htc.h header file is included in the project. This header file must be included in every project that is using HIGH-TECH C compiler for compiling the code. Since i am using HIGH-TECH C compiler so i included it. Then the statement _XTAL_FREQ 20e6 is defining our crystal frequency. Which is 20 MHz. Next i defined Port-C & D pins for 16x2 lcd and keypad interface. Each port pin is also given a meaning full name. After that some functions are defined. Then some strings are defined. These strings are displayed on 16x2 lcd display. The strings are used to communicate with the user.
Functions which are part of pic microcontroller calculator code
void main()
Main Function the heart of the code. Main function executes first. All other functions executes after it.
void lcdcmd (unsigned char)
This function sends commands and controls lcds registers to execute the command properly.
void lcddata (unsigned char)
This function sends data to lcd display and controls lcds registers to display data on 16x2 lcd.
void disp_num(float num)
This function displays calculated value or output result on 16x2 lcd display efficiently.
int get_num (char ch)
This function converts character value to integer. To display integer value on 16x2 lcd it must first be converted in to character format. On 16x2 lcd we can display a character 8-bit value.
void lcdinit ()
This function initializes the character lcd display. 16x2 lcd, font-size 7x5, cursor blinking etc.
char scan_key(void)
This functions checks which keypad key is pressed by the user.
Each and every Statement of the code is well commented. Go through the code and if you feel any problem in any statement just leave your queries in the comments section below.
Main Function the heart of the code. Main function executes first. All other functions executes after it.
void lcdcmd (unsigned char)
This function sends commands and controls lcds registers to execute the command properly.
void lcddata (unsigned char)
This function sends data to lcd display and controls lcds registers to display data on 16x2 lcd.
void disp_num(float num)
This function displays calculated value or output result on 16x2 lcd display efficiently.
int get_num (char ch)
This function converts character value to integer. To display integer value on 16x2 lcd it must first be converted in to character format. On 16x2 lcd we can display a character 8-bit value.
void lcdinit ()
This function initializes the character lcd display. 16x2 lcd, font-size 7x5, cursor blinking etc.
char scan_key(void)
This functions checks which keypad key is pressed by the user.
Each and every Statement of the code is well commented. Go through the code and if you feel any problem in any statement just leave your queries in the comments section below.
Project Code
Download the project code from the links given at the bottom of the Post.
More projects about calculators involving different other microcontrollers. Each project is made with 16x2 lcd display, 4x4 keypad and an intelligent unit, the microcontroller. Every project is open source. One can modify and use code according to his/her needs.
No comments:
Post a Comment