Calculator
description
Transcript of Calculator
![Page 1: Calculator](https://reader036.fdocuments.in/reader036/viewer/2022083006/56813e27550346895da807f4/html5/thumbnails/1.jpg)
Calculator
9S12DP256
Lab 2
![Page 2: Calculator](https://reader036.fdocuments.in/reader036/viewer/2022083006/56813e27550346895da807f4/html5/thumbnails/2.jpg)
\ 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](https://reader036.fdocuments.in/reader036/viewer/2022083006/56813e27550346895da807f4/html5/thumbnails/3.jpg)
\ 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](https://reader036.fdocuments.in/reader036/viewer/2022083006/56813e27550346895da807f4/html5/thumbnails/4.jpg)
\ 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](https://reader036.fdocuments.in/reader036/viewer/2022083006/56813e27550346895da807f4/html5/thumbnails/5.jpg)
: 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 ;