lect7_notes

lect7_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 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
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 #7: Making it work: The Keypad Reading for Today: Keypad datasheet, MSP43OX4xx User Guide Ch 9 Reading for Next Class: Review all reading, notes, User's Guide Ch 1,3.1-3.2,9 Lab #0: Due Now Lab #1 (on Web) : Due next Tuesday 9/16/2008 in class HW #2 (on Web): Due THURSDAY 9/ 1 1/ 2008 EXAM #1 — This Friday 9/12/2008! Last class: More on configuring and reading from and writing to the digital 10 ports on the MSP430F449. -->Using bitwise operations for configure the digital 10 ports. -—_—_——_——_____—_———__ MSP430F449 Basic Digital I/O > > Six independent, individually configurable, 8-bit wide digital I/O ports > > Each pin of each port can be configured individually as an input or an output > > Each pin of each port can be individually read or written to Function Select Register: Sets function of each pin in the port (i.e. P4SEL) -- Bit = O = Selected for Digital I/O -— Bit = 1 = Not selected for digital I/O (multiplexed pin functions) Direction Register: Sets direction of each pin in the port (i.e. P2DIR) -- Bit = O = Corresponding pin is an Input -- Bit = 1 = Corresponding pin is an Output Input Register: Where input to the port is read from (i.e. PZIN) -- Bit = O = Logic low -- Bit = 1 2 Logic high Output Register: Where data to be output from the port is written ( PSOUT) -- Bit = 0 2 Logic 10W -- Bit = 1 = Logic high > > All I/O port registers are memory mapped — Read and write to the registers names (defined msp430x44x.h) as if they were C variables! 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 8 S (are they an input orevice?) (r we U Se \HAQM +0 a KSW‘W V0” W “6 DF‘QS‘MS AQMOtC we ” LED’S we Connecteé +0 oom a pm on (132.740 =>COUU QASO lookoh IA-kergqce Boqvé SCRQMKQ‘IQ +3V ‘ a) when Pinks Loaic' P2.’7 \ :‘X +k~er€ LS no UOthKCS‘e MSP r ‘ 95° (W grep acroes LLDS / A pz’u‘. => 100 curren+ 5 0‘” F :) Whin ?3Y\ ‘33 Log‘zc O \ern HowdotheLEDfunctions work? curflen“ Q \ows aflé LED 2 0” void LEDOff(void) { PZDIR |= (BIT7IBIT6IBIT5IBIT4); // Set 92.7—2.4 to output )emvc //P;ns 0—5 0.10va :_>’PZD1?‘: ’PZDIR 011 \\\\ Oooo PZSEL &= ~(BIT7IBIT6IBIT5IBIT4); // P2.7—-2.4 I/O option leave i03n’5‘qegie r“5132869. :PZSEL AND Nafl \\\\ oooo>;PZSEL X 00001111 PZOUT |= (BIT7IBIT6IBIT5IBIT4); // P2.7—2.4 output = 1 // (1=LEDs off) ?ZOUT=?1OUT OK HHOOOO } void LEDdisplayHex(unsigned char num) { unsigned char tmp_num; th mm = (~num)<<4- //B“cl;safta complemmiecl becauSe. - _ I // Logic +Urn$ LED 0M => Jim—Wm : Now/Wm lam shxmel b‘fi Lt ms WN'N— PZOUT = tmp_num & OXFO ; /’\1/\/’/\“/ “HM -vw ~ o‘ooowoo):F7<<‘1 } P M; ( =7oh "\72 OUT = ‘1 o kl 4-00 Are the 4 Buttons Inputs or Outputs? >> Where and How are they connected? (you'll write button routines in HW#2) 3? Check, ‘er Cl [may SCkQVna/‘LECJ —’____/ (Dozier USepdl L‘\r\l<$ B Polling >> How do you now monitor and use your properly configured digital I/O ports? Conslcler tonal/M3 prom clemag >) Keep execulcna 3e+ke<j() oval 0\ ketj \lS Gjresgecl- _~~> OVerkOVerf—OI/Cr VOL/6".“- z'? (Polling +ke Rea Poxé >> (2)th no ken ‘IS “PregSei “Hoe Width l00p Probably EXPLU‘QS 1m ckg-CUJ [fl/“Orb >> Ekgfl $é$$€£~lwe bu+ MOT verfi egglclew“ Or’ elefiavx‘l' _‘ One Last Example: Now, write a function that reads the low nibble from P6 into a byte, and another functions that outputs the complement of the low nibble of a byte on P4. Assume ports configured as in Bonus Problem... void portConfig() { /* Setup P6.3—0 as digital IO inputs */ PGSEL = PGSEL & ~(BIT3|BIT2|BIT1|BITO); P6DIR = P6DIR & ~(BIT3IBIT2IBIT1IBITO); /* Setup P4.7—4 as digital IO outputs */ P4SEL = P4SEL & ~(BIT7IBIT6IBIT5IBIT4); P4DIR = P4DIR | (BIT7IBIT6IBIT5IBIT4); } Char in_P6() { char inbits; // Read in from port 6. Save only the low nibble) inbits = P6IN; inbits = inbits & 0x0F; return(inbits); // return the value inbits } void out_P4(char inByte) { char outbits; // Complement byte outbits = ~inByte; // Shift low nibble left to bits 7—4 outbits = outbits << 4; //output on P4.7—4 P4OUT = outbits; Polling > > How do you now monitor and use your properly configured digital I/O ports? of Sand OUJFPU+$ 55 ugh-tch +0 Pkom' COA sicker Ma‘infl £10m C\‘€W\OIC ‘> keflp exectfi‘ma fie} Rak3() Over and (Di/Cr Ctvxé over kink over ckeckins +0 56¢ Vania has been Pressed I —§T\mot+\s @OkLlUQ *kfl Ke‘fipo‘A' Custom Interface Board 10 Map (so far...) > > 4 LEDs = Outputs (active low) = Port 2 pins 7 thru 4 (P2.7-4) LEDOff(void); LEDdisplayHex(unsigned char num); cm‘igx MN >> 4 Buttons = ??? -- Write functions for HW#2 & Lab 1 ha»... ’4"’_"’“- ~ » it > > Buzzer = Output 2 Port 1 pins 2 and 0 (P120) (also requires other functions like timer) void buzzer0n(void); void buzzerOff(void); W Use H\€.Sca 74;) ab [4/01 > > 12 Button Keypad = Output (P1.7-5) and Input (P2.3-O) both active low setupKeypad(void); getKeys(void); Let's take a closer look at the keypad... her: . R%osxc 1 ~ 3.2» Keypad Operation Logic 0 w Ov > > The keypad is a grid matrix of push button switches C O L : I or 0 => 120w Lndmcdors Run) (2&1);wa Rum Are U \\C\L+\ve \DLL.) _ L06]; 0 when l<€Lj L3 Presseé => I? am. 33+ +0 L05“: (3 cm; kelfi \s 30w“ “(hen End 90. Bu+ iJFwL’sel +0 Loyal ugh emu mu 2? balm“ \5 (30335:; (RW=lkn5wk‘1\ > > In order to determine which (if any) key has been pressed, the programmer must poll each column of grid individually . MANN =) G S+eps +0 $0 ll ken 9&5 Dots in the chart indicate connected terminals ‘ Terminats are identified? on the keyboard. ‘5 Od‘lPU‘l' "0 0n Column PMS 12 Button Keypads (which cue: (PL7-S’) mmxcougs Z) Inpu-l- Rooo (3m 5 CR1. 3- 0) Standard ’l’D \\\n “L‘u “1Mm“*¢ saga: * - i 5 2 was r _ 5 Hllflfllll P 85‘“ Ell-III 3) 0 Jr _* | Iain-lull u go \m on Co amp?” Ellfllflll ‘ ' 2 arms: I C} I | L) \ Ellflllfll . l anw row 9m +:: See aaaaaa ! it xx \ , . t , 11 I b n \ I \\ I ‘0’ IEIIIIIIIH A. » z 5 , is W pressal -aalln - TERMINAL woman 5 'Pofi" \ KHZ é) INDqu (0‘43 pins ‘l‘o See ( \\ ’ x v ka Ll; “3" “U; “4’; 0’ #1 I g. X g. o 5 Col Rows "P t2 \Ccr 35kT/3W‘5 QUV‘U‘WOA S‘Q‘XS Op ©or+ \ \X— or a \ ad} VJ) IO DONNA *‘Ke Kata Pqé /************~k~k setupKeypad() *********~k*~k*********/ void setupKeypad(v0id) { PlDIR |= BIT7|BIT6|BIT5; // Pl.7-5 Column Select outputs fl“? PlSEL &= ~(BIT7IBIT6IBIT5); // Set Pl.7—5 for Digital I/O PlOUT |= BIT7|BIT6IBIT5; // Set P1.7-5 High (ale-Sehc“ an COL} PZDIR &= ~(BIT3IBIT2IBIT1IBITO); // P2.3—0 Row Select inputs 5—," ? PZSEL &= ~(BIT3IBIT2IBIT1IBITO); // Set P2.3—0 Digital I/O /**‘k********~k******* getKeys() ************************/ void getKeys(void) { unsigned char lookup={'1','4','7','+','2','5','8','0', '3'I'6'I'9'Il#l}; unsigned char KY[12]; unsigned char RW=0x01; unsigned char CL=Ox20; for(int i=0; i<12; i++) { PIOUT &= ~CL; // Set current Column KY[i] = (P2IN&OXOF)==(~RW&OXOF); if(KY[i]==l) // Key was pressed { hitKey = lookup[i]; // Gets key value break; } else hitKey=0; // no key was pressed RW <<=1; // Goto next row if(RW>0xO8) { PlOUT |= BIT7|BIT6|BIT57 // 91.7—5 High RW=0x01; // Goto lrst Row CL <<=1; // Goto next column } } PlOUT |= BIT7|BIT6|BIT5; // Pl.7—5 High } C Break: --> getKey( ) is a bit cryptic. What's going on here?? > > Lets look at the unsigned char arrays lookup and KY 300%)?“th = '#' 9‘00“ U? \n 0\c\§ W ASCII odes fior 39h = '9- :Egii;izfi ‘+4\42 ¢A2~QL80 imkuafei‘fflih = '3' 11> ky \3 CUR arrays 04: \1 fiiafij their ‘m ARC,qu M€%Qr%d 32h fih “hp/‘3 \3 pressed II M II x» 37h ll \1 34h IDOKUPL") 3 M II m. II H POVA'Q' :00 Xxxxx % KKxxloo- par-t 2. W W CDkUM“$ Flaws How does the loop structure work? =>F0r1ooP (L coon-B We *9“? 0+0 =>CL flow-Ls 45 0x30 _._ 0010 0000 (l5+ COL. 3 => 12L.) S’rcw4-s 45 0X0, ___ 0000000! 05+ Row) —--> Pew! ‘m 200-35 \Hnevx move +0 2‘5 Coluwm anal re‘Lcl. Ln Rea—95 6.33.0.1“ 4/qu Movc +0 3'4 Co] 2) (363, H‘ is CrfiPJHC! 1* “J50 WWKS/ 50 ~ ' ~ What do you get back from getKey( )? ( L3 0% CCU“ we ‘U’m lbw/{HOV‘ asay) fie ASCII co-vle £or 44x4. 1&3 Pressei storeé tn QLOBAL How do you manipulate k’tLK 6y ? 1+ depenés II >> /’0 use \\ ,, [710st 45 K noun leer conver—f $0M ASCJI +0 Lm‘leaer Eb Sub‘hrckchfij 50k Let \rfi-‘thgQBI - 33H ’- nom:\a\%\<€j«©x30; HUM; 3 Another, clearer(?) version of getKeys () /******************* getKey52() ************************/ void getKeys(void) { unsigned char lookup={'l','4','7','+','2','5','8','0', l3l’l6III9lll#l}; unsigned char row, col, num_col=3, num_rows = 4; // Set up bit patterns for testing each column // Apply 0 to test the column and l to make column inactive // Recall that the columns are connected Porl pins 7-5 // For column 1 = 110xxxxx, col 2 = 101xxxxx, col 3 = Ollxxxxx unsigned char col_mask = {0xDF, OXBF, 0x7F}; \\0 \ ***# ngu/ for (col = 0; col < num_ool; col) kg: { (N 9‘ PIOUT = PIOUT & col_mask(col); // Test current Column the’ O$O row = (APZIN) & OXOF; // Read in rows, complement because (0V§9_4,/\Jfl // keypad is active low. Only keep bits 3-0 switch (row) { case 1: // hitKey is a global variable defined in demo.c hitKey = lookup[col*num row]; break; _ case 2: hitKey = lookup[col*num row+1]; break; n case 4: hitKey = lookup[col*num_row+2]; break; case 8: hitKey = lookup[col*num_row+3]; break; default hitKey = 0; break; } } PlOUT |= BIT7|BIT6|BIT5; // set column pins P1.7—5 all High } ...
View Full Document

This note was uploaded on 10/27/2008 for the course ECE 2801 taught by Professor Jarvis during the Fall '08 term at WPI.

Page1 / 10

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

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

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