HP 20b RPN Calculator By Jayne (Jay) Shim & SonYon (Sonny) - - PowerPoint PPT Presentation

hp 20b rpn calculator
SMART_READER_LITE
LIVE PREVIEW

HP 20b RPN Calculator By Jayne (Jay) Shim & SonYon (Sonny) - - PowerPoint PPT Presentation

HP 20b RPN Calculator By Jayne (Jay) Shim & SonYon (Sonny) Song ? THE PROCESSOR CAPP1 TDI CAPM1 TDO Charge ICE ARM7TDMI CAPP2 JTAG TMS Pump CAPM2 SCAN Processor TCK VDDINLCD JTAGSEL VDD3V6 LCD VDDLCD System


slide-1
SLIDE 1

HP 20b  RPN Calculator

By Jayne (Jay) Shim & SonYon (Sonny) Song

slide-2
SLIDE 2
slide-3
SLIDE 3

 ?

slide-4
SLIDE 4

THE PROCESSOR

TDI TDO TMS TCK NRST FIQ IRQ0-IRQ1 PCK0-PCK2 PMC Peripheral Bridge Peripheral Data Controller AIC PLL SRAM 2 Kbytes( Back-up) 4 Kbytes (Core) ARM7TDMI Processor ICE JTAG SCAN JTAGSEL PIOA (26 IOs) Timer Counter NPCS0 NPCS1 NPCS2 NPCS3 MISO MOSI SPCK Flash 64/128 Kbytes DRXD DTXD TCLK0 TCLK1 TCLK2 TIOA0 TIOB0 TIOA1 TIOB1 TIOA2 TIOB2 Memory Controller Abort Status Address Decoder Misalignment Detection PIO PIO APB Embedded Flash Controller AD0 AD1 AD2 AD3 ADTRG 11 Channels PDC PDC SPI PDC ADC ADVREF TC0 TC1 TC2 TWD TWCK TWI XIN XOUT VDDIO1 PWMC PWM0 PWM1 PWM2 PWM3 1.8 V Voltage Regulator GND VDDOUT VDDCORE VDDIO1 VDDCORE Fast Flash Programming Interface ERASE PGMD0-PGMD15 PGMNCMD PGMEN0-PGMEN2 PGMRDY PGMNVALID PGMNOE PGMCK PGMM0-PGMM3 VDDIO2 TST DBGU PDC PDC PIO PIT WDT System Controller VDDIO1 SAM-BA ROM (12 Kbytes) NRSTB FWUP PIOB (24 IOs) LCD Controller SEG00-SEG39 COM0-COM9 PIOC (30 IOs) 32k RCOSC Supply Controller POR OSC BOD 2 MHz RCOSC VDDIO1 RTC USART0 RXD0 TXD0 SCK0 RTS0 CTS0 PDC PDC USART1 RXD1 TXD1 SCK1 RTS1 CTS1 DCD1 DSR1 DTR1 RI1 PDC PDC PIO PDC PDC VDDLCD CAPP1 CAPM1 CAPP2 CAPM2 CLKIN PLLRC VDD3V6 LCD Voltage Regulator VDDIO2 Charge Pump VDDINLCD
slide-5
SLIDE 5

Liquid Crystal Display (LCD)

slide-6
SLIDE 6

The Keyboard

 Keyboard Matrix Keyboard connected to processor 

slide-7
SLIDE 7
slide-8
SLIDE 8

12 x 3 = 36 12 ÷ 3 = 4 ERROR

slide-9
SLIDE 9
  • 1. ENTER “1”
  • 3. INPUT

12 x 3 = 36

  • 2. ENTER “2”

12

12

slide-10
SLIDE 10

12 x 3 = 36

  • 4. Enter “3”

3

12 3

slide-11
SLIDE 11

12 x 3 = 36

  • 5. MULT “×”

 36

36

slide-12
SLIDE 12

What about...

a complex complex expression? expression?!

slide-13
SLIDE 13
  • 1. Enter “2”

  • 2. INPUT

((2 + 3) × 5) × 6

2

2

slide-14
SLIDE 14
  • 3. Enter “3”

((2 + 3) × 5) × 6

2

3

3

slide-15
SLIDE 15
  • 4. ADD “+”

((2 + 3) × 5) × 6

5

5

slide-16
SLIDE 16

((2 + 3) × 5) × 6

  • 5. Enter “5”

5

5 5

slide-17
SLIDE 17
  • 6. MULT “×”

((2 + 3) × 5) × 6

25

25

slide-18
SLIDE 18

((2 + 3) × 5) × 6

  • 7. Enter “6”

25

6

6

slide-19
SLIDE 19
  • 8. MULT “×”

((2 + 3) × 5) × 6

150

150

slide-20
SLIDE 20
slide-21
SLIDE 21

Empty Stack

ERROR: ERROR: EMPTY EMPTY STACK STACK

  • 1. MULT “×”
slide-22
SLIDE 22

OTHER USEFUL KEYS

