S215  09 1202     
IL02-30 Class Exercise
15 points

Note: The switches and the LEDs are numbered 7 6 5 4 3 2 1 0
void main (void)
{
unsigned char x;
InitPorts();
//----------------------------------
while (1==1)
{
//|||||||||||||||||||||||||||| MAIN LOOP |||||||||||||||||||||||
x = SWITCHES & 0b00111100;
LEDS = x;
//||||||||||||||||||||||| END OF MAIN LOOP |||||||||||||||||||        
}
}

1. If all the switches are on, which LEDs are on? Circle the ones that are on: 7 6 5 4 3 2 1 0

2. If the switches contain 11001001, which LEDs are on?
Circle the ones that
    are on: 7 6 5 4 3 2 1 0

void main (void)
{
unsigned char x;
x = 0;
InitPorts();
//----------------------------------
while (1==1)
{
//|||||||||||||||||||||||||||| MAIN LOOP |||||||||||||||||||||||
LEDS = 0;        //Turn off all LEDs
x = SWITCHES & 0b00000111;

if (SW3==1) LED0 = 1;
if (x > 0)  LED1 = 1;
if (x == 0) LED2 = 1;

//||||||||||||||||||||||||| END OF MAIN LOOP |||||||||||||||||        
}
}

3. If all the switches are off, which LEDs are on? ___________

4. If only switch 3 is on, which LEDs are on? __________

5. If only switch 0 is on, which LEDs are on? __________
void main (void)
{
unsigned char x;
x = 0;
InitPorts();
//----------------------------------
while (1==1)
{
//|||||||||||||||||||||||||||| MAIN LOOP ||||||||||||||||||||||
if (PBdl()==1)
  //PBdl returns a 1 if a leading edge has been detected.

    x = x + 1;
DispFP(x, 0);

//||||||||||||||||||||||||| END OF MAIN LOOP ||||||||||||||||       
}
}

6. If the pushbutton is pressed 5 times, what number will be displayed? _________

7. From a fresh start, if the pushbutton is pressed and remains held down for several seconds, what will be displayed?
     a. The display will rapidly count up, starting at zero.
     b. 0 will be displayed.
     c. 1 will be displayed.
     d. 2 will be displayed.










--- Go to next page ---







#include "s215-header13.h"
unsigned char Mult(unsigned char x, unsigned char y);
#pragma code
//||||||||||||||||||||| BEGINNING OF MAIN PROGRAM |||||||||||||
void main (void)
{
unsigned char a, b, c, x, y;
x = 0;
InitPorts();
//----------------------------------
while (1==1)
{
//|||||||||||||||||||||||||||| MAIN LOOP |||||||||||||||||||||
x = SWITCHES;
y = 2;
a = 3;
b = 4;

c = Mult(a, b);
DispFP(c, 0);

//||||||||||||||||||||||||| END OF MAIN LOOP |||||||||||||||       
}
}
//||||||||||||||||||||||| END OF MAIN PROGRAM ||||||||||||||

unsigned char
Mult(unsigned char x, unsigned char y)
{
    unsigned char z;
    z = x * y;
    return z;
}

Note: There is a trick or two in the following questions.

8. If 00000101 is put into the switches, what number will be displayed? _________

9. If 00000011 is put into the switches, what number will be displayed? _________