Vous êtes sur la page 1sur 2

Tutorial Problems Week 2

Write the psuedo code, structure diagram and C program

Problem 1 Security Light


See Lab2

Problem 2 Power Switch


See Lab2

Problem 3 Hair Dryer


The hair dryer has a fan switch which is used to turn the fan on and off, and a heater switch which will
turn the heater on and off. (note the fan motor must be going while the heater is on, else the heater
will burn up)
Inputs
fan switch PINA_Bit0
heater switch PINA_Bit1

Outputs
fan motor
heater

PORTC_Bit0
PORTC_Bit1

Problem 4 Incrementing LEDS


The program will read the switch value on PINA, and then every second increment the seven
segment displays on PORTC until the value on PINA is reached

Problem 5 Flashing Christmas tree lights


8 Christmas tree lights are connected to Port C. (lights 0, 1, 2, 3, 4, 5, 6 & 7 ). The lights
initially are all off, then one by one (starting at bit0) every second until they are all on. The
lights will then flash on and off for five seconds, (flashing on/off within a second) The pattern
will then repeat.

Problem 6

Fridge door

You are to turn the fridge light on when the door is opened and off when the door is shut. If
the door is left open for more than 30 seconds then turn on a warning beeper pulsing every 2
seconds. Note you are to use the real time interrupts for your delay.
Inputs

Door sensor

Outputs

PINA_Bit0

Fridge light
Beeper

PORTB_Bit6
PORTD_bit1

Question 7

Two way light switch

A two way light switch is often seen in a hallway, where a light switch is placed at either end
of the hall. Either switch can be used to turn the light on or off. The interesting thing being
that if both light switches start in the off position, then when a light switch is turned on at one
switch, (light now on), then when the second switch is turned on the light will now turn off.
This can be shown electrically as below.

Light Bulb

Power

Inputs

Switch 1

Outputs

PINA_Bit0

Light bulb

PORTB_Bit6

Hint look for a change of state on the switches and if they change then to toggle the light and
then store the new state of the switches. Storing the state of the switches is simple if bit
masking is used.

Question 8

Robot Control

You are designing a robot to move toward a light source. Three digital photo sensors S L, SC,
and SR with sharply defined non overlapping fields of view are mounted at the front of the
robot pointing 45o to the left, straight ahead, and 45o to the right, respectively. Two wheels WL
and WR are powered depending on the output of the sensors. If the left sensor S L detects light,
the robot is pointing too far to the right, and the right wheel W R must be switched on to turn
the robot to the left. The opposite is necessary if the right sensor S R receives light. If the
forward-pointing sensor SC detects light, then both wheels WL and WR should be turned on. If
no sensor detects light then turn on the left wheel WL. Treat the sensors as having binary
outputs, i.e., either "on" or "off", and the powered wheels as being "on" or "off".
Inputs

Right Sensor SR
Center Sensor SC
Left Sensor SL

Outputs

PINA_Bit0
PINA_Bit1
PINA_Bit2

Right Wheel WR
Left Wheel WL

PORTC_Bit0
PORTC_Bit1

Vous aimerez peut-être aussi