Exam1 Solution - Name:_ Exam #: <- RECORD YOUR EXAM...

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

View Full Document Right Arrow Icon
Name:______________________________ SHOW ALL WORK page 1 of 9 Exam #: <--- RECORD YOUR EXAM NUMBER! Test grades will be posted by exam number Embedded Control Laboratory Sample First Exam - Fall 2006 SHOW ALL WORK! OPEN BOOKS / OPEN NOTES Section: _____ Lab Time: ______________________ Your Grading TA: ______________________ Question # Point value Mark Grader 1a 3 1b 6 1c 8 2a, 2b, 2c 10 2d, 2e 14 2f 9 TOTAL 50
Background image of page 1

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

View Full DocumentRight Arrow Icon
Name:______________________________ SHOW ALL WORK page 2 of 9 1) (17 points) Use the following schematic to complete this problem. Answer the following questions based on the schematic shown above. a) (3 points) Write a function called “Port_Init” which correctly configures the ports for input and output. Code Comments/Pseudocode void Port_Init(void) { P2MDOUT |= 0x0F; // Set P2.0~P2.3 to push-pull mode P2MDOUT &= ~0x30(0xCF); // Set P2.4 and P2.5 to open-drain mode P2 |= 0x30; // Set p2.4 P2.5 to high impedance state } (P2.1) 74F365 Buffer (P2.3) 2 4 10 3 5 9 +5V 1 k (P2.5) Push Button 1 (P2.0) C8051 EVB Connector (P2.4) 67 (P2.2) +5V 1 k Push Button 2 Bi-Color LED (BLED1) 510 Bi-Color LED (BLED2) 510 (PB1) (PB2)
Background image of page 2
Name:______________________________ SHOW ALL WORK page 3 of 9 b) (6 points) Write a function called “pushButton” which returns 0 if none of pushbuttons is pressed, 1 if only “Push Button 1” is pressed, 2 if only “Push Button 2” is pressed, and 3 if both push buttons are pressed. Specify global variables outside of the function, if needed. Code Comments/Pseudocode /* write global variables if used */ /* write global variables if used */ sbit pushbutton1 = P2^4; sbit pushbutton2 = P2^5; unsigned char pushButton(void){ if ( pushbutton1 && pushbutton2) return 0; if ( !pushbutton1 && pushbutton2) return 1; if ( pushbutton1 && !pushbutton2) return 2; if ( !pushbutton1 && !pushbutton2) return 3; OR: return ((~pushbutton2) * 2 + (~pushbutton1)); OR: if ( !pushbutton1){ if (!pushbutton2) return 3; else return 1; } else{ if(!pushbutton2) return 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
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

Exam1 Solution - Name:_ Exam #: &lt;- RECORD YOUR EXAM...

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

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