In this presentation we will go over exactly what it took for us to - - PowerPoint PPT Presentation

in this presentation we will go over exactly what it took
SMART_READER_LITE
LIVE PREVIEW

In this presentation we will go over exactly what it took for us to - - PowerPoint PPT Presentation

In this presentation we will go over exactly what it took for us to attempt to build a calculator from the ground up. Our calculators user guide The hardware platform The software we implemented All numbers Basic


slide-1
SLIDE 1
slide-2
SLIDE 2

In this presentation we will go over exactly what it took for us to attempt to build a calculator from the ground up.

ž Our calculator’s user guide ž The hardware platform ž The software we implemented

slide-3
SLIDE 3
slide-4
SLIDE 4

ž All numbers ž Basic operators ž Power ž INPUT ž Backspace

slide-5
SLIDE 5

Reverse Polish notation (RPN): Operators follow operands

ž 3+5à3 5 + ž 10*8à10 8 *

slide-6
SLIDE 6

1 1 1 1 1 2 2

1 + 1

slide-7
SLIDE 7

15 15 15 5 5 3 3

slide-8
SLIDE 8

7 1 6 18 3 7 3 7 1 3 3 6 3 3 18

slide-9
SLIDE 9
slide-10
SLIDE 10
slide-11
SLIDE 11
slide-12
SLIDE 12
slide-13
SLIDE 13

ž lcd_init() ž lcd_put_char7(char ch, int col) ž lcd_print7(const char *c) ž lcd_print_int_neg(int negative,

unsigned int n)

ž lcd_print_int(int n)

slide-14
SLIDE 14
slide-15
SLIDE 15

ž Keyboard_init() ž Keyboard_column_high(int column) ž Keyboard_column_low(int column) ž Keyboard_row_read(int row)

slide-16
SLIDE 16
slide-17
SLIDE 17
  • 1. Lab 4 first makes use of lab 3 so that the user

may enter numbers and operations

  • 2. Lab 3 then makes use of lab 2 in order to go

through the key board and see what is actually being pressed

  • 3. Lab 4 then gets the results from lab 3 and

decodes the resultrs in order to see what to with the number

  • 4. Finally lab 4 makes use of lab 1 in order to
  • utput the result

LAB 4 LAB 2 LAB 3 LAB 1

slide-18
SLIDE 18

ž

#include "AT91SAM7L128.h"

ž

#include "lcd.h"

ž

#define SCREEN 12

ž

#define INT_MAX 2147483647

ž

void clear() //clears the screen

ž

{

ž

int i=0;

ž

while(i < SCREEN) {

ž

lcd_put_char7(' ',i);

ž

i++;

ž

}

ž

}

ž

int main()

ž

{

ž

lcd_init();

ž ž

int num = 2147483646; //integer to be outputted

ž

int newnum = num;

ž

int i=0;

ž

clear();

ž

if(num == 0)

ž

lcd_put_char7('0',0); //displays '0' if the integer is 0

ž

else if (num >= INT_MAX || num*-1 >= INT_MAX) {

ž

lcd_put_char7('E',0); //displays error message

ž

lcd_put_char7('R',1);

ž

lcd_put_char7('R',2);

ž

lcd_put_char7('o',3);

ž

lcd_put_char7('R',4);

ž

}

ž

else {

ž

if(num < 0) { //displays negative sign, increments counter

ž

num = abs(num);

ž

newnum = abs(newnum);

ž

lcd_put_char7('-',0);

ž

i++;

ž

}

ž

while(newnum > 0) { //counts number of digits in integer

ž

newnum = newnum/10;

ž

i++;

ž

}

ž

while(num > 0) { //displays the integer

ž

char thing = num%10 + '0';

ž

lcd_put_char7(thing,i-1);

ž

num=num/10;

ž

i--;

ž

}

ž

}

ž

return 0;

ž

}

slide-19
SLIDE 19

ž

