EXPERIMENT NO. 01 CALCULATOR USING PIC16F877

Similar documents
/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

Write LED display data, in accordance with the address from the display from low to high, from low to high data byte operation.

Lecture (09) PIC16F84A LCD interface LCD. Dr. Ahmed M. ElShafee

LABORATORY MANUAL EMBEDDED SYSTEMS LABORATORY. M. Tech I Year I Sem R15 DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.

LCD. Configuration and Programming

// sets the position of cursor in row and column

LCDs. Embedded Systems Interfacing. 20 September 2011

Lab 3 LCD Mar

Experiment 9: Using HI-TECH C Compiler in MPLAB

EXPERIMENT NO. 02 ELECTRONIC VOTING MACHINE USING 8051.

Lecture (04) PIC 16F84A programming I

Chapter 11: Interrupt On Change

Input/Output Ports and Interfacing

Texas Instruments Microcontroller HOW-TO GUIDE Interfacing Keypad with MSP430F5529

SURE. electronics. Demo Board for LCD Character Module User's Guide Sure Electronics Inc. DE-LD007_Ver1.0

Dragon12 LCD Displays Hantronix_CLD.PDF data sheet (Dragon12 CD-ROM) Dragon12 LCD Display. The Dragon12 board has a 16 character x 2 line display

The EE 109 LCD Shield

6.1. EE 109 Unit 6. LCD Interfacing

Chapter 9. Input/Output (I/O) Ports and Interfacing. Updated: 3/13/12

CHAPTER 1 - World of microcontrollers

ME 6405 Introduction to Mechatronics

Lecture (03) PIC16F84 (2)

Dragon12 LCD Displays Hantronix_CLD.PDF data sheet (Dragon12 CD-ROM) Dragon12 LCD Display. The Dragon12 board has a 16 character x 2 line display

Dragon12 LCD Displays Huang Sections 7.8 Hantronix_CLD.PDF data sheet (Dragon12 CD-ROM) ATD_10B8C Block User Guide. Dragon12 LCD Display

EE 361L Digital Systems and Computer Design Laboratory

The EE 109 LCD Shield

ECE Homework #10

EMBEDDED HARDWARE DESIGN. Tutorial Interfacing LCD with Microcontroller /I

Reprinted by permission of T&L Publications Inc. Copyright 2001 USB MICROCONTROLLERS FOR THE MASSES

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

MicroToys Guide: PS/2 Mouse N. Pinckney April 2005

PIC 16F84A programming (II)

Hong Kong Institute of Vocational Education Digital Electronics & Microcontroller. 8. Microcontroller

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

Embedded Systems Lab Lab 1 Introduction to Microcontrollers Eng. Dalia A. Awad

Team 8: Robert Blake Craig Goliber Alanna Ocampo

LABORATORY MANUAL Interfacing LCD 16x2, Keypad 4x4 and 7Segment Display to PIC18F4580

ECE2049 Homework #2 The MSP430 Architecture & Basic Digital IO (DUE Friday 9/8/17 at 4 pm in class)

ELCT501 Digital System Design Winter Tutorial #11 FPGA Complete Design Flow with LCD Example

Q1 Q2 Q3 Q4 Q5 Q6 Total /7.5 /5 /10 /5 /7.5 /5 /40

Lecture (04) PIC16F84A (3)

Timer1 Capture Mode:

BME 4900 Page 1 of 2. Meeting 2: Personal Progress Report 12/2/09 Team 12 with Drew Seils. Semester One Week Two

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

FACULTY OF ENGINEERING LAB SHEET

LCD03 - I2C/Serial LCD Technical Documentation


Accurate Time and Interrupts

MICROPROCESSORS A (17.383) Fall Lecture Outline

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

Laboratory 10. Programming a PIC Microcontroller - Part II

How to use LCD screen from the application board v2

Page 1 of 7. Samtron/Samsung 20S204DA2

The modules in this lab room are 4 line by 16 character display modules. The data sheet/users manual for the module is posted on My.Seneca.

Getting Started in C Programming with Keil MDK-ARM Version 5

