0% found this document useful (0 votes)
3 views12 pages

Microcontroller CP

The document presents a course project report on a simple calculator using the 8051 microcontroller, detailing its design, components, and programming. It includes sections on the introduction, circuit diagram, program code, results, applications, and conclusion, emphasizing the educational value of the project in electronics and communication engineering. The project successfully demonstrates basic arithmetic operations and the functionality of interfacing a microcontroller with an LCD display.

Uploaded by

shashankcm0313
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views12 pages

Microcontroller CP

The document presents a course project report on a simple calculator using the 8051 microcontroller, detailing its design, components, and programming. It includes sections on the introduction, circuit diagram, program code, results, applications, and conclusion, emphasizing the educational value of the project in electronics and communication engineering. The project successfully demonstrates basic arithmetic operations and the functionality of interfacing a microcontroller with an LCD display.

Uploaded by

shashankcm0313
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Bapuji Educational Association®

BAPUJI INSTITUTE OF ENGINEERING AND TECHNOLOGY, DAVANGERE


577004

Course Project Report on

SIMPLE CALCULATOR USING 8051


Course: Microcontroller Course Code : BEC405A

Submitted by

4BD23EC114 Uday D R
4BD23EC094 Shashank C M

Dr. G.S. Sunitha Dr. G.S. Sunitha


Course Project Guide Program Coordinator

Department of Electronics & Communication Engineering


2024-2025
Vision of the Department

To be in the forefront in providing quality technical education and research in Electronics &
Communication Engineering to produce skilled professionals to cater to the challenges of the
society.

Mission of the Department

M1: To facilitate the students with profound technical knowledge through effective teaching
learning process for a successful career.

M2: To impart quality education to strengthen students to meet the industry standards and face
confidently the challenges in the programme.

M3: To develop the essence of innovation and research among students and faculty by
providing infrastructure and a conducive environment.

M4: To inculcate the student community with ethical values, communication skills, leadership
qualities, entrepreneurial skills and lifelong learning to meet the societal needs.
Simple Calculator Using 8051 microcontroller

INDEX

Sl. No Content Page No


1 Introduction 2
2 Circuit diagram 4
3 Explanation 4
5 Program 6
6 Results and Discussion 8
7 Applications 9
8 Conclusion 10
9 References 10

Dept of ECE, BIET, Davanagere 1|Page


Simple Calculator Using 8051 microcontroller

Seven Seg control using 8051

1. Introduction

Proteus Software:

Proteus is a comprehensive suite of electronic design automation (EDA) tools used for circuit
simulation, PCB design, and microcontroller simulation. It is widely used by engineers,
designers, and hobbyists for designing and testing circuits before implementing them in
hardware. Developed by Lab centre Electronics, Proteus offers a range of features that make
it a powerful tool for both education and professional projects.

Keil µvision:

Keil µVision, often referred to as Keil µVision or simply Keil, is an integrateddevelopment


environment (IDE) specifically designed for embedded software development. Developed by
Keil, a division of ARM Holdings, it is widely used for programming and debugging
microcontrollers, especially those based on ARM Cortex-M, ARM7, ARM9, and other ARM
architecture processors. The Keil µVision environment combines project management, code
editing, compilation, and debugging in a single application, making it a powerful tool for
embedded developers.

LCD (Liquid Crystal Display)

An LCD (Liquid Crystal Display) is a flat-panel display technology commonly used in


devices such as televisions, computer monitors, calculators, digital clocks, and portable
electronics like smartphones and tablets. LCDs are valued for their low power consumption,
thin profile, and ability to display sharp, high-resolution images.
How LCD Works:
LCDs do not emit light directly. Instead, they use a backlight or reflector to produce visible
images. The screen consists of liquid crystal molecules sandwiched between two polarized
glass layers. By applying varying electrical voltages to these crystals, they twist or align in
ways that either block or allow light to pass through, creating images on the screen.

Dept of ECE, BIET, Davanagere 2|Page


Simple Calculator Using 8051 microcontroller

Key Features:
• Energy Efficient: Uses less power compared to CRT and plasma displays.
• Lightweight and Compact: Ideal for portable devices.
• Sharp Image Quality: Capable of high resolutions and good color reproduction.
• Available in Various Sizes: From small screens on calculators to large TV screens.

Common Types of LCD:


• Twisted Nematic (TN): Fast response time, lower cost.
• In-Plane Switching (IPS): Better color accuracy and viewing angles.
• Vertical Alignment (VA): Good contrast and deeper blacks.
LCD technology continues to be a crucial component in modern electronics due to its

