{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lect6_notes - Foundations of Embedded Systems A Term Spring...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Foundations of Embedded Systems A Term Spring 2008 Lecture #6: More Digital I/O using the MSP430F449 Reading for Today: MSP430x4xx User Guide Ch 9 Reading for Next Class: Keypad datasheet, MSP430x4xx User Guide Ch 9, Homework #2 is on Web: Due Thursday 9/11/08 Lab #0: Report due 9/9/2008 in class Last class: Specifics of the MSP430F449 memory organization This class: Embedded systems read from and write to Ports to perform I/O. Embedded system designers usually have to implement these low—level IO routines themselves. MSP430F449 Basic Digital I/O Inputting or outputting logic levels to the pins of the MSP430 package >> Six independent, individually configurable digital I/O ports C: pm 7 P3 n 0 >> Each port is 8 bits wide >> Each pin of each port can be configured individually as input or output >> Each pin of each port can be individually read from or written to >> Ports 1 and 2 can generate interrupts which are control signals that can be accepted or ignored by the '430 —- We'll be using interrupts later in the term >> Each port is controlled by four byte—addressable (i.e. 1 byte wide) registers >> All the U0 port registers are memory mapped meaning each register associated with an 10 port or other peripheral device has a unique address ——> and in IAR C a predefined name ?0r£ e 00+?» raj—‘34.?“ => flgour : 0035‘ k Pori” 3 poncho“ Select ;) ??:. SEL : oolB k Q How do you know what the addresses are? Loo k ‘m H$PQBOFHM TA E 151’ 116,, 5.45“ :>m50, names are assifingé +0%Q aééresses an l""5941”,, 9w. h The 4 registers controlling the Digital I/O ports are 59” /, v“ \Mm fi‘xl P" 1.19” RegiSWL/K, where ' + 9-. \ LA'PQ-\' o m Po‘r‘f appeqra +0 CPU A\ Function Select Register: Se i8 (5‘5 quq—Jr FPO F + P .1 h per D35} -\ «,0 1/0 >9M°5+ ’P‘ms have Q or more ponc‘i“°ns ’Px SEL (Le. 'Pg SEQ ; o: 9351-lccl1/o; I: Gtkerfandzaa \ Direction Register: 36.4 5 - Nx‘rr“ ———————— m- M““M~ ~_HM ._ ’PLIDIR: OXOF; // 5845 'P'm’l-‘l as Capo-+5 // seis ?Lns 3-0 Q3 cu+pu+s ? lo I m In C (LAVA—\UE .2 lDGIU' "‘”“5:m‘g‘tiiégi’s‘£ér‘2”"” ~.__‘ WHNMHWMWKx * >> Using the digital I/O ports is conceptually simple... gfaé or LLJFK‘\€. (1651(64 Values firem/éo We r€fi75+8k flames assockcde La‘wHA “‘9th __ (m5P#30x9qy.H) >> Make extensive use of C's Bitwise operations —— & I ~ (and &= I: ~=) Ex: Using IAR C configure Port 3 for digital I/O wit; Pins 1 and 0 as inputs and Pins 7 thru 4 and out uts. . 7 p (P0! -\ 3 - . - v ' ' ignflre Vfleg T356). :0. Ilse/(wt ALL PW {3w dtfiiidio, *‘Hms Assumes p ~\n's 2+3 aren‘4 balms) USE! 5mg fin} ICaM Ao tau“ WM {,ng please I <’_ _ ,___.__,__V_...__-\ \\/ Beiigr Lidoufij PrQSen/e Se‘é‘lrlncas {301 Pgn32+3 _______._.\ =>W15 (Earth/es Same bl-i-LQKSQ OP‘QVCL/‘LTOMS PQ‘MQMMW; 4¢ moulzxk 59+ «Amb010 WWW 4c Oklzl bid 4 cam—My ’PBSEL :. 133 SEL 84 OXOQv // HUD Moooouoo // PssEL = ooooxxoo \ OxFO’ ”T’SDHZ: II \\I l xxxx se‘b UP ou+Pu+ Pm 3 2 // P3DIR: \\\\ xxOO [I $843 ”P inpm‘ p‘mS ETBQHW way (ire Age/\é bu‘E‘ (0 week: Prom new E LL39— LOO~C+ )Q/Aow’ WKM Mw/cfi M‘QW" r~> DCM, 1:014 FCk my examples 0‘; Mfigzc _MUMBMES l E E S , => 3::er numbers \HVLF appear LA (1on , ‘kuE- “make er Cole Odd/L" EQUSQ #de¥Ene Con$+CUlVEzS +29 make Coée Clearer E BiTD Hvu BETV are. Aefiznei ‘m mqugaxqqm‘ E E E BiTB I 0000\000 3.1‘1 = \ooo 0000 540 } BET-O ; 0000 000‘ BETH = 0001 0000 if" 052 ‘Hmem +0 52+ ‘FssL—“L Cami T’SDER (Nye, («)cux‘E’ P533: L: 0000 XX 00 W 93mm : HH “~00 EFBSEL: PSSEL J} (BXTB \ BIT 2,3] :7 ECZ,U1va.Eeer \j VgSEL Ba (EXT?) 1 B n- 2,) Efiecause (B'\T;\ BIT 1w —: 0000 \000 +0000 010 O %‘cm\'\0.rh3’ we use +ke BITCvBIT’? fleéPZA’LJVKOc/ug +0 59—‘Lup ’PBDIK f :L30 now ?3DIQW lLHxXxx wfl kaUQ +0 3—024 B410 0 M‘ 8+1” =3 DJCLA+ ~\—\I\€L~\ *0 \042 O 5 ’PBDxrz :mma 3<~,'(81T1881T03; :v\ SUMMCLY‘LG’ we(cl. 36+ ’P3bik +0 MV€ \‘Jms ‘7-% as Ou+pq+5 anA Pms 1-0 as lnpu‘FS LJSLAB ‘Hwasa 3L lines a? code // Se‘bp P3D1R 133D 3R 1:: (154T? $Bnel {5.75 \BITH) PBDH? 2<= N<‘B\T1\B\TOBJ §//.nh<15e£up ngfL @ weds pms 1—H, \,0 C01. 1329‘”? ID "PTSSEL 5;; (Ens \ BIT a); 371-0014; vU< Cam reed rpm/fife +0 was Po.’+ Using pre-defined constants to avoid “magic numbers” >> In C, there is always multiple ways to implement the same functionality >> Some ways are accepted as representing better coding style -> Try to avoid “magic numbers” = fixed hard—coded numbers that appear in code without explanation of their meaning or purpose >> These values are pre—defined in the msp430x44x.h header file we can just use 'em! BITO = 00000001 BIT4 = 00010000 \ =— 02 BITl = 00000010 31115 = 00100000 , A up BIT2 = 00000100 BIT6 = 01000000 5; ' 13113 = 00001000 BIT7 = 10000000 N :) NOT // S‘in’ UP ?ED \R _._) ans7~‘—]:OQ+PJ‘\'/. SPKAS i‘O:In/\Pu‘\” ’iBDIR \: (BtT'H Burusnswna); 133le 90“ ~(BIT\'\ 3WD»; // 5e+up ?5SEL L) 'Ptns 141 a“; (-o seiec‘ieJ For vatzs‘theo 1/0 ?355L &:(31T5\B\TL§ Ex. Now, read in from Pins 1-0 and place a 1 on the output Pins 7-4 that correspond to the binary number 0—3 on Pins 1—0. Pin 4 should is 0 and Pin 7 should be 3. .r . ~ ; . 4 o a F TR \ S ‘5 QCL s a er "35+ R eaé 9mm P3!“ (mi W“ ‘J‘e ”Pm” UV\$‘L(‘J)V\~€A Clrxc‘ur‘ Ln b PL 8) OU+Q0$€J // unmcjnet‘a by‘l’C (Lnb‘k‘ls .2: ?3 '[M & (Bl-T1 \BITOB‘ //P5‘|N 2; 000000” J ?3.0L)T Xx: 0x06 //5e‘r 8175 9—7 +00 SLuiJchm (in Brls} Case 0: ”PsooT 1:: Oxloji //P50oT:P30oT 0R lob 'l (‘v .— brea k) // cocrlc‘. also go P500 >x tot/E C0152 \ .‘ >> In an application program like demo.c the digital I/O ports are used repeatedly >> The application programmer wraps the specific port functionalities by placing the assignments to the port specific registers into useful C functions >> These functions are easy to manipulate and can be re-Hsed in other applications with same hardware >> main() is then a series of calls to functions whose names convey their purpose /****************DEMO.C MAIN FUNCTION *********************/ void main(void) { int pos=l; unsigned char lastKey=0; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer init_sys(); // Initialize the MSP430 /* Loop forever waiting for input */ while(1) { getKeys(); if (hitKey ==' ') { LEDOff(); clearLCD(); writeWord("ECE2801"); stelay(5); clearLCD(); writeWord("MSP430"); stelay(5); clearLCD(); writeWord("DEMO"); stelay(5); clearLCD(); } else if(hitKey>0) { if (lastKey == '#') clearLCD(); if (hitKey == '+') { buzzer0n() stelay(l) buzzerOff( vxo ‘- } else { writeLetter(pos,hitKey); LEDdisplayHex(hitKey); stelay(3); } } lastKey = hitKey; } Input or Output? Let's take a closer look at the 4 LED‘s.... >>On what port and pins are the LEDs connected on the Interface Board? [U 6 5 (are they an input ormevice?) (I L06 U36 \HAQM +0 6 15PM” VU‘ :5Di‘gfiimfi ‘UVLO AQVWO‘C— cue CCAA +l/Lc'd‘ 4KQ ’4 LED’s are connecteg +0 "Pom z puns 2—1—7 (_ ”92.743 =>Coui<l d-\SO leokoA 'In+er$oocé BockvA Sckéméuiig +3V \ 7 ;) when Pm '13 Logic! P2,"! ‘ :—_~._ ~er~€r€ L3 {\0 VOLLLCS «Q M>P~I30 ‘_\‘__,,,_fi/ AVOP across LED!S / .—— ‘3sz :9 L30 curren+:o"F :) Whfih PX“ "IS Logic 0 4k€n c u we + S? r ' = on How do the LED functions work? i A ‘0“) '3 cu. A6 L I: D void LEDOff (void) { P2DIR |= (BIT7IBIT6IBIT5IBIT4); // Set P2.7—2.4 to output Rowe //p;n5 o--5 atomfl §3>PZD1R2 ”920.2 OR \\\\ oooo PZSEL &= ~(BIT7IBIT6IBIT5IBIT4); // P2.7—2.4 I/O option ’eave iO‘iflzegie 5>?ZSEL11PZSEL AND NUT’( HM 0000); ‘PZSEL X 0000111] PZOUT |= (BIT7|BIT6|BIT5|BIT4); // P2.7—2.4 output 1 // (1=LEDs off) P ZOUT: 'P‘LOUT orL \Hloooo } void LEDdisplayHex(unsigned char num) { unsigned char tmp_num; tmp num = (~num)<<4- ”3&5an compiemgm-{ecl becauSe. , _ ‘ I 1/ Logic, Q SHJrVSS LED 0M 11> iMLWm 5 NOT OWN rem smug: be) H lo'rls / ~ /'~\ \J "“\ 7’ PZOUT = tmp_num & OXFO; v /,,.M\/,,\,. \’ \ / (@Lei‘ ham: 08h 4/an Are the 4 Buttons Inputs or Outputs? >> Where and How are they connected? (you'll write button routines in HW#2) Ci“ Q W\ CL)L‘\ C , I” :9 Check um 0:19 i, (Under USeCal L‘xnl<$ 3 Polling >> How do you now monitor and use your properly configured digital I/O ports? Consécier math/til prom clemag >> KEEP execolmqs ge'Jr/(etj() Uw‘l‘ll Ck Ketj KS @regs‘eA -—> Ov8r 4—Overt— (DI/fir raver”. =9 Polling +—u\e R95 90¢ >> when no kQ‘j )3 "Préggeé +‘me magn leap probably Executes 1m CK£€LU M‘xcrb 5€COAclS (quy, >> EéLSva VLQQ¥6C+RW¢ \bu‘l‘ MOT vex/t3 egglcleat‘i or eiQfiAW—lr .1 ...
View Full Document

{[ snackBarMessage ]}