in this presentation we will go over exactly what it took
play

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


  1. 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

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

  3. Reverse Polish notation (RPN): Operators follow operands ž 3+5 à 3 5 + ž 10*8 à 10 8 *

  4. 1 + 1 1 1 1 1 1 2 2

  5. 15 15 5 15 5 3 3

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

  7. ž 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 )

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

  9. LAB 4 LAB 3 LAB 1 LAB 2 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 output the result

  10. #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; ž } ž

  11. #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 ž } ž ž

  12. 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; ž } ž } ž }

  13. 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.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend