|
References:
|
Section I. Using an Interrupt.
The 6802 microprocessor is widely used for the control of traffic lights. In Part II of this experiment
you will program this microprocessor to control the traffic lights at an intersection. In this section
you will first learn how to operate the traffic standard and how to use an interrupt.
The traffic standard you will use has 5-volt light bulbs. The current required by each light bulb is
approximately 110 mA, whereas the PIA can safely supply only about 5 mA. To supply the current
to the bulb (and to protect the microcomputer), you are to use a Darlington transistor amplifier.
Figure 2.1 shows the pinout for a ULN2003 chip that contains seven Darlington amplifiers. (Each
Darlington in this chip can supply up to 500 mA; they can be used in parallel to supply higher
currents.) The figure also shows a 5-volt light bulb connected properly to one of the Darlington
outputs (pin 16). Note that pin 8 is grounded and pin 9 is connected to the +5 V terminal of the
power supply in order to provide the power for the transistors on the chip.
The inverter symbol in each line of the ULN2003 is misleading. Placing a low (0V) on an input line will not force a high (+5V) on the corresponding output. Each Darlington amplifier has an open-collector output; the bulb connected to that output acts as a pullup resistor. It is the +5V connection that pulls up the output signal via that bulb resistance.
A high on input pin 1 turns on
the Darlington, forces a low
on output pin 16 and energizes
the light bulb. A low on input
pin 1 turns off the Darlington,
permits the terminal of the
light bulb which is connected
to pin 16 to be pulled high
through the resistance of the
bulb, and turns off the light.
1. Connect the top red bulb of the traffic standard to the first Darlington of the chip as shown in Fig.
2.1. Connect the input of the same Darlington to pin PA6 of the PIA. With this circuitry you are
ready to use the microprocessor to control the operation of that bulb.
2. There is a normally-open (NO) momentary-contact switch on the traffic standard. In this section
of the experiment you will cause the bulb to blink continuously until that switch is pushed. After the
switch is pushed, the light will stay on continuously. (At least one of the switches on the traffic standards in the lab have been discovered to have been labeled backwards by the manufacturer. You can use an ohmmeter to determine if your switch is labe
lled correctly.)
Figure 2.2 shows how to connect the switch to a pulldown resistor and buffer (inverter) in order to provide a high signal
to the PIA when the switch is open but a low signal when the switch is closed. The buffer assures
that the voltage level delivered to the PIA is in the correct (TTL) range.
One way to determine when to change the light from blinking operation to continuous operation would be
to connect the buffer output of the switch circuit to a PIA input (say, PB0) and program the computer
to periodically check that input. This checking process is called polling. How often would the program have
to check the status of the switch?
Instead of polling, you are to use a hardware interrupt to change the light to blinking operation.
Construct the switch circuit of Fig. 2.2.
Connect the buffer output to the CA1 input of
the PIA. Use the jumper J1 on the MEK-6802-D5 to connect the output of the PIA to
the input of the microprocessor. (See
page 2-6 of the User's Manual.)
3. Configuration and Initialization: The microprocessor and PIA must be initialized to prepare them to handle the interrupt signal. The first program segment shown below will perform the initialization. It:
The second program segment is the interrupt service routine that stops the blinking and turns on the
light continuously. (The service routine would end in an RTI command if there were some action in
the main program program to return to. In this instance, the computer halts with the light glowing
continuously.)
The third program segment is the main program that blinks the light. You must hand assemble this part of the program. That is, you must determine the line numbers and the hexadecimal machine code that belongs in the first two col umns of the table.
4. Enter the program segments into the MEK-6802-D5, run the program to blink the light that is connected to PA6 of the PIA, then push
the switch to engage the interrupt. After the interrupt occurs, examine the registers and the stack.
0000 | 8E E418 | LDS #$E418 | Initialize user stack pointer | |
0003 | CE E000 | LDX #$E000 | Establish address of IRQ service routine | |
0006 | FF E43C | STX $E43C | Store address in IRQ interrupt vector | |
*Configure PIA | ||||
0009 | 7F E481 | CLR $E481 | Enable DDRA (Clear bit 2 of CRA) | |
000C | 86 FF | LDA A #$FF | Make port A all outputs ( particularly, PA6) | |
000E | B7 E480 | STA A $E480 | (Set all bits of DDRA) | |
0011 | C6 04 | LDA B #$04 | Enable DRA (A = %0000 0100) | |
0013 | F7 E481 | STA B $E481 | (Set bit 2 of CRA) | |
0016 | B5 E480 | BIT A $E480 | Clear any IRQA flag (Read DRA) | |
0019 | B7 E480 | STA A $E480 | Set DRA bits (Output PA6 low; turn on light) | |
001C | 86 05 | LDA A #$05 | Enable CA1 on falling edge; retain DRA enable | |
001E | B7 E481 | STA A $E481 | (Set bits 0 and 2, clear bit 1, of CRA) | |
0021 | 0E | CLI | Clear µP interrupt mask | |
0022 | 7E 0030 | JMP $0030 | Jump to main program |
ORG #$E000 | Place IRQ service routine at $E000 | |||
E000 | B5 E480 | BITA #$E480 | Read DRA to clear IRQA interrupt flag | |
E003 | 86 FF | LDAA #$FF | Turn on light at PA6 | |
E004 | B7 E480 | STAA $E480 | (Set bits of DRA, particularly PA6) | |
E007 | 3F | SWI | Halt the program |
0030 | BEGIN | LDA B #$FF | Set bit six of DRA | |
STA B $E480 | (PA6 high; light on) | |||
LDA A #$05 | Wait 0.5 seconds | |||
WAIT1 | JSR DELAY | Go to 0.1 second delay | ||
DEC A | ||||
BNE WAIT1 | ||||
CLR B | Clear bit six of DRA | |||
STA B $E480 | (PA6 low; light off) | |||
LDA A #$0A | Wait 1 second | |||
WAIT2 | JSR DELAY | Go to 0.1 second delay | ||
DEC A | ||||
BNE WAIT2 | ||||
JMP BEGIN | Repeat blink | |||
DELAY | LDX #$2AB9 | 0.1 second counter | ||
LOOP | DEX | 0.1 second loop | ||
BNE LOOP | ||||
RTS |
Section II. Controlling Traffic Lights at a Normal Intersection
You are to control the traffic lights at a normal intersection. The light is to have the dwell times shown in the table below. The timing of the lights is also displayed in Figure 2.3.
Light | North-South Street |
East-West Street |
---|---|---|
Red Green Amber |
13 seconds 13 seconds 8 seconds |
18 seconds 3 seconds 3 seconds |
Amber must precede red. Green follows red without an intervening amber, but with a one second
delay after the cross street has turned red. The cycle time for the traffic light is 29 seconds. You must
control the lights for both the north-south street and the east-west street.
Connect the six lights of your 5-volt traffic standard
to a power supply and to pins PA1-PA6 of the user
PIA on the MEK-6802-D5 in the fashion used in
Section I. You will need to use a separate Darlington
amplifier for each light.
Write a program that will control the lights according to the pattern described above. Your
initialization routine need not deal with the stack or interrupts. Hand assemble the program. Enter
your assembled program into the MEK-6802-D5. Then run the program and demonstrate it to your
instructor.
Section III. Light Control to Accommodate Emergency Vehicles ()
Assume that a fire-house is located in the block north of the intersection. When an emergency vehicle leaves the fire-house, heading south, the north-south traffic light should be green. A sensor to detect the approach of an emergency vehicle is normally activated by radio or by a strobe light. You will activate it with a switch. Upon activation of the emergency vehicle sensor, the traffic signals facing north-south will immediately give a blinking amber light for 15 seconds and then revert to normal operation. During this 15 second period the east-west street traffic lights will operate as follows:
a) If red when the emergency vehicle signal is activated, it will remain red for the 15 seconds the
north-south street carries the flashing amber;
b) If amber when the emergency vehicle signal is activated, it will complete the 3-second amber
period and then turn red and remain red until the end of the 15 seconds that the north-south signal
carries the flashing amber;
c) If green when the emergency vehicle signal is activated, it will immediately give a two second signal of solid amber, then flashing red for 4 seconds, and finally turn solid red for the remainder of the 15 second period that the north-south street gives the flashing amber.