![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Dont know if this would be the correct topic for this coding, so just redirect me if I'm wrong.
I'm using MiniIDE to program my 68HC11, what I'm trying to do is have a 4x4 keypad input unique signitures to PortC (input, which is setup as KYTAB) which then will look towards a table (Display) and will display a value on a seven segment display in hex format (0-F) depending on the button depressed on the keypad. If you have need of further details, I will be happy to post. Any help would be greatly appreciated. * Matrix Keypad * Based on a lab written by Donald Weiman * These techniques are adapted from Spasov (1 ed), listing 9.10, p 280 REGBAS EQU $1000 ;base address for register access PORTC EQU $03 ;offset to address of PORT C (switches) PORTB EQU $04 ;offset to address of PORT B (7-segment display) DDRC EQU $1007 ;offset to address of Data Direction Register for Port C RAM EQU $2000 ;put the program at the start of user RAM STACK EQU $0FFF ;put the stack at the top of the user RAM IOBITS EQU %11110000 ;data to make bits 0-3 input, bits 4-7 output MAX EQU 16 ;number of keys to check DLYDTA EQU 22222 ;data for a 10 mS delay with 2 MHz clock frequency ALLOFF EQU %00000000 ;data to turn all LED segments off * .................................................. ................................... ORG RAM BRA START FCC 'Matrix Keypad, Christopher C. VanOverbake, 2/13/05' START: LDS #STACK ;Load Stack Pointer LDX #REGBAS ;puts 1000 into the X register LDAA #IOBITS ;Loads the I/O info into Acc A LDS DDRC ;Stores Acc A into the DDRC LDAA #ALLOFF ;Loads the info for the LEDs into Acc A STAA PORTB,X ;Stores Acc A (Turns off) Port B MAIN: BSR KEYUP ;Jump to keyboard up BSR KEYDN ;Jump to Keyboar down BSR DISPLAY ;display on 8 segment display BRA MAIN ;loop back to main *****************************SUBROUTINES********** ****************************** *****************************Keyboard up**************************************** ************************************************** ********* * This subroutine waits until all keys are released * Input: (IX) = base address of the register block * Output: none * No registers are affected KEYUP: PSHA ;preserves all data KEYUP1: BSR IDKEY ;jumps to keypad CMPA #0 ;Compares A with 0 BNE KEYUP1 ;Branch if Not = 0 to KEYUP1 *arrive here when it is equal to 0 BSR D10MS ;Jumps to ten millisecond delay BSR IDKEY ;jumps to keypad CMPA #0 ;Compares A with 0 BNE KEYUP1 ;Branch if Not = 0 to KEYUP1 *arrive here when it is equal to 0 PULA ;Restor data RTS ;Return from subroutine. ************************************************** ****************************** *****************************Keyboard Down************************************ ************************************************** ****************************** * This subroutine waits for any key to be pressed and returns with its key code in ACCA * Input: (IX) = base address of the register block * Output: (ACCA) = key code * No registers other than ACCA are affected KEYDN: PSHB ;Preserve contents of register B KEYDN1: BSR IDKEY ;Branches to IDkey CMPA #0 ;Compares A with 0 BEQ KEYDN1 ;Branch if Equal to 0 to KEYDN1 *arrive here when it is not equal to 0 BSR D10MS ;Jumps to 10 millisecond Delay PSHA ;Preserves bit data BSR IDKEY ;jump to PULB ;Restore contents of accumultor B CBA ;Compares B to A BNE KEYDN1 ;Branch if Not = to 0 to KEYDN1 *arrive here when B is equal to A PULB ;Restore contents of register B RTS ;Return from subroutine ************************************************** ******************************* ***************************Keyboard ********************************************* ************************************************** ******************************* * This subroutine returns a key code from the keypad * Input: (IX) = base address of the register block * Output: (ACCA) = key code (01 - 16), or 00 if no key is pressed * No registers other than ACCA are affected IDKEY: PSHY ;Preserve contents of regester Y PSHB ;Preserve contents of acumulator B LDY #KYTAB ;Load Index Y with KYTAB data LDAA #MAX ;Load Acc A with 16 IDKEY1: BEQ IDKEY2 ;Branch if Acc A's = to 0 LDAB 0,Y ;Load Acc B with 0 STAB PORTC,X ;Store Acc B on Port C PSHA ;Preserve contents of acumulator A LDAA PORTC,X ;Load Acc A with Port C Data CBA ;Compare B with A PULA ;restore contents of acumulaor A BEQ IDKEY2 ;Branch if A/B is = with 0 *arrive here when A/B isn't = to 0 INY ;Increment Index Register Y DECA ;Decrement A BRA IDKEY1 ;loop to decision acc A = 0 *return with the key code in Acc A IDKEY2: PULB ;Restore contents of accumulator B PULY ;Restore contents of accumulator Y RTS ;Return from subroutine ************************************************** ******************************* *****************************Delay**************** ******************************* ************************************************** ******************************* * This is a software time delay used for key debouncing * The delay will be 10 mS with a 2 MHz Clock * Input: none * Output: none * No registers are affected D10MS: PSHX ;Push X LDX #DLYDTA ;Load Accumulator X with 22222 (delay data for 10ms) D10MS1: BEQ D10MS2 ;Branch to D10MS2 if equal to zero DEX ;Decrement X BRA D10MS1 ;Branch always to D10MS1 D10MS2: PULX ;Pull X RTS ;Return from subroutine ************************************************** ****************************** ************************** Display******************************************* *** ************************************************** ****************************** * This subroutine will display an alphanumeric character on a seven-segment * display connected to Port B * Input: (ACCA) = key code * Output: none * No registers are affected display * This is the lookup table used by the DISPLAY subroutine * the lookup table for the Seven-Segment Display assumes that segments * "a" through "g" are driven by bits 6 through 0 respectively. Display: PSHX ;Push X FCB %11111111 ;dummy data for keycode 00 FCB %10000001 ;data for keycode 01 "0" FCB %11001111 ;data for keycode 02 "1" FCB %10010010 ;data for keycode 03 "2" FCB %10000110 ;data for keycode 04 "3" FCB %11001100 ;data for keycode 05 "4" FCB %10100100 ;data for keycode 06 "5" FCB %10100000 ;data for keycode 07 "6" FCB %10001111 ;data for keycode 08 "7" FCB %10000000 ;data for keycode 09 "8" FCB %10000100 ;data for keycode 10 "9" FCB %10001000 ;data for keycode 11 "A" (ENT) FCB %11100000 ;data for keycode 12 "B" (CLR) FCB %10110001 ;data for keycode 13 "C" (CM) FCB %11000010 ;data for keycode 14 "D" (TST) FCB %10110000 ;data for keycode 15 "E" (EXM) FCB %10111000 ;data for keycode 16 "F" (STP) PULX ;Pull X RTS ;Return from subroutine ************************************************** ******************************** * This is the lookup table used by the IDKEY routine * this lookup table assumes that the connections are: * Keypad Port Bit * Pin 8 (Column 4) 0 (input) * Pin 7 (Column 3) 1 (input) * Pin 6 (Column 2) 2 (input) * Pin 5 (Column 1) 3 (input) * Pin 4 (Row 4) 4 (output) * Pin 3 (Row 3) 5 (output) * Pin 2 (Row 2) 6 (output) * Pin 1 (Row 1) 7 (output) ************************************************** ****************************** * don't forget to put the actual lookup table here * you'll have to figure this part out * hint: check out your lecture notes KYTAB: PSHX ;Push X FCB %11101110 ;keycode 16, row 4, column 4 FCB %11101101 ;keycode 15, row 4, column 3 FCB %11101011 ;keycode 14, row 4, column 2 FCB %11100111 ;keycode 13, row 4, column 1 FCB %11011110 ;keycode 12, row 3, column 4 FCB %11011101 ;keycode 11, row 3, column 3 FCB %11011011 ;keycode 10, row 3, column 2 FCB %11010111 ;keycode 09, row 3, column 1 FCB %10111110 ;keycode 08, row 2, column 4 FCB %10111101 ;keycode 07, row 2, column 3 FCB %10111011 ;keycode 06, row 2, column 2 FCB %10110111 ;keycode 05, row 2, column 1 FCB %01111110 ;keycode 04, row 1, column 4 FCB %01111101 ;keycode 03, row 1, column 3 FCB %01111011 ;keycode 02, row 1, column 2 FCB %01110111 ;keycode 01, row 1, column 1 PULX ;Pull X RTS ;Return from subroutine ************************************************** ***************************** |
|
|
|
|