slide-23
SLIDE 23

Backspace ()

Press Backspace “”

7

slide-24
SLIDE 24

Sign (+⁄−)

Press Sign “+⁄−”

7

  • 7
slide-25
SLIDE 25

Getting Started: Hello World

#include "AT91SAM7L128.h“ #include "lcd.h" int main() { int number = 999 ; int digit; int lcdIndex = 11; / lcd_init(); if (number > 999999999 || number < -999999999) { lcd_put_char7('O', 0); lcd_put_char7('V', 1); lcd_put_char7('E', 2); lcd_put_char7('R', 3); lcd_put_char7('F', 4); lcd_put_char7('L', 5); lcd_put_char7('O', 6); lcd_put_char7('W', 7); }

slide-26
SLIDE 26

Getting Started: Hello World

else { if (number > 0) { while (number > 0) { digit = number % 10; number = number / 10; lcd_put_char7(digit+48, lcdIndex); lcdIndex--; } } else if (number == 0) { lcd_put_char7(48, lcdIndex); } else if (number <0) { while (number < 0) { digit = number % 10; digit = digit*-1; number = number / 10; lcd_put_char7(digit+48, lcdIndex); lcdIndex--; } if (number == 0) { lcd_put_char7(45, 0); } } } return 0; }

slide-27
SLIDE 27

Listening to the Keyboard

const char keyboard_layout [7][6] = {{'N', 'I', 'P', 'M', 'F', 'A'}, {'C', 'R', 'N', 'B', '%', 'L'}, {'T', '(', ')', 'G', '<', '_'}, {'U', '7', '8', '9', '/', '_'}, {'D', '4', '5', '6', '*', '_'}, {'S', '1', '2', '3', '-', '_'}, {'O', '0', '.', '=', '+', '_'}};

slide-28
SLIDE 28

Listening to the Keyboard

char keyboard_key() { int column; int row; char button; for (column = 0; column <= COLUMN; column++) { keyboard_column_low(column); for (row = 0; row <= ROW; row++) { if(!keyboard_row_read(row)) { keyboard_column_high(column); button = keyboard_layout[column][row]; return button; } } keyboard_column_high(column); } return 0; }

slide-29
SLIDE 29

Listening to the Keyboard

int main() { for (;;) { char key = keyboard_key(); if (key != 0) { for(j = 0; j < 14; j++) { lcd_put_char7(' ',j); } lcd_put_char7(key,11); } else { lcd_print7("no key pressed"); } } return 0; }

slide-30
SLIDE 30

Entering and Displaying Numbers

void keyboard_get_entry(struct entry *result) { int input = 0; int counter = 0; int sign = 1; for (;;) { int c = keyboard_key(); if (c <= '9' && c >= '0') { input = input * 10 + (c - '0'); counter++; } else if (c == '~') { sign *= -1; } else if (c == '\b') { input /= 10; if(input == 0) lcd_put_char7(' ', 11); } else if (c != -1){ result->operation = c; break; }

slide-31
SLIDE 31

Entering and Displaying Numbers

while (c != -1) { c = keyboard_key(); } if (input != 0) lcd_print_int_neg(sign == -1, input); } if (counter == 0) { result->number = INT_MAX; } else { result->number = sign*input; } }

slide-32
SLIDE 32

Entering and Displaying Numbers

int main() { struct entry entry; *AT91C_WDTC_WDMR = AT91C_WDTC_WDDIS; lcd_init(); keyboard_init(); lcd_print7("PRESS"); while (1) { keyboard_get_entry(&entry); if (entry.operation != 0 && entry.number! =INT_MAX) { lcd_print_int(entry.number); lcd_put_char7(entry.operation, 0); entry.operation = 0; } } return 0; }

slide-33
SLIDE 33

An RPN Calculator

void calculate(char operation, int index, int *stack) { if (index < 0) { lcd_print7("ERROR"); } else { int n1 = stack[index]; int n2 = stack[index+1]; switch (operation) { case '+': stack[index] = n1 + n2; break; case '-': stack[index] = n1 - n2; break; case '*': stack[index] = n1 * n2; break; case '/': stack[index] = n1 / n2; break; } stack[index+1] = 0; lcd_print_int (stack[index]); } }

slide-34
SLIDE 34

An RPN Calculator

int main(){ int stack [50]; int index = 0; while (1) { keyboard_get_entry(&entry); if (entry.operation != 0 && entry.number!=INT_MAX) { stack[index] = entry.number; lcd_print_int(entry.number); if (entry.operation == '\r') { index++; } else if (entry.operation == '+' || entry.operation == '-' || entry.operation == '*' || entry.operation == '/') { index--; calculate(entry.operation, index, stack); index++; } } else if (entry.operation == '+' || entry.operation == '-' || entry.operation == '*' || entry.operation == '/') { if (index >= 2) { index = index - 2; calculate(entry.operation, index, stack); index++; } else { lcd_print7("ERROR"); } } } }