HOURS SYLLABUS

Chapter Two MIPS Arithmetic

Using Timers of Microchip PIC18F Microcontrollers

Getting Started in C Programming with Keil MDK-ARM Version 5

ECE 4510/5530 Microcontroller Applications Week 7

Appendix A: Rack Specification Sheet

EECE.3170: Microprocessor Systems Design I Spring 2016

Start a New Project with Keil MDK-ARM Version 5 and ST Micro Nucleo-F446RE

The University of Texas at Arlington Lecture 5

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

MEPCO SCHLENK ENGINEERING COLLEGE, SIVAKASI. Department of Electronics and Communication Engineering COURSE INSTRUCTION MANUAL

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

The University of Texas at Arlington Lecture 7

Programming (1.0hour)

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

Figure 1: Pushbutton without Pull-up.

Kpad. Technical Manual

Lab 5: LCD and A/D: Digital Voltmeter

Real Time Operating Systems Application Board Details

Human Response Timer

Getting Started in C Programming with Keil MDK-ARM Version 5

CHAPTER 12 LCD AND KEYBOARD INTERFACING

Lab Report for Sensor Calibration using a PIC16F84 GROUP MEMBERS ALFRED MAZHINDU SIMBARASHE CHIWESHE

MPLAB SIM. MPLAB IDE Software Simulation Engine Microchip Technology Incorporated MPLAB SIM Software Simulation Engine

DEV-1 HamStack Development Board

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

MICROCONTROLLER SYSTEM CONTROL DESIGN JON PRITCHARD SCOTT VON THUN

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

Assembly Language Instructions

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interfacing External Devices using Embedded C Module No: CS/ES/22

Application Note - PIC Source Code v1.1.doc

{ int i,j; for(i=0;i<count;i++) for(j=0;j<1275;j++); }

Agenda. PicoBlaze Hello World project using the PicoBlaze. Class 9 Copyright 2011 Greg Tumbush Ver 1.0 1

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */

LCD05 datasheet 1.0

PIC 28 Pin Board Documentation. Update Version 5.0

EEE111A/B Microprocessors

Lab 5: LCD and A/D: Digital Voltmeter

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING B.ENG (HONS) ELECTRICAL AND ELECTRONIC ENGINEERING EXAMINATION SEMESTER /2016

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

I2C interface Tutorial

EECE.3170: Microprocessor Systems Design I Summer 2017

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

Transcription:

EXPERIMENT NO. 01 CALCULATOR USING PIC16F877 DOP: DOS: Project Members: 1) Prasad Pawaskar 58 2) Vishal Thakur 72 Page No.- 1

AIM: To implement basic calculator functionality using PIC microcontroller (PIC16F877) Tools: Keil uvision 4, ISIS Proteus 7 Theory: A calculator is a simple device used to perform basic as well as complex operations of arithmetic. The most basic calculator includes algorithms and/or hardware to implement at the minimum, addition, subtraction, multiplication and division. This PIC microcontroller tutorial provides a simple calculator implementation for PIC16F877 microcontroller. This is a simple one digit calculator which implements only 4 functions addition(+), subtraction(-), multiplication(x) and division(/). PIC 16F877 is one of the most advanced microcontroller from Microchip. This controller is widely used for experimental and modern applications because of its low price, wide range of applications, high quality, and ease of availability. It is ideal for applications such as machine control applications, measurement devices, study purpose, and so on. The PIC 16F877 features all the components which modern microcontrollers normally have. Algorithm:1) Initialize keypad and LCD display. 2) Introduce delay for first number from keypad and display the result of LCD. 3) Introduce delay for getting function key and wait for second number and then equal sign. 4) According to the desired Function result is calculated and displayed on the screen. Code: // Code of the Calculator #include "Includes.h" /* Pin configuration * RA0 = Enable pin for LCD Page No.- 2

