0

I successfully implemented a keypad matrix in an atmega328 through polling in the main loop and now my goal is to do it only on key press (using pin change interrupt).

I'm using PORTB[3...0] for rows and PINC[2..0] for columns. However, I'm facing a strange problem while simulating the atmega328p in Proteus. PORTB and PINC are getting stuck on their last value which means that the program works only once (key press can be detected once)

This is the state of the ports initially. State of the ports initially

This is after the first successful key press. It can be noticed that some ports (responsible for the key pressed) are stuck. Some ports (responsible for the key pressed) are stuck

What have I tried:

I tried enabling and disabling pull up resistors for PORTB and tried to reinitialize the PORTB and PINC again after each interrupt but this didn't work. One thing that worked was setting all PORTB to 0 after each interrupt but I don't know how to do it for PINC.

.ORG 0X00
JMP START
.ORG 0X08
JMP PORT1_ISR

.ORG 0X100
START:
LDI R17, HIGH(RAMEND)
OUT SPH, R17
LDI R17, LOW(RAMEND)
OUT SPL, R17

; Initializing ports
LDI R16,0XFF 
OUT DDRB,R16
OUT DDRD,R16 
LDI R16,0X00 
OUT DDRC,R16 

;LDI R16, 0X0F
;OUT PORTC,R16

OUT PORTD,R16

;SBI PORTB,0 
;SBI PORTB,1 
;SBI PORTB,2 
;SBI PORTB,3

; Enabling interrupts
LDI R16, (1<<PCIE1)
STS PCICR, R16
LDI R16, (1<<PCINT8)|(1<<PCINT9)|(1<<PCINT10)
STS PCMSK1, R16
SEI

MAIN:
RJMP MAIN

.ORG 0X0500
PORT1_ISR:

; ROW 0 
CBI PORTB,0 
SBI PORTB,1 
SBI PORTB,2 
SBI PORTB,3

SBIS PINC,0 
LDI R20,0X06 ; CODE 1
SBIS PINC,1 
LDI R20,0X5B ; CODE 2
SBIS PINC,2 
LDI R20,0X4F ; CODE 3


; ROW 1 
SBI PORTB,0 
CBI PORTB,1 
SBI PORTB,2 
SBI PORTB,3

SBIS PINC,0 
LDI R20,0X66 ; CODE 4
SBIS PINC,1 
LDI R20,0X6D ; CODE 5
SBIS PINC,2 
LDI R20,0X7D ; CODE 6

; Row 2
SBI PORTB,0 
SBI PORTB,1 
CBI PORTB,2 
SBI PORTB,3

SBIS PINC,0 
LDI R20,0X07 ;CODE 7
SBIS PINC,1 
LDI R20,0X7F ;CODE 8
SBIS PINC,2 
LDI R20,0X6F ;CODE 9

; Row 3
SBI PORTB,0 
SBI PORTB,1 
SBI PORTB,2 
CBI PORTB,3

SBIS PINC,1 
LDI R20,0X3F ;CODE 0

OUT PORTD, R20

;LDI R16, 0x0F
;OUT DDRB, R16
LDI R16, 0X00
OUT PORTB, R16

;LDI R16, 0x00
;OUT DDRC, R16
;OUT PORTC, R16


RETI
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.