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 of s simply le ly learni ning ng t the he s synt yntax o of 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 of 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 of t the he c calc lcula lator
CAPP1 TDI CAPM1 Charge TDO ICE ARM7TDMI CAPP2 JTAG TMS PROCESSOR Pump CAPM2 SCAN TCK Processor VDDINLCD JTAGSEL VDD3V6 LCD VDDLCD System Controller Voltage Regulator VDDIO2 TST 2 MHz RCOSC FIQ 1.8 V VDDIO1 AIC IRQ0-IRQ1 Voltage GND PIO Regulator VDDOUT PCK0-PCK2 VDDCORE CLKIN VDDIO2 Memory Controller SRAM PLLRC PLL PMC Embedded Address 2 Kbytes( Back-up) Flash Decoder XIN 4 Kbytes (Core) OSC Controller XOUT Abort Misalignment 32k RCOSC Status Detection VDDCORE Flash VDDIO1 BOD ERASE 64/128 Kbytes Supply POR VDDIO1 Controller Peripheral Bridge NRST ROM (12 Kbytes) Peripheral Data NRSTB PGMRDY Controller PGMNVALID Fast Flash 11 Channels PGMNOE Programming PGMCK FWUP Interface PGMM0-PGMM3 VDDIO1 PGMD0-PGMD15 PGMNCMD PGMEN0-PGMEN2 APB SAM-BA RTC PIT WDT PWM0 PWM1 PWMC PDC PWM2 DRXD PIO DBGU PWM3 DTXD PDC TCLK0 Timer Counter TCLK1 TCLK2 PIOA (26 IOs) TIOA0 TC0 TIOB0 TIOA1 PIOB (24 IOs) TC1 TIOB1 TIOA2 TC2 TIOB2 PIOC (30 IOs) PIO PDC TWI TWD TWCK SEG00-SEG39 PDC COM0-COM9 PDC NPCS0 LCD Controller NPCS1 NPCS2 SPI NPCS3 MISO RXD0 PDC MOSI TXD0 PDC SPCK SCK0 USART0 PDC ADTRG RTS0 PDC AD0 CTS0 PIO AD1 RXD1 PDC AD2 TXD1 ADC AD3 SCK1 RTS1 USART1 ADVREF CTS1 DCD1 DSR1 DTR1 PDC RI1
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 of 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 of 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 of 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 of 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 on 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 over 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 on 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 one ne a a c cha haracter and nd t the he s second nd o one 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. .
#include "AT91SAM7L128.h" #include "lcd.h" LAB 1 CODE 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 of 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 one ne d digit v valu lue o of 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 of 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)
char keyboard_key() LAB 2 CODE { 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 ' '; } !
Recommend
More recommend