Project report - Electrical4study.com

Transcription

Project report - Electrical4study.com
Project report
LCD BASED SCIENTIFIC CALCULATOR
(Using ATMEGA16 Microcontroller)
SUBMITTED TO:
Muhammad Usman Aslam
SUBMITTED BY:
Umar Iqbal
Muhammad Usman
REGISTRATION NO:
(2010-EE-591)
(2010-EE-596)
RACHNA COLLEGE OF ENGINEERING & TECHNOLOGY
GUJRANWALA
Table of contents
1. DESCRIPTION………………………………………………………………….
2. COMPONENTS……………………………………………................................
ATMEGA16 Microcontroller………………………………………..
Pin Description………………………………………………………
14X2 LCD……………………………………………………………
3. CIRCUIT DIAGRAM……………………………………………………………
4. WORKING……………………………………………………………………….
5. PROBLEM FACED………………………………………………………………
6. PROGRAM TO MAKE A SCIENTIFIC CALCULATOR………………………
Electrical4study.com
ACKNOWLEDGEMENT
To complete our this lcd based scientific calculator project we got help from a famous site
electrical4study.com. From this site we get the main idea of our project and also helpful material
related to our project. We also got help from our project in charge Muhammad UsmanAslam.
Who helped us to resolve our all problems regarding this project.
ABSTRACT
Our project is a LCD based Scientific Calculator. We made this project using ATMEGA16
microcontroller.At first chance we faced many problems. First was its trouble shooting and after
running it on Proteous then there came a problem when we implement it on the bread board. We
were unable to set its time. It took a long time to reduce this problem. After all we succeed in
implementation of this project in hard form. Now it is properly working.
Description
A scientific calculator is one that displays result on LCD. This project displays result on a 14x2
LCD module. The LCD is interfaced withmicrocontroller ATMEGA16. This circuit is used to
many mathematical problems as shown on proteus diagram.
Components Used
Micro Controller
The AVR is a modified Harvard architecture8-bitRISC single chip microcontroller which was
developed by Atmel in 1996. The AVR was one of the first microcontroller families to use onchip flash memory for program storage. The size of the program memory is usually indicated in
the naming of the device itself (e.g., the ATmega64x line has 64 kB of flash while the
ATmega32x line has 32 kB). Therefore our project IC (Atmagea16) has 16KB of flash
In 40 pin AT89C51, there are four ports designated as P1, P2, P3 and P0. All these ports are 8-bit
bi-directional ports, i.e., they can be used as both input and output ports. Except P0 which needs
external pull-ups, rest of the ports have internal pull-ups. When 1s are written to these port pins,
they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit
addressable and so their bits can also be accessed individually.Port P0 and P2 are also used to
Electrical4study.com
provide low byte and high byte addresses, respectively, when connected to an external memory.
Port 3 has multiplexed pins for special functions like serial communication, hardware interrupts,
timer inputs and read/write operation from external memory. ATmega16 has an inbuilt UART
for serial communication. It can be programmed to operate at different baud rates. Including two
timers & hardware interrupts, it has a total of six interrupts.
Electrical4study.com
Pin Configuration:
LCD (Liquid Crystal Display)
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of
applications. A 14x2 LCD display is very basic module and is very commonly used in various
devices and circuits. These modules are preferred over seven segments and other multi segment
LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of
displaying special & even custom characters (unlike in seven segments), animations and so on.
A 14x2 LCD means it can display 14 characters per line and there are 2 such lines. In this LCD
each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command
and Data.
The command register stores the command instructions given to the LCD. A command is an
instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the
cursor position, controlling display etc. The data register stores the data to be displayed on the
LCD. The data is the ASCII value of the character to be displayed on the LCD.
Electrical4study.com
Pin Description
Electrical4study.com
Circuit diagram
Electrical4study.com
WORKING
This calculator works with 25 different tasks and is configured by programming the
microcontroller ATmega16.
The connections in the circuit are as following: port P2 of microcontroller is used as data input
port which is connected to data pins (7-14) of LCD. P3^0, P3^1 and P3^6 pins of microcontroller
are connected to control pins RS, RW and EN of LCD. P1^0, P1^1, P1^2 and P1^3 pins of
microcontroller are connected to tactile switches to take manual inputs.
PROBLEMS FACED
At first chance we faced many problems. First was its trouble shooting. After running it on
Proteous there came a problem when we implement it on the bread board. We were unable to set
it. It took a long time to reduce this problem.
Program to make a scientific calculator
Electrical4study.com
#include <mega16.h>
#include <delay.h>
#include <lcd.h>
#include <stdlib.h>
#include <math.h>
#asm
.equ __lcd_port=0x18
#endasm
//#############################################
int key(void);
float _Main(void);
voidMohandes(void);
voidMohasebe(void);
voidAlamat(int,int);
floatEmoji(int);
//#############################################
float a = 0 , b = 0 , c = 0 , q , t;
int i ;
char y=0 , lcd[25] , z ;
//#############################################
void main(void){
DDRB=0x0F;
DDRC=0x07;
Electrical4study.com
DDRD=0x0F;
lcd_init(16);
while (1){
_Main();
}
}
//#############################################################
float _Main(void){
int Loop = 1 ;
y = key();
if( y == 15 ){a = 0 ;b = 0 ;c = 0 ;lcd_clear();return 0 ;}
if( y < 10 )
{
a = (a*10)+y ;
itoa(y , lcd);
lcd_puts(lcd);
delay_ms(50);
}
if( y > 9 && y < 16 )
{
if( y == 15 ){a = 0 ;b = 0 ;c = 0 ;lcd_clear();return 0 ;}
z=y;
Alamat(y,1);
while(Loop){
Electrical4study.com
y = key();
if( y == 15 ){a = 0 ;b = 0 ;c = 0 ;lcd_clear();return 0 ;}
if( y < 10 )
{
b = (b*10)+y ;
itoa(y , lcd);
lcd_puts(lcd);
delay_ms(50);
}
else if(y == 14)
{
lcd_putchar('=');
Mohasebe();
y=0;
Loop = 0 ;
}
}
}
if( y > 15 ){
lcd_clear();
a= 0 ; b = 0 ; c = 0;
Alamat(y , 2);
z=y;
Loop = 1 ;
while(Loop){
Electrical4study.com
y = key();
if( y == 15 ){a = 0 ;b = 0 ;c = 0 ;lcd_clear();return 0 ;}
if(y < 10){
a = (a*10) + y ;
itoa(y , lcd);
lcd_puts(lcd);
delay_ms(50);
}else if ( y == 14){
lcd_putchar('=');
Mohandes();
}
Loop = 1 ;
}
}
return 0;
}
//##########################################################
voidMohasebe(void){
if(z == 10)c = a / b ;
if(z == 11)c = a * b ;
if(z == 12)c = a - b ;
if(z == 13)c = a + b ;
ftoa(c , 3 , lcd);
lcd_puts(lcd);
delay_ms(100);
Electrical4study.com
}
//#########################################################
floatEmoji(intrr){
q=1;
for(i=0;i<rr;i++)q = q * 2.71728 ;
return q;
}
//#########################################################
voidMohandes(void){
t = (3.1415926535897932384626433832795/180)*a ;
if(z == 16)c = sin(t) ;
if(z == 17)c = cos(t) ;
if(z == 18)c = tan(t) ;
if(z == 19)c = 1/tan(t) ;
if(z == 20)c = asin(t) ;
if(z == 21)c = acos(t) ;
if(z == 22)c = log(a) ;
if(z == 23)c = sqrt(a) ;
if(z == 24)c = Emoji(a) ;
ftoa(c , 3 , lcd);
lcd_puts(lcd);
delay_ms(100);
}
//#########################################################
voidAlamat(intMoji,intHalat){
Electrical4study.com
if(Halat == 1){
if(Moji == 10)lcd_putchar('/') ;
if(Moji == 11)lcd_putchar('*') ;
if(Moji == 12)lcd_putchar('-') ;
if(Moji == 13)lcd_putchar('+') ;
delay_ms(100);
}
if(Halat == 2){
if(Moji == 16)lcd_putsf("Sin ") ;
if(Moji == 17)lcd_putsf("Cos ") ;
if(Moji == 18)lcd_putsf("Tan ") ;
if(Moji == 19)lcd_putsf("Cot ") ;
if(Moji == 20)lcd_putsf("aSin") ;
if(Moji == 21)lcd_putsf("aCos") ;
if(Moji == 22)lcd_putsf("Log ") ;
if(Moji == 23)lcd_putsf("Sqrt ") ;
if(Moji == 24)lcd_putsf("exp ") ;
delay_ms(100);
}
}
//#########################################################
int key(void){
char KEY = 1 ;
while(KEY){
Electrical4study.com
PORTD.0 = 1 ;
PORTD.1 = 0 ;
PORTD.2 = 0 ;
PORTD.3 = 0 ;
if(PIND.4 == 1){return 7 ; KEY = 0;delay_ms(50);}
if(PIND.5 == 1){return 8 ; KEY = 0;delay_ms(50);}
if(PIND.6 == 1){return 9 ; KEY = 0;delay_ms(50);}
if(PIND.7 == 1){return 10; KEY = 0;delay_ms(50);}
//==========================================
PORTD.0 = 0 ;
PORTD.1 = 1 ;
PORTD.2 = 0 ;
PORTD.3 = 0 ;
if(PIND.4 == 1){return 4 ; KEY = 0;}
if(PIND.5 == 1){return 5 ; KEY = 0;}
if(PIND.6 == 1){return 6 ; KEY = 0;}
if(PIND.7 == 1){return 11; KEY = 0;}
//==========================================
PORTD.0 = 0 ;
PORTD.1 = 0 ;
PORTD.2 = 1 ;
PORTD.3 = 0 ;
if(PIND.4 == 1){return 1 ; KEY = 0;}
if(PIND.5 == 1){return 2 ; KEY = 0;}
Electrical4study.com
if(PIND.6 == 1){return 3 ; KEY = 0;}
if(PIND.7 == 1){return 12; KEY = 0;}
//==========================================
PORTD.0 = 0 ;
PORTD.1 = 0 ;
PORTD.2 = 0 ;
PORTD.3 = 1 ;
if(PIND.4 == 1){return 15; KEY = 0;}
if(PIND.5 == 1){return 0 ; KEY = 0;}
if(PIND.6 == 1){return 14; KEY = 0;}
if(PIND.7 == 1){return 13; KEY = 0;}
//===================================================================
==========
PORTC.0 = 1 ;
PORTC.1 = 0 ;
PORTC.2 = 0 ;
if(PINC.5 == 1){return 16 ; KEY=0;}
if(PINC.6 == 1){return 17; KEY=0;}
if(PINC.7 == 1){return 18 ; KEY=0;}
//=====================================================
PORTC.0 = 0 ;
PORTC.1 = 1 ;
PORTC.2 = 0 ;
Electrical4study.com
if(PINC.5 == 1){return 19 ; KEY=0;}
if(PINC.6 == 1){return 20 ; KEY=0;}
if(PINC.7 == 1){return 21 ; KEY=0;}
//=====================================================
PORTC.0 = 0 ;
PORTC.1 = 0 ;
PORTC.2 = 1 ;
if(PINC.5 == 1){return 22 ; KEY=0;}
if(PINC.6 == 1){return 23 ; KEY=0;}
if(PINC.7 == 1){return 24 ; KEY=0;}
KEY = 1 ;
}
}
//############################################################
Electrical4study.com