Freescale Semiconductor, Inc.
Application Note
Code Listings
;Check the entries in the table, to find the ADC value range
;that corresponds to the ADC data register value.
KeyLoop:
LDA
CMP
BLS
LDA
CMP
BLS
INCX
INCX
KeyTable+1,X
ADValue
Match
KeyTable,X
ADVAlue
Match
;Check high range
;Within range
;Check low range
;Within range
;Point to next table record
;Increment the key value, when a match is made,
;the variable will contain the key that was pressed.
INC
BRA
InKey
KeyLoop
; At this point, InKey variable holds keypress information
; One can arbitrate the key press here. For this simple example
; we just repeat the main loop
Match:
BRA
MainLoop
* ----------------------------------------------------------------------------------
; Key lookup table. Holds the minimum and maximum ADC values
; which identify a particular key in the resistor ladder
* ----------------------------------------------------------------------------------
KeyTable:
NoKey
Key1
Key2
Key3
Key4
Key5
Key6
Key7
Key8
FCB
FCB
FCB
FCB
FCB
FCB
FCB
FCB
FCB
$EF,$FF
$00,$0F
$0F,$2F
$2F,$4F
$4F,$6F
$6F,$8F
$8F,$AF
$AF,$CF
$CF,$EF
;No key pressed
* ----------------------------------------------------------------------------------
; Vector definitions
* ----------------------------------------------------------------------------------
ORG
FDB
$1FFE
Start
;Reset vector
AN1775 Rev. 1
For More Information On This Product,
Go to: www.freescale.com