OBJECTIVE: Using the information in your course notes about the Stanton Trainer (pp.z6-z10) (coming some online) and the following information, write a program to decode the Stanton Trainer's 16-key keypad. The values for the keys will be in HEX format. When a key on the keypad is depressed, light the 7-segment LEDs on the Stanton Trainer to display the corresponding HEX value. Also display the keys value on the screen. Both displays should be off (not displaying anything) then no key is being depressed.
EQUIPMENT NECESSARY:
| Stanton Trainer |
PRE-LAB:
1. Study the Stanton Trainer schematics
from the Course Notes and read the following lab information.
2. Determine which jumper settings to use
on the Stanton Trainer for this particular experiment.
3. Write a C program to initialize the
8255 and determine when a key is pressed
on the HEX keypad. The program should display the value if the pressed
key on the 7-segment LEDs and on the screen. All displays should
be turned off by your program when there is no key on the Stanton being
pressed. The program should be run continuously.
DURING LAB:
1. Set the appropriate jumper(s) on the
Stanton board.
2. Run your program and have the TA verify
that it works.
POST-LAB:
Write a report which discusses your software
and how it interacts with the keypad and LEDs on the Stanton Trainer.
Also describe the jumper selection on the Stanton Trainer.
PROGRAMMING COMMENTS:
| SEND OUT ON PORT C | READ VIA PORT B |
| PC7 | PC6 | PC5 | PC4 | PB7 | PB6 | PB5 | PB4 | Depressed Key | ||
| 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 0 | ||
| 1 | 1 | 0 | 1 | 1 | ||||||
| 1 | 0 | 1 | 1 | 2 | ||||||
| 0 | 1 | 1 | 1 | 3 |
| PC7 | PC6 | PC5 | PC4 | PB7 | PB6 | PB5 | PB4 | Depressed Key | ||
| 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 4 | ||
| 1 | 1 | 0 | 1 | 5 | ||||||
| 1 | 0 | 1 | 1 | 6 | ||||||
| 0 | 1 | 1 | 1 | 7 |
| PC7 | PC6 | PC5 | PC4 | PB7 | PB6 | PB5 | PB4 | Depressed Key | ||
| 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 8 | ||
| 1 | 1 | 0 | 1 | 9 | ||||||
| 1 | 0 | 1 | 1 | A | ||||||
| 0 | 1 | 1 | 1 | B |
| PC7 | PC6 | PC5 | PC4 | PB7 | PB6 | PB5 | PB4 | Depressed Key | ||
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | C | ||
| 1 | 1 | 0 | 1 | D | ||||||
| 1 | 0 | 1 | 1 | E | ||||||
| 0 | 1 | 1 | 1 | F |
To determine by software when a keypad key has been hit, sequentially send out Test Outputs shown in the table above. After each one has been sent out., Port B should be read, then depending on the location of the '0' in the bit field (PB7 - PB4), you will know exactly which key has been depressed.
To active the LEDs on the Stanton (after setting the correct jumper(s)), you must send the correct byte of information to Port A of the 8255. This byte corresponds to the particular segments you wish to light-up to display the HEX value of the key depressed.
NOTE: As each of the test patterns are sent out, C0 and C1 should both be set to 1 so that both the 7-seg displays on the Stanton board are enabled.
Here is some pseudo-code of how the program could (although there are several ways) be written:
---------------------------------------
while (keyboard is not hit )
/*the keyboard on the computer NOT the stanton */
{
init the 8255;
........
send "Test Output 1" to Port
C;
read Port B;
compare against the PB bit
fields listed above;
if not anyone of them, then
continue;
send "Test Output 2" to Port
C;
read Port B;
compare against the PB bit
fields listed above;
if not anyone of them, then
continue;
........
}
----------------------------------------
HINTS:
As you could imagine, the program could simply
be a huge CASE statement (for example) there is a clever way to send out
the bits that you want just by using the "shift" operators in C.
These operators are unary and allow you to shift a number by 1 bit (to
the left or right). In particular the operators are ">>" and "<<".
Then you could use bit-wise operators to check which number was the one
read from Port B.
Remember: Be careful of which bits in the 8bit fields are the ones that you wish to use.
7-Segment Displays: How do I know what byte
to write to port A to make the correct segments light up? Answer,
there should be a drawing that indicates which bit corresponds to which
segment. (Online coming soon)