8051 Microcontroller:

The 8051 microcontroller, developed by Intel in 1980, is a widely used 8-bit microcontroller
renowned for its simplicity, versatility, and extensive support in embedded systems.

a. CPU: Handles arithmetic and logical operations, and controls the flow of instructions.
b. Memory:
1. 4KB ROM for program storage.
2. 128 bytes RAM for data storage and temporary variables.
c. I/O Ports: Four 8-bit bidirectional ports (P0 to P3) for interfacing with external devices.
d. Timers/Counters: Two 16-bit timers (Timer 0 and Timer 1) for timing operations and
event counting.
e. Serial Communication: Built-in UART for serial communication with external devices.
f. Interrupts: Five interrupt sources for handling asynchronous events.
g. Oscillator and Clock: Typically uses a 12 MHz crystal oscillator to generate the clock
signal.

Dept of ECE, BIET, Davanagere 3|Page


2. Circuit Diagram:

Circuit Diagram

3. Main Components and Their Connections:

1. Keypad (4x4 Matrix)

• This is a 16-key keypad used to enter digits and operations.

• It has 4 rows (R1-R4) and 4 columns (C1-C4):

o Rows (A–D) are connected to P1.4 to P1.7 of the microcontroller.

o Columns (1–4) are connected to P1.0 to P1.3.

• The microcontroller scans the rows and columns to detect which key is pressed.

2. Microcontroller – AT89C51

• 40-pin microcontroller from the 8051 family.

• Port 1 (P1.0 to P1.7): Used for interfacing with the keypad.

• Port 2 (P2.0 to P2.7): Used for interfacing with the LCD data lines (D0–D7).

• Port 3 (specifically P3.5, P3.6, and P3.7): Used to control LCD pins:

Dept of ECE, BIET, Davanagere 4|Page


o P3.5 (RS) – Register Select

o P3.6 (RW) – Read/Write

o P3.7 (E) – Enable

3. LCD Display (LM016L / 16x2)

• 16x2 LCD means it can display 2 lines of 16 characters.

• Pin mapping to the microcontroller:

o D0–D7 → Connected to P2.0–P2.7 of AT89C51

o RS (pin 4) → P3.5

o RW (pin 5) → P3.6

o E (pin 6) → P3.7

o VSS (pin 1) → Ground

o VDD (pin 2) → +5V

o VEE (pin 3) → Contrast control (usually via a potentiometer)

Working Overview

1. The user presses a key on the keypad.

2. The AT89C51 detects which key was pressed by scanning P1.0–P1.7.

3. Based on the key, it executes logic (e.g., addition).

4. The result is sent to the LCD using Port 2 and control lines on Port 3.

5. The LCD displays the result.

Other Key Pins on AT89C51

• XTAL1/XTAL2 (Pins 18, 19): Connected to a crystal oscillator to provide the clock signal.

• RST (Pin 9): Reset input.

• EA (Pin 31): External Access – typically connected to Vcc to use internal memory.

• PSEN & ALE (Pins 29, 30): Used when interfacing with external memory (not in use
here).

Dept of ECE, BIET, Davanagere 5|Page


Summary

This diagram shows a simple microcontroller-based calculator where:

• A keypad is used to input numbers and operations.

• An LCD is used to display the result.

• The AT89C51 microcontroller reads the input, processes it, and outputs the result to the
display.

4. 8051 C Programe Code

#include <REGX51.H>

#define LCD P2
sbit RS = P3^5;
sbit RW = P3^6;
sbit EN = P3^7;

unsigned char key;


unsigned int num1 = 0, num2 = 0, result = 0;
char op;

// Delay function
void delay_ms(unsigned int ms) {
unsigned int i, j;
for(i=0; i<ms; i++)
for(j=0; j<127; j++);
}

// LCD command
void lcd_cmd(unsigned char cmd) {
LCD = cmd;
RS = 0;
RW = 0;
EN = 1;
delay_ms(1);
EN = 0;
}

// LCD data
void lcd_data(unsigned char dat) {
LCD = dat;
RS = 1;
RW = 0;
EN = 1;
delay_ms(1);
EN = 0;
}

// LCD initialization
void lcd_init() {
lcd_cmd(0x38);
lcd_cmd(0x0C);
lcd_cmd(0x06);
lcd_cmd(0x01);
lcd_cmd(0x80);
}

