0% found this document useful (0 votes)
139 views2 pages

Microcomputers Exam Solutions

This document provides solutions to questions on a mid-term exam for an introduction to microcomputers course. Question 1 involves analyzing a for loop code snippet. Question 2 provides a function to count the number of blank spaces in a string. Question 3 describes a finite state machine for controlling a flag motor using two sensors. Question 4 gives the logic equations and schematic for a 4-bit decoder circuit.

Uploaded by

jkmaro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views2 pages

Microcomputers Exam Solutions

This document provides solutions to questions on a mid-term exam for an introduction to microcomputers course. Question 1 involves analyzing a for loop code snippet. Question 2 provides a function to count the number of blank spaces in a string. Question 3 describes a finite state machine for controlling a flag motor using two sensors. Question 4 gives the logic equations and schematic for a 4-bit decoder circuit.

Uploaded by

jkmaro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

APSC 380 : I NTRODUCTION TO M ICROCOMPUTERS

1997/98 W INTER S ESSION T ERM 2

Solutions to Mid-Term Exam


Question 1 states we find that it is not possible to determine
when to exit the off state (in one case we need to
The for statement initializes the variable i to N-1 exit it when the S sensor goes high, in the other case
(4), executes the body of the loop while i is non-zero we need to exit it when the S sensor goes low). We
and decrements it at the end of each loop. Therefore can avoid this problem by using two “off” states: one
the values of i in the loop will be 4, 3, 2, and 1. when the flag reaches the upper limit and one when
The first expression in the loop sets c to the bit- the flag reaches the lower limit. Appropriate names
wise logical AND of i and 0x02. The value of this and outputs might be as shown in the following table:
expression will be 2 if bit 1 of i is set and zero other-
wise. The binary values of i will be: 100, 011, 010 state R U
and 001. Only the second and third values have bit 1 TOP 0 0
set so the program will print four lines: BOTTOM 0 0
DOWN 1 0
0 UP 1 1
2
2 The state transition diagram showing the states
0 and the logical conditions that cause transitions be-
tween them is:
S==0
L==1 TOP
Question 2
One possible solution is: UP DOWN

/* Count and return the number of blank (space) BOTTOM


characters in the string s. */ S==1 L==1

int blanks ( char s[] )


and a tabular description of the state machine is:
{
int i, n ; starting input next
n = 0 ;
for ( i=0 ; s[i] ; i++ ) { state S L state
if ( s[i] == ’ ’ ) { TOP 0 X DOWN
n++ ;
}
TOP 1 X TOP
} DOWN X 0 DOWN
return n ; DOWN X 1 BOTTOM
}
BOTTOM 0 X BOTTOM
BOTTOM 1 X UP
Question 3 UP X 0 UP
UP X 1 TOP
As explained in the question, the inputs are the sun-
shine detector S, and the flag limit detector L. The where the ”X” indicates that an input has no effect.
two outputs are U the motor up/down control and R, However, this solution will not work properly if
the motor on/off control. the state transitions happen so fast that the limit
There are three useful combinations of outputs: switch will still be active (L 1) after the controller
off, motor going up, and motor going down. How- has spent just one clock period in the UP or DOWN
ever, if we design the controller using only three states. In this case the controller would immediately

midtermsol.tex 1
transition from UP to DOWN to BOTTOM states without A B

moving the flag very far. To avoid this problem we


can either slow down the state transitions (by using a
slow clock) or add two additional states as shown in
the state transition diagram below: Y0
L==1 S==0
TOP
Y1

UP DOWN0
Y2
L==0 L==0
Y3
UP0 DOWN

BOTTOM
S==1 L==1

for which the state transition table is:

starting input next


state S L state
TOP 0 X DOWN0
TOP 1 X TOP
DOWN0 X 0 DOWN
DOWN0 X 1 DOWN0
DOWN X 0 DOWN
DOWN X 1 BOTTOM
BOTTOM 0 X BOTTOM
BOTTOM 1 X UP0
UP0 X 0 UP
UP0 X 1 UP0
UP X 0 UP
UP X 1 TOP

The outputs for the DOWN0 and UP0 would be the


same as the outputs for the DOWN and UP states re-
spectively.
Either solution is acceptable.

Question 4
The logic equations for each of the four outputs can
be written in sum-of-products form as:
Y0 AB
Y1 AB
Y2 AB
Y3 AB
and a schematic diagram for the decoder is:

You might also like