* RA1 = CLK pin for LCD * RA2 = Data pin for LCD * PORTB = Keypad pins */ // Config word CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF); // Main function void main(void) char key; // Key char for keeping record of pressed key int num1 = 0; // First number char func = '+'; // Function to be performed among two numbers int num2 = 0; // Second number InitKeypad(); // Initialize Keypad InitLCD(); // Initialize LCD while(1) //get numb1 key = GetKey(); ClearLCDScreen(); // Clear LCD screen WriteDataToLCD(key); // Echo the key pressed to LCD num1 = get_num(key); // Get int number from char value, it checks for wrong input as well if(num1!=error) // If correct input then proceed, num1==error means wrong input //get function key = GetKey(); WriteDataToLCD(key); //Echo the key pressed to LCD func = get_func(key); //it checks for wrong func if(func!='e') //if correct input then Page No.- 3

proceed, func=='e' means wrong input //get numb2 key = GetKey(); WriteDataToLCD(key); //Echo the key pressed to LCD num2 = get_num(key); //Get int number from char value, it checks for wrong input as well if(num2!=error) //if correct input then proceed, num2==error means wrong input //get equal sign key = GetKey(); WriteDataToLCD(key); //Echo the key pressed to LCD if(key == '=') //if = is pressed then proceed switch(func) //switch on function case '+': disp_num(num1+num2); break; case '-': disp_num(num1-num2); break; case 'x': disp_num(num1*num2); break; case '/': disp_num(num1/num2); break; else //key other then = here means error wrong input if(key == 'C') //if clear screen is pressed then clear screen and reset ClearLCDScreen(); // Clear LCD screen else DispError(0); //Display Page No.- 4

wrong input error * Functions used inside main for * making calculator are shown below int get_num(char ch) //convert char into int int num = 0; switch(ch) case '0': num = 0; break; case '1': num = 1; break; case '2': num = 2; break; case '3': num = 3; break; case '4': num = 4; break; case '5': num = 5; break; case '6': num = 6; break; case '7': num = 7; break; case '8': num = 8; break; case '9': num = 9; break; case 'C': ClearLCDScreen(); num = Error; break; //this is used as a clear screen and then reset by setting error default: DispError(0); num = Error; break; //it means wrong input return num; char get_func(char chf) //detects the errors in inputted function if(chf=='c') //if clear screen then clear the LCD and reset Page No.- 5

ClearLCDScreen(); return 'e'; //clear display if( chf!='+' && chf!='-' && chf!='x' && chf!='/' ) //if input is not from allowed funtions then show error DispError(1); return 'e'; return chf; //function is correct so return the correct function void DispError(int numb) //displays differet error messages ClearLCDScreen(); //clear display switch(numb) case 0: WriteStringToLCD("Wrong Input"); break; case 1: WriteStringToLCD("Wrong Function"); break; default: WriteStringToLCD("Wrong Input"); break; void disp_num(int numb) //displays number on LCD unsigned char UnitDigit = 0; //It will contain unit digit of numb unsigned char TenthDigit = 0; //It will contain 10th position digit of numb if(numb<0) numb = -1*numb; // Make number positive WriteDataToLCD('-'); // Display a negative sign on LCD Page No.- 6

TenthDigit = (numb/10); // Findout Tenth Digit if( TenthDigit!= 0) // If it is zero, then don't display WriteDataToLCD(TenthDigit+0x30); // Make Char of TenthDigit and then display it on LCD UnitDigit = numb - TenthDigit*10; WriteDataToLCD(UnitDigit+0x30); // Make Char of UnitDigit and then display it on LCD //LCD Display: #include "Includes.h" void ToggleEpinOfLCD(void) LCD_E = 1; // Give a pulse on E pin delay_us(e_delay); // so that LCD can latch the LCD_E = 0; // data from data bus delay_us(e_delay); void WriteByteToLCD(unsigned Byte) unsigned char BitCount = 0; for(bitcount=0;bitcount<8;bitcount++) LCD_D = (((Byte>>BitCount)&0x1)!=0); value // Write bit LCD_CLK = 1; // Toggle Clock pin to transfer it delay_us(10); LCD_CLK = 0; delay_us(10); void WriteCommandToLCD(unsigned char Command) Page No.- 7

