0

I want to input 2 numbers into ATmega32 by keypad.
By my professor code. This project is quite hard for me, I don't fully understand the code.

The question is:
Input two hexadecimal numbers by buttons and save to R20, then display the number of 1s and 0s by using 7-segment LEDs.

This not the full code for the question:
only for the keypad, this is the part I stuck.

The problem is to input the two numbers, as the code only work for one input. If I press the second time, the previous number will be deleted.

How can I solve this?

.include "m32def.inc"

.EQU KEY_PORT = PORTA
.EQU KEY_PIN = PINA
.EQU KEY_DDR = DDRA 

          LDI R20,HIGH(RAMEND)
          OUT SPH, R20
          LDI R20, LOW(RAMEND)
          OUT SPL, R20
          LDI R21, 0xFF
          OUT DDRC, R21
          LDI R20, 0xF0
          OUT KEY_DDR,R20

GROUND_ALL_ROWS:
               LDI R20,0x0F
           OUT KEY_PORT, R20

WAIT_FOR_RELEASE:
               NOP
           IN R21, KEY_PIN
           ANDI R21, 0x0F
           CPI R21, 0x0F
           BRNE WAIT_FOR_RELEASE

WAIT_FOR_KEY:
               NOP
           IN R21, KEY_PIN
           ANDI R21, 0x0F
           CPI R21, 0x0F
           BREQ WAIT_FOR_KEY
           CALL WAIT15MS
           IN R21,KEY_PIN
           ANDI R21, 0x0F
           CPI R21, 0x0F
           BREQ WAIT_FOR_KEY
           LDI R21, 0b01111111
           OUT KEY_PORT, R21
           NOP
           IN R21, KEY_PIN
           ANDI R21,0x0F
           CPI R21, 0x0F
           BRNE COL1
           LDI R21, 0b10111111
           OUT KEY_PORT, R21
           NOP
           IN R21, KEY_PIN
           ANDI R21, 0x0F
           CPI R21,0x0F
           BRNE COL2
           LDI R21,0b11011111
           OUT KEY_PORT, R21
           NOP
           IN R21, KEY_PIN
           ANDI R21, 0x0F
           CPI R21, 0x0F
           BRNE COL3
           LDI R21,0b11101111
           OUT KEY_PORT, R21
           NOP
           IN R21, KEY_PIN
           ANDI R21, 0x0F
           CPI R21, 0x0F
           BRNE COL4

COL1:
              LDI R30,LOW( KCODE0<<1)
          LDI R31, HIGH( KCODE0<<1)
          RJMP FIND
COL2:
              LDI R30,LOW( KCODE1<<1)
          LDI R31, HIGH( KCODE1<<1)
          RJMP FIND        
COL3:
              LDI R30,LOW( KCODE2<<1)
          LDI R31, HIGH( KCODE2<<1)
          RJMP FIND         
 COL4:
              LDI R30,LOW( KCODE3<<1)
          LDI R31, HIGH( KCODE3<<1)
          RJMP FIND                        
MATCH:
              LPM R20,Z
          OUT PORTC,R20
          RJMP GROUND_ALL_ROWS
FIND:
              LSR R21
          BRCC MATCH
          LPM R20,Z+
          RJMP FIND

WAIT15MS:
              LDI R16,64
DELAY1: LDI R17,200
DELAY2: LDI R18,19
DELAY3: NOP
          DEC R18
          BRNE DELAY3
          DEC   R17
          BRNE DELAY2
          DEC R16
          BRNE DELAY1
          RET

.ORG 0x300

KCODE0: .DB '0','4','8','C'
KCODE1: .DB '1','5','9','D'
KCODE2: .DB '2','6','A','E'
KCODE3: .DB '3','7','B','F'

This code is to find the matrix in the keypad, but I am using proteus to simulate the code:

Simulate ATmega32

zx485
  • 28,498
  • 28
  • 50
  • 59
  • Correct me if I'm wrong. You need to click twice on keypad and then display those two clicked numbers in one 7seg display in sequence? If yes, after the recognition of first number (you already have this solution) you need to store this result and wait for another click. Aftter two of this actions, display 1st and 2nd value on display. – dunajski Jun 14 '19 at 12:01
  • Yes, is it. the simulate picture shows a 7 led as a test, I trying on my keypad, not a 7 seg yet. – Anime Lover Jun 14 '19 at 12:57

0 Answers0