Experiment #8 - California State University, Northridge

advertisement
California State University, Northridge
ECE 425L
Experiment #8
KEYPAD INTERFACING
Navya Paleru
Ari Mahpour
Group 9
3-2-10
Introduction:
This experiment introduces interfacing a keypad directly to 68HC12 and scan it
without a switch bounce ie, displaying the inputs of the keypad while eliminating switch
bounce. We understand the concept behind switch debouncing and write a program that
performs software debouncing by creating a time delay of 100 ms.
Procedure:
Part A:
The first step is to connect the keypad ROW 4:1 signals to pull up resistors (10k
ohms) and port h7:4.PH3:0 are lower nibble that are outputs.PH7:4 are upper nibble that
are inputs.when we give 1110 (E) to PH3:0 we can read any of the following keys ‘*’,
‘7’, ‘4’, ‘1’.when we give 1101(D) to PH3:0 we can read any of the following keys ‘0’,
‘8’, ‘5’, ‘2’. when we give 1011(B) to PH3:0 we can read any of the following keys ‘#’,
‘9’, ‘6’, ‘3’. when we give 0111(7) to PH3:0 we can read any of the following keys ‘D’,
‘C’, ‘B’, ‘A’.If a key is pressed the we check the corresponding column . Then we
proceed to check the corresponding row and then we print the value in the monitor by
using D-Bug 12 utility.
Part B:
The second step we use the same hardware as of the first part and we create a
time delay debounce of 100 ms for the buttons. After creating the program we connect
the keypad as shown in figure 1 using port 0 through 7. We connect 10 K resistors to
Rows 1, 2, 3 and 4 with a voltage supply of 5 volts. The pins for Port H are given in
figure 1 making easier to connect the keypad to the EVboard.
Results and Interpretation
Part A
The first portion of this laboratory experiment required the students to
simply press a button and attempt to read it from the memory. This was specifically done
just to test the functionality of the HC12 and determine whether all the circuitry was set
up correctly. Had the values not have been displayed properly, only the circuitry would
be at fault rather than the assembly code itself.
The difficultly that was faced with this portion of the experiment was
understanding the cryptic hexadecimal values that were retrieved from the memory. In
addition, it was hard to remember that the columns and rows moved from highest to
lowest bits so determining whether the wiring was correct or not was a bit challenging at
first. In order to combat with this issue, we developed a spreadsheet that would convert
our values back and forth between hexadecimal and binary. That easily enabled us to
determine what our outputs were supposed to be. After interpreting the data properly,
there were no difficulties in understanding the outputs and we had determined that our
wiring and circuitry as a whole was correct.
Part B
In the second portion of the laboratory experiment, the code was to be put to test.
The outputs worked flawlessly but were not represented in the most elegant manner. The
number and letter outputs had been represented in 8-bit hexadecimal which meant that
there were leading zeros in front of every output. The asterisk and pound sign were
represented as an ASCII character so they did not have any leading characters. Though it
was not the prettiest output it managed to work quite well.
The most challenging part of this specific exercise was determining the delays.
Using various methods of trial and error we managed to get the code running and
working properly but various delay functions had to be manually added into the source
code. The easier part was the coding scheme of the program itself. The basic algorithm
was given in the assignment and it was to be run in a loop so it was not too long. The
bulk of it, however, was the trial and error delay statements.
Conclusion:
This laboratory experiment required a much deeper understanding of the
architecture of the Motorola HC12 than previous laboratory experiments. We had to
understand the concept of timings in the architecture itself and how the ports interact with
interrupts. A basic knowledge of polling and electronics was also required to accomplish
this laboratory experiment. For the future, some changes that could be made would be a
more aesthetically pleasing output. It was very hard to read the line of outputs and did not
make it easy to present to the instructor. Also, in the future, future implementations of the
hexadecimal-binary spreadsheet might be taken into consideration. It saved a very
significant amount of time and made the experiment move in a much smoother fashion.
Program:
* Set directives
STACKTOP
EQU
$8000
DDRH
EQU
$0025
DDRH_INI
EQU
$0F
PORTH
EQU
$0024
DLYVALUE
EQU
$FFFF
PUTCHAR
EQU
$FE04
OUTHEX
EQU
$FE16
;65535 cycles, roughly 33ms
* Set memory referenced values
ORG
$0800
LETTER_E
FCB
$0E
;800
LETTER_D
FCB
$0D
;801
LETTER_B
FCB
$0B
;802
NUMBER_SEVEN
FCB
$07
;803
NOKEY
FCB
$F0
ORG
$0850
FCB
$7D,$EE,$ED,$EB,$DE,$DD,$DB
HEXTABLE
,$BE,$BD,$BB,$E7,$D7,$B7,$77
* Begin code
* Set up PORTH
ORG
$0900
LDS
#STACKTOP
LDAA
#DDRH_INI
STAA
DDRH
;BiDi's
* Load E, D, B, and 7 and store it to PORTH
* Cycle through columns to detect those letters
RESTART:
LDX
CYCLE:
LDY
YDELAY:
#$0800
#$0
CPX
#$0804
BEQ
RESTART
LDAB
1,X+
STAB
PORTH
BRA
YDELAY ;STOPS READING TOO FAST
INY
CPY
#$FF ;Compare Y to %1111_1111
BNE
YDELAY
LDAA
PORTH
TFR
;Continue after hitting $FF
A,B
ANDB
#%11110000
CMPB
NOKEY
BNE
FINDKEY
BRA
CYCLE
;Grab [7:4] bits
FINDKEY:
PSHA
LDAB
;Push the value-in-question to the stack
#$0 ;Start the counter (counter = print value)
CHKRSTRT:
LDX
#$0850
ABX
;X <-- B + X
LDAA
0,X
CMPA
0,SP ;Compare table position with top of stack
BEQ
;Load table values
HEXPRINT
INCB
HEXPRINT:
CMPB
#$0E
BEQ
ASCIICHK
BRA
CHKRSTRT
PULA
;Leave for * or #
;Clear stack
CLRA
ASCIICHK:
LDX
OUTHEX
JSR
0,X
BRA
DELAYONE
LDAA
#$7E
;If value = *, print *
CMPA
0,SP
;Else print #
BEQ
ASTPRINT
PULA
;Print current B reg to hex
;Clear stack
CLRA
LDAB
#$23
LDX
PUTCHAR
JSR
0,X
BRA
DELAYONE
;Load up pound sign in hex
;Print pound
ASTPRINT:
PULA
;Clear stack
CLRA
DELAYONE:
LDAB
#$2A
LDX
PUTCHAR
JSR
0,X
BRA
DELAYONE
LDX
#DLYVALUE ;Time delay routine
JSR
DELAY
LDX
#DLYVALUE;Run twice, total delay ~66ms
JSR
DELAY
LDX
#DLYVALUE
JSR
DELAY
BRA
DELAYPRESS:
DELAY:
;Load up asterisk in hex
RELCHK
LDX
#DLYVALUE
JSR
DELAY
LDX
#DLYVALUE
JSR
DELAY
LDX
#DLYVALUE
JSR
DELAY
DEX
BNE
RTS
DELAY
;Print asterisk
RELCHK:
LDAA
PORTH
ANDA
DELAYTWO:
#%11110000
;Grab [7:4] Bits
CMPA
NOKEY
BEQ
DELAYTWO
BRA
RELCHK
LDX
#DLYVALUE ;Time delay routine
JSR
DELAY
LDX #DLYVALUE
;Run twice, total delay ~66ms
JSR
DELAY
LDX
#DLYVALUE
JSR
JMP
DELAY
RESTART
Download