WriteByteToLCD((Command&0xF0)>>4); // Write Upper nibble WriteByteToLCD(Command&0x0F); // Write Lower nibble void WriteDataToLCD(char LCDChar) WriteByteToLCD(((LCDChar&0xF0)>>4) 0x80); // Write Upper nibble WriteByteToLCD((LCDChar&0x0F) 0x80); // Write Lower nibble oid InitLCD(void) // Firstly make all pins output LCD_E = 0; // E = 0 LCD_D = 0; // D = 0 LCD_CLK = 0; // CLK = 0 LCD_E_Dir = 0; // Make Output LCD_D_Dir = 0; // Make Output LCD_CLK_Dir = 0; // Make Output ///////////////// Reset process from datasheet ////////////// delay_ms(40); WriteByteToLCD(0x03); delay_ms(6); WriteByteToLCD(0x03); Page No.- 8

delay_us(300); WriteByteToLCD(0x03); delay_ms(2); WriteByteToLCD(0x02); delay_ms(2); /////////////// Reset Process End //////////////// WriteCommandToLCD(0x28); //function set WriteCommandToLCD(0x0c); //display on,cursor off,blink off WriteCommandToLCD(0x01); //clear display WriteCommandToLCD(0x06); //entry mode, set increment void ClearLCDScreen(void) // Clear the Screen and return cursor to zero position WriteCommandToLCD(0x01); // Clear the screen delay_ms(2); // Delay for cursor to return at zero position void WriteStringToLCD(const char *s) while(*s) WriteDataToLCD(*s++); //Keypad : #include "Includes.h" // Function name: InitKeypad void InitKeypad(void) PORTB = 0x00; // Set PORTB pin values zero TRISB = 0xF0; // PORTB4 to PORTB7 pins input, PORTB0 to PORTB3 pins output // Enable weak internal pull up on input pins Page No.- 9

OPTION_REG &= 0x7F; // Function name: READ_SWITCHES // Scan all the keypad keys to detect any pressed key. char READ_SWITCHES(void) RowA = 0; RowB = 1; RowC = 1; RowD = 1; //Test Row A if (C1 == 0) delay_ms(250); while (C1==0); return '7'; if (C2 == 0) delay_ms(250); while (C2==0); return '8'; if (C3 == 0) delay_ms(250); while (C3==0); return '9'; if (C4 == 0) delay_ms(250); while (C4==0); return '/'; RowA = 1; RowB = 0; RowC = 1; RowD = 1; //Test Row B if (C1 == 0) delay_ms(250); while (C1==0); return '4'; if (C2 == 0) delay_ms(250); while (C2==0); return '5'; if (C3 == 0) delay_ms(250); while (C3==0); return '6'; if (C4 == 0) delay_ms(250); while (C4==0); return 'x'; RowA = 1; RowB = 1; RowC = 0; RowD = 1; //Test Row C if (C1 == 0) delay_ms(250); while (C1==0); return '1'; if (C2 == 0) delay_ms(250); while (C2==0); return '2'; if (C3 == 0) delay_ms(250); while (C3==0); return '3'; if (C4 == 0) delay_ms(250); while (C4==0); return '-'; RowA = 1; RowB = 1; RowC = 1; RowD = 0; //Test Row D if (C1 == 0) delay_ms(250); while (C1==0); return 'C'; if (C2 == 0) delay_ms(250); while (C2==0); return '0'; if (C3 == 0) delay_ms(250); while (C3==0); return '='; if (C4 == 0) delay_ms(250); while (C4==0); return '+'; return 'n'; // Means no key has been pressed // Function name: GetKey // Read pressed key value from keypad and return its value char GetKey(void) // Get key from user Page No.- 10

char key = 'n'; // Assume no key pressed while(key=='n') // Wait untill a key is pressed key = READ_SWITCHES(); // Scan the keys again and again return key; value Output : //when key pressed then return its Conclusio n: Thus, a basic Calculator was simulated using Proteus with the help of Keil. The results were visually verified using the Run feature in Proteus. Page No.- 11