Microcontroller CP
Microcontroller CP
Submitted by
4BD23EC114 Uday D R
4BD23EC094 Shashank C M
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.
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
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:
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.
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.
Circuit Diagram
• The microcontroller scans the rows and columns to detect which key is pressed.
2. Microcontroller – AT89C51
• 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:
o RS (pin 4) → P3.5
o RW (pin 5) → P3.6
o E (pin 6) → P3.7
Working Overview
4. The result is sent to the LCD using Port 2 and control lines on Port 3.
• XTAL1/XTAL2 (Pins 18, 19): Connected to a crystal oscillator to provide the clock signal.
• 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).
• The AT89C51 microcontroller reads the input, processes it, and outputs the result to the
display.
#include <REGX51.H>
#define LCD P2
sbit RS = P3^5;
sbit RW = P3^6;
sbit EN = P3^7;
// 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);
}
// 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';
}
// 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) {
// 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);
}
3+3=6
Applications:
A simple calculator using the 8051 microcontroller performs basic arithmetic operations like:
• Addition (+)
• Subtraction (-)
• Multiplication (×)
• Division (÷)
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