OVERVIEW Wrote f firmware f for a an H n HP 2 20b c calc - - PowerPoint PPT Presentation
OVERVIEW Wrote f firmware f for a an H n HP 2 20b c calc - - PowerPoint PPT Presentation
OVERVIEW Wrote f firmware f for a an H n HP 2 20b c calc lcula lator, a , allo llowing ng i it t to d displa lay y user i input a and nd p process i inf nforma mation n Worked w with a h and nd u und nderstood
OVERVIEW
- Wrote f
firmware f for a an H n HP 2 20b c calc lcula lator, a , allo llowing ng i it t to d displa lay y user i input a and nd p process i inf nforma mation n
- Worked w
with a h and nd u und nderstood t the he C C p programmi mming ng la lang nguage
- Went
nt f from mo m modifyi ying ng a a s simple le me metho hod ( (lc lcd_p _put_c _cha har7) t to worki king ng w with c h cont ntrol s l structures, s , structs, a , and nd p point nters
- Ins
Instead o
- f s
simply le ly learni ning ng t the he s synt yntax o
- f C
C i in a n a t traditiona nal l cla lassroom s m setting ng, w , we le learne ned ho how t to u use C Computer S Scienc nce to a affect s society ( y (i.e .e. a . alt lter w wha hat a a w widely ly-u
- used d
device d does)
- Took o
k our f first s step i in b n build lding ng a appli lications ns
- Series o
- f t
thr hree la lab e experime ment nts t tha hat t took u k us f from m und nderstand nding ng d displa lay, t , to u und nderstand nding ng ho how a a k keyb yboard works ks, t , to mo modifyi ying ng t the he b beha havior o
- f t
the he c calc lcula lator
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
HOW RPN CALCULATORS WORK
- The
he c calc lcula lator i is a an R n RPN c calc lcula lator, w , whi hich s h stand nds f for R Reverse Poli lish N h Notation. n.
- You c
can r n represent nt a anyt ythi hing ng ma mathe hema matically w lly with- o h- out u using ng parent nthe heses a and nd b by s y saving ng k keys
- ystrokes. T
. The he s style yle o
- f a
an R n RPN calc lcula lator, ho , however, i , is no not c convent ntiona nal. l.
- Whe
hen e n ent ntering ng c computations ns, y , you mu must p put i in t n the he f first nu nume merical l valu lue a and nd t the hen p n press IN INPUT
- UT. T
. The hen y n you e ent nter a a s second nd v valu lue a and nd an o n operation. T
- n. The
he r result lt i is y you g get a an e n evalu luated ma mathe hema matical l
- expression. T
- n. Thu
hus, p , putting ng i in a n a 5 5, IN , INPUT UT, 6 , 6, + , + w will r ll return a n a v valu lue o
- f
- 11. T
. Thi his i is c count nter-i
- int
ntuitive t to u us b because w we w want nt t to d do 5 5, + , +, 6 , 6, , =. H . However, t , thi his i is a actually mo lly more e efficient nt. .
- For c
comple lex s situations ns li like e evalu luating ng ( (3 + + 5 5)/(7 + + 6 6), y , you w would ld divide t the hem i m int nto s sub-e
- expressions
ns a and nd t the hen d n divide t the he t two s sub- expressions ns a at t the he v very e y end
- nd. S
. So y you w would ld e ent nter a a s sequenc nce o
- f
comma mmand nds i ident ntical t l to 3 3, IN , INPUT UT, 5 , 5, + , +, 7 , 7, IN , INPUT UT, 6 , 6, + , +, / , /. N . Notice tha hat t the he d division o n operator i is a at t the he e end
- nd. R
. Runni nning ng t thi his i in y n your calc lcula lator w will a ll actually r lly return t n the he c correct v valu lue o
- f 0
0.6 .6153846. .
A LITTLE BIT OF BACKGROUND
- The
he s software u used f for t the he H HP 2 20b calc lcula lator i is b based o
- n e
n ent ntry- s
- sys
ystem m lo logic, w , whi hich c h cont ntains ns R RPN a and nd A Alg lgebraic and nd C Cha hain A n Alg lgebraic s
- software. T
. The here a are
- ver 2
220 b built lt-i
- in f
n func nctions ns a and nd me menu nus and nd p prompts a are i inc nclu luded. .
- Atme
mel A l AT91SAM7L128 p processor
- The
he lcd_p _put_c _char7 func nction i n is t the he essent ntial t l tool t l to d displa lay o y output o
- n t
n the he calc lcula
- lator. T
. The he f func nction t n takes i in t n two parame meters, t , the he f first o
- ne
ne a a c cha haracter and nd t the he s second nd o
- ne
ne a a nu numb
- mber. T
. The he func nction t n the hen r n returns ns t the he c cha haracter a at the he g given i n ind ndex nu nume merical v l valu lue. .
LAB 1 CODE
#include "AT91SAM7L128.h" #include "lcd.h" void clearScreen() { int i; for(i=0; i<11; i++){ lcd_put_char7(' ',i);} } void printOutput(int number) { clearScreen(); int counter, remain; char character; int position = 11; int absArg = abs(number); for(counter = absArg; counter >= 1; counter /= 10) { remain = counter % 10; character = '0' + remain; lcd_put_char7(character, position); position--; } if(number < 0) { lcd_put_char7('-', 0); } if(number == 0) { lcd_put_char7('0', 11); } } int main() { lcd_init(); printOutput(23444); printOutput(-0); return 0; }!
LAB 1 EXPLANATION
- Go
Goal: d l: displa lay a y a nu nume merical a l argume ment nt i in t n the he c calc lcula lator
- Cle
lear s screen a n assigns ns e empty s y spaces i in e n every p y position i n in t n the he s
- screen. S
- n. So i
it ma makes t the he s screen n ready t y to a accept t the he nu numb mber. .
- After c
cle leani ning ng u up t the he s screen t n the he v variable le t takes t the he a absolu lute v valu lue o
- f i
input nu numb
- mber. In t
. In the he f for lo loop, t , the he nu numb mber i is k kept d divided b by 1 y 10 and nd t the he r rema maind nder i is s stored i in t n the he r right ht mo most p position n unt ntil t l the he c computer g gets t the he o
- ne
ne d digit v valu lue o
- f t
the he hi highe hest d digit nu numb
- mber. F
. For e example le, w , whe hen y n you ent nter 2 205, t , the he f first r result lt f from f m for lo loop i is 5 5 a and nd i it i is s sho hown i n in t n the he r right ht mo most p position 1 n 11. A . And nd the he r rema maini ning ng nu numb mber 2 20 g goes t thr hrough t h the he s same me p process a and nd 0 0 i in p n position 1 n 10 a and nd 2 2 i in n position 9 n 9. In c . In case w whe hen t n the he i input nu numb mber i is ne negative, t , the he nu numb mber g goes t thr hrough t h the he s same me process b because t the he c code t takes t the he a absolu lute v valu lue o
- f the
he nu numb mber p prior t to t the he f for lo loop. .
- To d
deal w l with t h the he ne negative s sign, lc n, lcd_p _put_c _cha har7('-'
- ', 0
, 0) d displa lays ys ' '-'
- ' i
in t n the he le left mo most p
- position. A
- n. Als
lso, i , if input i is z zero, t , the he s screen s n sho hows 0 0 i in t n the he r right htmo most p position b n by lc y lcd_p _put_c _cha har7('0', 1 , 11)
LAB 2 CODE
char keyboard_key() { int i; char keyboard[7][6] = {{'X', 'X', 'X', 'X', 'X', 'X'}, {'X', 'X', 'X', 'X', 'X', 'X'}, {'I', '(', ')', 'O', '<'}, {'^', '7', '8', '9', '%'}, {'v', '4', '5', '6', 'x'}, {'s', '1', '2', '3', '-'}, {' ', '0', '.', '=', '+'}}; for (i = 0; i < 7; i++) { keyboard_column_high(i); } int j, k; for (j = 0; j < 7; j++) { keyboard_column_low(j); for (k = 0; k < 6; k++) { if (!keyboard_row_read(k)) { return keyboard[j][k]; } } keyboard_column_high(j); } return ' '; }!
LAB 2 EXPLANATION
- Keyb
yboard_k _key( y() w works ks a as f follo llows: y : you f first lo loop t thr hrough a h all o ll of t the he c colu lumns mns a and nd y you s set the hem a m all t ll to hi
- high. Ini
- h. Initially y
lly you a assume me t the he w worst ( (i.e .e. t . tha hat t the he v valu lue y you a are t tryi ying ng t to access i is no not i in t n the he c calc lcula lator’s ’s k keyb yboard). T . Thu hus, t , the he r rowPosition i n is s set t to t two a and nd t the he colP lPosition i n is s set t to f
- five. Y
. You t the hen lo n loop t thr hrough a h all o ll of t the he r rows f for e each c h colu
- lumn. If
- mn. If t
the he row i is a als lso lo low, t , the hen y n you ha have t to r return b n both t h the he v valu lue o
- f t
the he r row a and nd t the he v valu lue o
- f t
the he colu lumn. mn.
- We t
the hen c n created a a t thr hree-d
- dime
mens nsiona nal a l array o y of a all o ll of t the he p possible le i input v valu lues o
- n a
n a calc lcula lator a and nd w we r return t n the he e ele leme ment nt i in t n tha hat t thr hree-d
- dime
mens nsiona nal a l array t y tha hat ha has a a r row position a n and nd a a c colu lumn p mn position e n equal t l to t tha hat o
- f t
the he t two lo low v valu lues. .
- Thi
his f func nction s n sho hown i n is i invoked b by ma y main.c n.c a and nd i is lo located i ins nside o
- f t
the he k keyb yboard.c .c f file le. .
- We t
tested i it w with a h a w wide r rang nge o
- f v
valu
- lues. W
. We s saw w wha hat w would ld ha happen i n if y you k kept pushi hing ng d down t n the he b button ( n (it w would ld k keep d displa layi ying ng) a and nd w we s saw w wha hat w would ld ha happen i n if you t tried t to hi hit t two v valu lues ( (only o nly one ne w would ld b be d displa layed). T . Thu hus, w , we a account nted f for e error. .
LAB 3 CODE/EXPLANATION
vo void keyb yboard_g _get_e _ent ntry(struct e ent ntry * y *result lt) { int nt e ent ntry= y=0; int nt ne negative = = 0 0; for (;;) ;;) { { //ma make s some me lo loop t tha hat c calls lls keyb yboard_k _key() t to c che heck i k if i it i is t true s so a as t to s see i if w whe hethe her a a k key i y is b being ng p
- pressed. W
. Whi hile le a a k key y is p pressed keep lo looping ng t thr hrough a h and nd c calli lling ng keyb yboard_k _key() u unt ntil i l it i is no no lo long nger b being ng p pressed, s , so o
- nc
nce keyb yboard_k _key() () is no no lo long nger t true a and nd t the hen t n take t tha hat v valu lue. Every i y ins nstanc nce o
- f keyb
yboard_k _key() s sho hould ld b be r repla laced b by a y a v variable le i ini nitiali lized withi hin t n the he lo loop i if ( (keyb yboard_k _key() > >= 0 0 & && keyb yboard_k _key() < <= 9 9) { { e ent ntry= y= e ent ntry * y * 1 10 + + ( (keyb yboard_k _key() – – ‘0 ‘0’) ’); ; r result lt->
- >nu
numb mber = = ne negative ? ? -e
- ent
ntry : e y : ent ntry; y; } } //che heck t k the he c cases t tha hat c can b n be p pushe hed e els lse i if ( (keyb yboard_k _key() = == ‘~ ‘~’) ’) / //if t the he p plu lus mi minu nus s sign i n is p pushe hed, ma , make ne negative t true. . { { ne negative = = 1 1; ; } }
LAB 3 CODE/EXPLANATION PART TWO
e els lse i if ( (keyb yboard_k _key() = == ' '\r' || || keyb yboard_k _key() = == ' '+' || || keyb yboard_k _key() = == ' '-'
- ' ||
|| keyb yboard_k _key() = == ' '*' || || keyb yboard_k _key() = == ' '/') // i if o
- ne
ne o
- f t
the hese a are p pressed e exit a and nd r return w n wha hat i is i in t n the he p point nter { { result lt->
- >operation =
n = keyb yboard_k _key(); ; return; n; } } lc lcd_p _print nt_i _int nt_ne _neg(ne negative, e , ent ntry) y); ; } } The he u user i is g going ng t to e ent nter a a s string ng o
- f nu
numb mbers w whi hich c h create o
- ne
ne la large nu numb mber b by lo y looping ng t thr hrough s h some me s sort o
- f
displa lay mo y modification w n whe here t the he nu numb mbers s stay o y on t n the he s screen a n and nd a allo llow f for t the he a addition o n of o
- the
her nu numb mbers Whe hen y n you ha have f fini nishe hed t typ yping ng t the he nu numb mber t tha hat y you d desire, y , you e ent nter an o n operation. t
- n. the
he p program r m recogni nizes thi his o
- peration a
n and nd i it r returns ns t the he func nction, s n, storing ng t the he o
- peration a
n and nd t the he nu numb mber i in s n struct The hese a are p passed t to t the he ma main f n func nction w n whe here y you c can t n test t tha hat t thi his w works ks correctly b ly by d y displa layi ying ng t the he nu numb mber and nd t the he o
- peration
n
LESSONS LEARNED
- Make s
sure t tha hat e everyone ne i in t n the he t team kno m knows t the heir r role le i in t n the he g
- group. If
. If s some meone ne ha has e extens nsive experienc nce w with C h C, ha , have t the hem e m expla lain t n to t the he o
- the
her g group me memb mbers w wha hat t the hey ha y have le learne ned s so the hey a y are c caught ht u up-t
- to-s
- speed. L
. Leave no no g group me memb mber b behi hind
- nd. H
. Have no no g group me memb mber d do a all o ll of the he w work. .
- The
he c code r reviews w were r really he lly help
- lpful. T
- l. The
he f feedback w k was v very g y good a and nd w we le learne ned a a lo lot a about mi mini nimi mizing ng c code a and nd ma maki king ng c code mo more r readable le w whi hile le ma maint ntaini ning ng o
- verall f
ll func nction. n.
- Als
lso le learne ned a about t the he b bala lanc nce o
- f c