lect6_notesC10

lect6_notesC10 - Foundations of Embedded Systems C Term...

Info iconThis preview shows pages 1–11. 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 DocumentRight 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 DocumentRight 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 DocumentRight 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 DocumentRight 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 DocumentRight Arrow Icon
Background image of page 10
Background image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Foundations of Embedded Systems C Term Spring 2010 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 1/28/2010 (by 2 pm to ECE office) Lab #0: Report due Now! Lab #1 (on web): Bonus sign—off by 5 pm Friday. Report due 2/2/2010 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. Almost all computer programs require Input and produce Output... >> Consider this C code for a General Purpose computer #include <stdio.h> void main() { char inKey = '—'; // declare variable named inKey // and initialize it to be ASCII '-' while (inKey != 'X'); { /* get character from keyboard */ inKey = getchar(); /* display character entered on screen */ putchar(inKey); } } How is the Input and Output handled? It's just a simple bit of software? >> getcha r( )l and putcha r() are C functions and part of the stdio library ——> Their function prototypes can be found in stdio.h ——> Also their implementations are part of stdio library which is “included” during the build process (compilation and linking) >> These “canned” software routines have always been part of standard C because everybody using; general purpose computers has needed to read characters from a keyboard and write to a monitor! ——> Several computing “layers” below our simple little application a byte has been placed on the microprocessor's data bus from the PORT attached to the keyboard... (i.e. voltages corresponding to Logic 1 and 0 have been applied to pins of uP) _ _ . M: It ‘ filman Appllfiujk «DA MAM C 'Fu aw} gz+chwu \\ V 03 S \H/{tn "’“M $504.5 ASSeWA’hSM OMC ‘3 L0 S‘OS-lew‘s m av X, FORTH \ Ham?“ "‘0" pm”. ‘/ \"’?or‘\- A—u owxé “$0v-l' B" are, 1/0 "D‘ms on ‘l/bQ ’PQLlLCLoa/e 0'}: We micro {JKOCQSSar/ Embedded Systems are Application-Specific and Unique >> There isn't a nominal configuration for a MSP430 based embedded computer ~> 3 Sabtqmuhes 0-3 MSPMBO L ("lxx LSXX HUI ~> DOEBAS 0"? processors in IQLL— 9 Have ditl‘erem‘é M‘QMDVUS <l~ periphech Lw'FiéouchHO‘AS D'\l:¥eren“ Snaiems will have Dipacempt‘t HM) Lannec‘ieA +0 processov I! 9N0 prcse+ Canvefl-lions tear I/O ,(l‘ke PC- >> TI can't readily supply canned I/O routines* because the I/O varies so much! (*Embedded OS are starting to provide some “system call ” functionalities) >> Embedded Systems Designer decides what 1/0 the system needs + + S ~7 Temperature Senso‘r) ‘R F 'Ln‘l er-PccC‘< , Ba 0" a LCD >> System designer integrates the HW sensors directly with uP's I/O ports ——> Those ports and peripheral provide the uP with input/output capabilities ——> In the MSP430' the peripherals and ports are Memory+Mapped O O I 0 fi 0 ‘ F; F k ==> ‘4 5595’“ ed «cl/dress be. to W s =) Adévess of cad/x device is lls-lci In day“; She€+ (also [A MSPq-Sox‘lxv.£\3 >> Most modern microcontrollers and even general purpose microprocessors will have at least some of these “standard 0 tion” peripherals on—chip —_ >>Digital I/O, timers, interrupt controllers, USART, ADC, comparators,.. >> The tricks is figuring out how they work on YOUR specific chip! MSP430F449 Basic Digital I/O Inputting 0r outputting logic levels to the pins of the MSP430 package ,.. o a. o- 'Por-lz ‘8 pins cm MP C:: ‘0 PACKmfie >> Six independent, individually configurable digital I/O ports 0 por‘ls => 4| 8 bib 0? A ten} >> Each port is :3 bits wide 49 3/0 [.4 io‘iaj >> 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 ‘ / 2) Rio”! or wri‘i‘tcux ‘lo like & va,14_\>\e m memor5_ >> 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 1/0 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 How do you know what the addresses are? L 00 k 59l- \H\ .4 Me M 0 f k3 qu In 44mg Ms? ugquqc‘ AAA.“ skqefi‘ (See Use'PuL LM 5 NCLVA‘65 Q‘r‘o— ASS‘\%QC( \LO \L’lfi‘QS‘e CLAJ—VQSSQS \ Lo ms'PLBOx Wink header file M How do You know what the addresses are? L 00 k R A P (43 Off‘ q q “DAT A 5 H : El (Useiul um) / 3>LHSOI names Cure assifineé +o‘1‘4xQ CLAAfESSCS Ln “was 4/30,, v “1.2.10 The 4 registers controlling the Digital I/O ports are Function Select Register: Se ‘8 (:{5 +\\ (C‘— 'Po {- + P ‘1 n cor ( D3 '\ %€1~ >9M"5+ ’P'ms [Acwe Q onmorfl Fonc‘f ‘0” S “4/ [PX S E L (LP. '93 5 EL‘) : O = Dye-{filed l/O; l -‘- O‘HAQW panc‘haa /"“"““'“*‘— -. , m m 'PLIDHz: OXOF, ,/ 5e+51>m1~uas Lam-+3 // $e+$ 'PLns 3—0 Q5 Oo‘lPU‘B MPH w»; (A where LAPQ+ +0 44m (sof‘t CLPPe‘kr‘S +0 CPU 1" (Ln Vcd U€ I FGIM- {Earl Illa” ck Varictbl' J 6 /-- A" *' w-«wm r—~_r-wwm_l_i-__Mm“ ’/ because M e Output Register: MW“‘“‘“‘“~~V ~~~~M M mor‘j Maggi /\ M :30th Q‘ Adda‘ +0 m‘rm 1C r [Y \S Lof1++eK O < \ x 00 "P L; o o T >> Using the digital I/O ports is conceptually simple... (RedaA or wr'fle ClCS‘ufeJ Values ‘C/oM/éo We (65175.1ch flames (1550(1qu uJ'ka 4J4epavrt a” (MSPq30x‘lqy.h) >> Make extensive use of C's Bitwise operations —— & | ~ (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. . ? p ?o« -\ 3 - c v v ' ' ignflve Viagra V356). :O' / ?3'D\.R 2 Ox (:0; // 58+ 0’ z 4.3 A'LL W *‘rms ASSUMES 12>}ns 2+3 oxen ‘4 belna use»?! 0W; mail 37:44“ A0 tom. ‘HvalM asI Plea” .’ , he \v~ ‘ ’Egtii" P‘JQLAW Pfe serve sail-Limbs 7501 Pan32*3 ____J =>T1vxls Pequot/es Same bl+LoRge Opeva/‘LTOMS Vemewx‘mer; xx MOD 1:# 59+ «Awh010 wkéle 4c male bed xx Gear.” T’BSEL .: 133 SE. Zz OxOQv // HUD Moooouoo // P3$EL .: Ooooxxdo \ OXFOJ /l?3D|R : II \\| l xxxx J // T’3DIR: nu kxOO n 3343 Up anm‘ p‘mS Mew, during) +k13 Lecfure, } + "13 c IQar ; kauE OKOC aMA OxFO aM¢leFC are AQéAé bu‘k‘ 9L3 felib Prov“ new Due; wad—L /iQ/Y\ka)’ W1 QM ‘, ;> DCln, F014 FCK WV Examfahs a? MAQM. _Mgfl§_es Z i 3‘? thecl mum Lem HUUL appear in Code ‘Hmfl' “make Hte Cole LAO/k” P036 #de‘p‘me Cons+cuxv~¥s 4v make Coée Clearer BiTD ‘eru BiT’I are de£2neé 7n msp‘BOxHHxM BKTD 2 0000 cool BITH = 000! 0000 BITS : oooo‘ooo BLT? = \000 0000 64C. } 05;: \erm +0 SQ+ 'VESEL anc’. p513“? udchr PESEL :2 @000 2<>< OD M 93mm HHM‘OO ll EFBSEL: vase». J; (Bx-rs \ an a}; => E?,U1vo.\em+k~3 'VgSEL Xx: (BsT3 i BtT 23 flame. (€\T;\ Ema»: 0000 \000 ’ +0000 0100’ gg‘mmkhkrltjl we use +k€ B‘TO~BIT7' “ fidetpinllrlocAs' +0 Sea/p ’PBDIR ’P3ybik 2 ?3'D\R ‘ (3n? \ 81T£a\ BIT§\ 31TH») K E?uiva\€vx+\\3, ’P3DVR \= (8:T‘1\Bin‘ BlTS \Bt‘r‘ivj' 1:? 30 wow (P39le ll\\XxxX i we have +0 3024 Ebb 0 Mam sun "-4? LOCkA+ *Kem *0 \042. O KPEVD\R 2??)le A963 \T’L a ‘8 1T5); _..5 4.“ Sammax‘fil we‘d. Se+ Vania +0 mm DCAS 7“‘-( as Ou+pa+5 and Pins [’0 CLS \unpu‘i‘s U5>LA§ +k€$a 2L fines a? Q0114 // syrup PBDIR [PB’DH—l 1’3: (TENT? ‘BI'T6:\ 61TH \BITH)‘ PBDR 3<£ ~(‘B\T1_ \Brr a) //inw.!. Scamp PSSEL =-> weds ms *1 (—H, \,o 1:0 T’SSEL &;CE\T5\B1T 1W 7 .,»A.‘.w..mw__..—u...mmw mu.¢.m.¢.~..«... W. W, P7100“; wad (Lu/N (ELLA “wa.+€ +0 +K23 90(4- 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 \ =) OK BITl = 00000010 BITS = 00100000 gfl Up BIT2 = 00000100 BIT6 = 01000000 8( BIT3 = 00001000 BIT7 = 10000000 N :) MDT- ~O :IAPJT in l // S‘E’A’ UP z) ’P‘~n57~9:0u+pa*'/. 3? 5 ’i’qulR \: (BtT7l BuTe\B\T'§\BnH>J’ T33 9“ 2-“ ~(B|T\'\ Errol // 59+”? ?5SEL :) ’Ptns ’1‘“ “4 "0 Sel‘fc‘eé For 44231+cc0 33/0 ?3SEL 2‘; (BtT5\ Bur-Q 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. ‘ _ ,. I ‘ L)’ TR \ 3 Vi S QCL 3 ii er ijkfil R 6&3 ‘R’C-wx T331“) (Ll/XX W»’\+‘€ 40 P30 ‘ 74 v7“ \..»——. ix“ NW, Defiant-’1 Chew Labals) ou+coae~ I/u~~s‘~aNA 5”“ L74 bids .1: 1M &( 1 \ 0000 (DC) “ ?3CUT X“:— Ox 0‘3 //5eT Ens 41—7 +0 0 Shut‘lC—la (in l)i‘l$\ % Cage O: “9300'? 1:: OxlO) //P30oT:P300‘r OR to“ break) COL/‘1A also do 19500730): lOl/B PBOUT 1‘ Ox 1 O) // her: we cwlé \notaeusecl 5 // “eaoo‘r \= B’Tg, PBQUT 1: OX 80; bV€LU<J‘ 5 >> 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- ted in other applications with same hardware >> main() is then a series of calls to functions whose names convey their purpose /****************DEMQ.C MAIN FUNCTION *********************/ void main(void) { int pos=l; unsigned char lastKey=0; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer init_sys(); // Initialize the MSP43O /* Loop forever waiting for input */ while(l) { getKeYS(); if (hitKey ==' -) I { . _ r .fse LEDOff(); </\._/~ ct LS c‘eaw‘ kiwi ‘HN’. clearLCD( ); Qunctko‘ns A0! writeWord("ECE2801"); stelay(5); clearLCD(); writeWord("MSP430"); stelay(5); clearLCD(); writeWord("DEMO"); stelay(5) ‘0 ‘0 clearLCD() } else if(hitKey>0) { if (lastKey == '#') clearLCD(); if (hitKey == '+') { buzzerOn(); stelay(1); buzzerOff(); } else { writeLetter(pos,hitKey); LEDdisplayHex(hitKey); stelay(3); } } lastKey = hitKey; ...
View Full Document

Page1 / 11

lect6_notesC10 - Foundations of Embedded Systems C Term...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online