Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to build a calculator using Pic16f877 microcontroller

By EG Projects August 18, 2019

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 16×2 character lcd and 4×4 numeric keypad and pic16f877 microcontroller. One should already know about 16×2 lcd working and 4×4 numeric keypad interface with microcontroller before beginning with the project. I have a good tutorial on 16×2 lcd pin out and working. You must first go with this tutorial if you don’t know about 16×2 lcd pin out, working principle and interface with microcontrollers.

16×2 lcd Pin out and Working

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 4×4 numeric keypad and pic microcontroller after manipulating the numbers displays result on 16×2 lcd.

Calculator with pic microcontroller – Working

When you turn on/power the system. A message will be displayed on the 16×2 lcd first row “Enter First No = “. You enter the number. As soon as you enter number it will be displayed on the 16×2 lcd screen. Then a second message will appear on 16×2 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 16×2 lcd. Calculator arithmetic operation result is shown below.

Calculator with pic16f877 microcontroller output

Calculator with pic16f877 microcontroller output

Pic16f877 microcontroller calculator – Project requirements

  • Pic16f877 Microcontroller
  • 16×2 lcd 
  • 4×4 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 16×2 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 build Using Pic16f877a microcontroller - Circuit Diagram

Calculator build Using Pic16f877a microcontroller – Circuit Diagram

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 16×2 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 16×2 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 16×2 lcd.
void disp_num(float num)
This function displays calculated value or output result on 16×2 lcd display efficiently. 
int get_num  (char ch)
This function converts character value to integer. To display integer value on 16×2 lcd it must first be converted in to character format. On 16×2 lcd we can display a character 8-bit value.
void lcdinit ()
This function initializes the character lcd display. 16×2 lcd, font-size 7×5, 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.

More projects about calculators involving different other microcontrollers. Each project is made with 16×2 lcd display, 4×4 keypad and an intelligent unit, the microcontroller. Every project is open source. One can modify and use code according to his/her needs.  

Calculator with 89c51 microcontroller

Calculator with Arduino uno

Download the project files, code(C, Hex) and simulation. Code is written is C Language using MP-LAB IDE and High-tech C compiler is used to compile the code. Simulation is made in Proteaus 8.0. Watch Project Video Below. Plz Give us your feed back on the project.
Watch The Project Video Here…….
Calculator Code

Filed Under: Microcontroller Projects, PIC Microcontroller

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Power Efficiency
Discover proven strategies for power conversion, wide bandgap devices, and motor control — balancing performance, cost, and sustainability across industrial, automotive, and IoT systems.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions.

  • Why is military EMC so strict?
  • Cannot prototype a power supply
  • Phased array antenna never on full power for long?
  • TPS63070 Power Supply
  • Question about resistors values impact on lead reading

RSS Electro-Tech-Online.com Discussions

  • need help in photodetection TIA circuit
  • Need to solder a really delicate ribbon for an electric reel need advice
  • Help please! BLDC driver circuit using the IR2136s and the STP80NF06 MOSFETS
  • Measuring controller current output with a meter
  • Anyone In The US Ordered From AliExpress Recently?

Featured Tutorials

Real Time Hardware Filter Design

  • Practical implementation of bandpass and band reject filters
    Practical implementation of bandpass and band reject filters
  • Practical application of hardware filters with real-life examples
    Practical application of hardware filters with real-life examples
  • A filter design example
    A filter design example
  • Types of filter responses
    Types of filter responses
  • What are the two types of hardware filters?
    What are the two types of hardware filters?
  • What are hardware filters and their types?
    What are hardware filters and their types?
More Tutorials >

Recent Articles

  • Microchip extends single pair Ethernet lineup with software-less endpoint
  • Infineon MCU targets high-voltage BMS in electric vehicles
  • SemiQ releases expanded SiC MOSFET lineup with detailed thermal and switching data
  • TDK adds 1000 W models to dc-dc converter series
  • LEMO introduces resin-free IP68 connectors for compact equipment

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe