Calculator

5
Calculator 9S12DP256 Lab 2

description

Calculator. 9S12DP256 Lab 2. \ Convert counted string at addr1 to double number ud2 \ ud1 normally zero to begin with \ addr2 points to first invalid character : >NUMBER ( ud1 addr1 -- ud2 addr2 ). ptr. kbuf. \Calculator (add) LOAD lcd256.whp LOAD keypad12.whp - PowerPoint PPT Presentation

Transcript of Calculator

Page 1: Calculator

Calculator

9S12DP256

Lab 2

Page 2: Calculator

\ Convert counted string at addr1 to double number ud2\ ud1 normally zero to begin with\ addr2 points to first invalid character

: >NUMBER ( ud1 addr1 -- ud2 addr2 )

\ Calculator (add)LOAD lcd256.whpLOAD keypad12.whp VARIABLE ptrVARIABLE firstVARIABLE kbuf20 ALLOT : init ( -- )

kbuf ptr !SPI.INITinit.keylcd.initTRUE first ! ;

kbufptr

Page 3: Calculator

\ Convert counted string at addr1 to double number ud2\ ud1 normally zero to begin with\ addr2 points to first invalid character

: >NUMBER ( ud1 addr1 -- ud2 addr2 )

kbuf

ptr

: display ( n -- )first @ \ if first digitIF init \ clear display FALSE first !THENhex2ascDUP >data8 \ display digit1 ptr +! \ update ptr ptr @ C! ;

313233

Enter decimal number 123

Page 4: Calculator

\ Convert counted string at addr1 to double number ud2\ ud1 normally zero to begin with\ addr2 points to first invalid character

: >NUMBER ( ud1 addr1 -- ud2 addr2 )

kbuf

ptr

313233

 : enter ( n -- d )

DROPptr @ kbuf - \ get no. of charskbuf C! \ make counted string1 ptr +!0 ptr @ C! \ make asciiz string0 0 kbuf \ convert ascii string>NUMBER DROP \ to double numberTRUE first ! ;

Press E

3

0

Page 5: Calculator

: add ( d1 n -- d2 )clear.lcdenterD+ 2DUP(D.) type.lcd ;

 : calc ( -- )

initBEGIN wait.for.keyup getkey DUP 14 = \ E key IF enter ELSE DUP 10 = \ A key IF add ELSE DUP 12 = \ C key IF init ELSE display THEN THEN THENAGAIN ;