________________________ ECE Box: _________ ECE2801 Sample EXAM #1

Name:________________________
_________
ECE Box:
ECE2801 Sample EXAM #1
Show all work. Be sure to sign your test and any scrap paper. Circle
final answer for each part of each question. Points are as indicated.
Good Luck!
1) Encode or decode the following numbers in the indicated formats. (30 pts)
IEEE 32-bit Floating Point format is shown below:
S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF
Where V = (-1)S * 2(E-127) * 1.FFF...
a. Encode 19.125 in 32-bit floating point format. Express final answer in hex.
Now give the decimal equivalent value of 8028h assuming the following formats
b. 2-byte Two's Complement Integer
c. 2-byte Unsigned Integer
d. 2-byte Sign-magnitude Integer
e. Binary coded decimal (BCD)
f. 2 ASCII characters (one character per byte)
2) In a “memory dump” from a certain microprocessor the memory locations are
shown incrementally from left to right starting with the address given at the left.
For example, this line shows the contents of memory (in hex) from address
0400h to 040Fh with address 0400h holding 00 and address 040Fh holding 15h.
Ex: 0x0400 00 04 00 9A 00 AF 0C C1 23 55 24 6D 00 00 15
Below is a memory dump showing how the following variables are stored in
memory at one point during program execution. The variables are stored
sequentially beginning at address 0500h. (20 pts)
unsigned
ii = 0;
char
mask1, mask2=15;
long int qual = 0x71FA8081;
char myString[4];
0x0500
0x0510
0x0520
// 16 bit unsigned int
// 32 bit 2's complement
00 00 AA 0F 71 FA 80 81 48 45 4C 50 00 11 45 54
10 00 80 00 00 00 01 02 00 FF 71 00 70 F8 FB 00
11 45 54 00 11 00 54 81 80 00 11 A0 CC 09 76 22
a) Is this microprocessor a Little Endian or Big Endian? How can you tell?
b) What ASCII text is stored in myString?
c) What value is stored in the variable mask1?
d) At what address is the variable mask2 stored?
e) Show how these 5 variables would be stored in memory on the MSP430C449.
Assume the starting address is 0300h.
0x0300
3) The code below uses demo.c as a model and uses several functions from
demo.c but it also has a new function called newThing(). (25 pts)
a) Add comments describing the code's function where indicated by
//______________ .
Explain fully what happens when the following key sequence is pressed.
Describe what output, if any, appears on the LCD, the LEDs and the buzzer.
(Answer in the table provided below)
b) Before the first key is pressed.
c) When the key '0' is pressed.
d) Then key '*' is pressed.
e) Then key '7' is pressed.
f) Then key '5' is pressed.
/* Compiler directives */
#define ASCII_0 0x30
#define ASCII_9 0x39
#define ALL_GOOD 1
/* Prototypes for functions available */
void setupKeypad(void);
void initLCD(void);
// Keypad initialization
// Setup code for LCD
unsigned char myGetKeys(void); // Reads from keypad, returns
code if key is pressed or 0 if no key pressed
void swDelay(unsigned int max_cnt); // SW delay loop
void LEDOff(void);
// sets up LED port and turns LEDs off
void LEDdisplayHex(unsigned char num); //displays hex code of num
//on LEDs
void clearLCD(void);
// Clears LCD
// ASCII
void writeWord(const char *word); // displays words up to 7
// chars on MSP430 LCD
int newThing(int num1, num2);
// prototype for new function
void main()
{ int newNum, lastSave = 0, myNum;
unsigned char inKey, led;
LEDOff();
setupKeypad();
initLCD();
inKey = 0;
while (ALL_GOOD)
//____________________________________
{
if ((inKey >= ASCII_0) && (inKey <= ASCII_9)) {
newNum = inKey-ASCII_0; //__________________________
myNum = newThing(newNum,lastSave);
if (myNum > 0)
{
lastSave = newNum; //_____________________________
clearLCD();
writeWord(inKey);
swDelay(5);
clearLCD();
writeWord("BIGGEST");
swDelay(5);
}
inKey = 0;
//______________________________
LEDOff();
led = inKey & 0x0F; //_______________________________
LEDdisplayHex(led);
}
else {
clearLCD();
writeWord("ENTER #");
swDelay(5);
inKey = myGetKeys();
if ((inKey == '*') || (inKey == '#'))
{ buzzerOn();
swDelay(1); //_______________________________________
buzzerOff();
swDelay(1);
buzzerOn();
swDelay(1);
buzzerOff();
clearLCD();
writeWord("NOT A #");
swDelay(5); //_______________________________________
inKey = 0;
}
}
} // end while
} // end main()
/***** Function newThing() ******/
// WHAT DOES THIS FUNCTION DO?
//
//_______________________________________________________________
int newThing(int thing1, thing2)
{
newVal = thing1-thing2;
return(newVal);
}
LCD
b)
c)
d)
e)
LEDs
Buzzer
f)
4) The single red LED on the Olimex board is connected to Port 1 pin 3 as shown
below. (25 pts)
3.3 V
MSP430
P1.3
R
a) Using the code framework below, complete the function redLED() which will
properly configure and light the red LED or turn it off based on the value of its
input argument. Your function should not alter the settings of any other Port 1
pins.
b) Complete the function inFromP5() to properly configure P5.7-0 all as digital
inputs and to read in a byte from Port 5.
c) In main() will the LED light when testByte is odd or even?
/* Compiler directives (includes and defines) */
#include "msp430x44x.h"
#include <stdlib.h>
void redLED(unsigned char on_off)
{ // LED is lights when on_off = 0 and is off otherwise
}
unsigned char inFromP5()
{
}
void main()
{
while (1)
{
unsigned char testByte, tmp;
testByte = inFromP5();
tmp = testByte & 0x01;
redLED(tmp);
swDelay(3);
}
}
ASCII Table-I
ASCII Table –2