#include "AT91SAM7L128.h"

ž

#include "lcd.h"

ž

#include "keyboard.h"

ž ž

#define KEYBOARD_COLUMNS 0x7f

ž

#define KEYBOARD_ROWS 0x400fc00

ž

#define NOTHING -1

ž

#define COLUMNS 7

ž

#define ROWS 6

ž

#define TENS 10

ž ž

const unsigned char keyboard_row_index[] = {11,12,13,14,15,26};

ž ž

void keyboard_init();

ž

void keyboard_column_high(int column);

ž

void keyboard_column_low(int column);

ž

int keyboard_row_read(int row);

ž ž

int keyboard_key()

ž

{

ž

int i, j;

ž ž

for (i = 0; i < COLUMNS; i++) //cycles through columns

ž

{

ž

keyboard_column_low(i); //sets each test column low

ž

for(j = 0; j < ROWS; j++) //cycles through rows

› if(!keyboard_row_read(j)) //checks each row for pressed //button ž

{

– keyboard_column_high(i); ž

return (i*TENS)+j; //returns an integer with the

ž

//column as the tens value

ž

//and row as the ones value

ž

}

ž

keyboard_column_high(i); //resets test column to high

ž

}

ž

return NOTHING; //returns constant if nothing

ž

//is pressed

ž

}

ž ž

char what_pressed(int col,int row) //takes in the tens place and

ž

//remainder of key_pressed

ž

{

ž

char layout[COLUMNS][ROWS]={ //layout of the calculator as array

ž

{'A','B','C','D','E','F'},

ž

{'G','H','I','J','K','L'},

ž

{'M','N','O','P','Q',' '},

ž

{'R','7','8','9','/',' '},

ž

{'S','4','5','6','*',' '},

ž

{'T','1','2','3','-',' '},

ž

{'Z','0','.','=','+',' '}};

ž

return layout[col][row]; //returns character for key pressed

ž

}

ž

slide-20
SLIDE 20

ž

void keyboard_get_entry(struct entry *result)

ž

{

ž

int counter = -1;

ž

int num = INT_MAX;

ž

int pressed = -1;

ž

int isnegative = 0;

ž ž

for(;;)

ž

{

ž

while(keyboard_key() == -1);

ž

pressed = keyboard_key();

ž

while(keyboard_key() != -1);

ž ž

counter++;

ž ž

if(counter>11)

ž

return;

ž ž

else if(pressed >= '0' && pressed <= '9')

ž

{

ž

lcd_put_char7(pressed,counter);

ž

if( (counter == 0) || (isnegative == 1) )

ž

num=0;

ž

num = num*10 + (pressed-'0');

ž

}

ž

else if((pressed == '-') || (pressed == '+') || (pressed == '*') || (pressed == '/') || (pressed == '\r') || (pressed == '='))

ž

{

ž

lcd_put_char7(pressed,counter); – if (isnegative == 1) {

ž

result->number = num * -1;

ž

result->operation = pressed;

ž

return;

ž

}

ž

if (counter == 0 && pressed == '-') {

ž

isnegative = 1;

ž

}

ž ž

else {

ž

result->number = num;

ž

result->operation = pressed;

ž

return;

ž

}

ž

}

ž

else if(pressed == '\b')

ž

{

ž

lcd_put_char7(' ',counter-1);

ž

counter = counter - 2;

ž

num = num/10;

ž

}

ž

} }

slide-21
SLIDE 21

Plan

  • 1. Use keyboard_entry
  • 2. Have a limit within our while statement that allows for three or four number

to be saved within our “stack”

  • 3. As the numbers and operations are entered we will perform those

Operations

  • 4. We will re-write a function similar to that in lab 1 which will output the final

sum of the users inputs.

  • 5. Also like lab 1 we will have to have tests for “special cases”

Overall Will mainly just be connecting the pieces of the past three labs and it will most definitely be completed before the deadline.

slide-22
SLIDE 22