Dept of ECE, BIET, Davanagere 6|Page


// LCD print string
void lcd_print(char *str) {
while(*str) {
lcd_data(*str++);
}
}

// Keypad scanning
char keypad_scan() {
char keypad[4][4] = {
{'7', '8', '9', '/'},
{'4', '5', '6', 'x'},
{'1', '2', '3', '-'},
{'C', '0', '=', '+'}
};
unsigned char row, col;
P1 = 0xF0;
for(row=0; row<4; row++) {
P1 = ~(0x10 << row);
delay_ms(1);
col = P1 & 0x0F;
if(col != 0x0F) {
if((col & 0x01) == 0) return keypad[row][0];
if((col & 0x02) == 0) return keypad[row][1];
if((col & 0x04) == 0) return keypad[row][2];
if((col & 0x08) == 0) return keypad[row][3];
}
}
return '\0';
}

// Convert integer to string


void int_to_str(unsigned int num, char *str) {
int i = 0, j;
char temp;
if(num == 0) {
str[i++] = '0';
} else {
while(num > 0 && i < 5) {
str[i++] = (num % 10) + '0';
num /= 10;
}
}
str[i] = '\0';
// Reverse the string
for(j=0; j<i/2; j++) {
temp = str[j];
str[j] = str[i-j-1];
str[i-j-1] = temp;
}
}

// Main program
void main() {
char key_press;
lcd_init();
lcd_print("Calc Ready");
delay_ms(1000);
lcd_cmd(0x01); // clear LCD

while(1) {
// Input first number
lcd_cmd(0x80);
num1 = 0;
while(1) {

Dept of ECE, BIET, Davanagere 7|Page


key_press = keypad_scan();
if(key_press >= '0' && key_press <= '9') {
lcd_data(key_press);
num1 = num1 * 10 + (key_press - '0');
delay_ms(300);
} else if(key_press == '+' || key_press == '-' || key_press == 'x' || key_press == '/') {
lcd_data(key_press);
op = key_press;
delay_ms(300);
break;
}
}

// Input second number


num2 = 0;
while(1) {
key_press = keypad_scan();
if(key_press >= '0' && key_press <= '9') {
lcd_data(key_press);
num2 = num2 * 10 + (key_press - '0');
delay_ms(300);
} else if(key_press == '=') {
lcd_data('=');
delay_ms(300);
break;
}
}

// Perform calculation
switch(op) {
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case 'x': result = num1 * num2; break;
case '/':
if(num2 != 0)
result = num1 / num2;
else
result = 0; // handle div by zero
break;
default: result = 0;
}

// Display result
lcd_cmd(0xC0); // second line
if(result == 0 && op == '/' && num2 == 0) {
lcd_print("Error");
} else {
char str[6]; // support up to 5 digits + null
int_to_str(result, str);
lcd_print(str);
}

// Wait for 'C' to clear


while(1) {
key_press = keypad_scan();
if(key_press == 'C') {
lcd_cmd(0x01); // clear LCD
delay_ms(300);
break;
}
}
}
}

Dept of ECE, BIET, Davanagere 8|Page


SIMULATION OF SEVEN SEGMENT DISPLAY

3. Results and Discussion:

3+3=6

Result of the project

Applications:

A simple calculator using the 8051 microcontroller performs basic arithmetic operations like:

• Addition (+)
• Subtraction (-)
• Multiplication (×)
• Division (÷)

Dept of ECE, BIET, Davanagere 9|Page


SIMULATION OF SEVEN SEGMENT DISPLAY

Conclusion

In conclusion, the successful interfacing of a simple calculator with the 8051 microcontroller
demonstrates the ability to display numerical information in a simple and effective manner.
Through the use of assembly level programming and simulation with Proteus software, we
have verified the functionality of the interface and ensured accurate display of numbers. This
project showcases the potential applications of microcontrollers in various fields. The
knowledge gained from this project can be extended to more complex display systems and
real-time applications, making it a valuable learning experience in the field of electronics and
communication engineering.

References

1. Muhammad Ali Mazidi and Janice Gillespie Mazidi and Rollind. The “8051
Microcontroller and Embedded Systems – Using Assembly and C”, Mckinlay; Phi, 2006
/ Pearson, 2006.

2. YOUTUDE: https://youtu.be/t2kC8PHwINg?si=nNYAzI0J5GYQCsYo

Dept of ECE, BIET, Davanagere 10 | P a g e

You might also like