Yagami5159
New Member
Hi, good evening, well there's not much to say, I'm currently have a side project of making a combination lock using 3*4 keypad for inputs and 4 seven segment display as outputs (by using PIC 16F877A) under assembly language.
Well I looked through the keypad tutorials, I've decided to try the basics to make a keypad to accept 4 digits input and it'll show ON at the 7segment display as correct and OFF as incorrect:
But when I ran the PIC simulator IDE, I've got an error saying "Hardware Stack Overflow", What did I do wrong?
Well I looked through the keypad tutorials, I've decided to try the basics to make a keypad to accept 4 digits input and it'll show ON at the 7segment display as correct and OFF as incorrect:
Code:
; Keyscan.asm
; Reads keypad and returns value in W reg
INCLUDE P16F877A.INC
__CONFIG _XT_OSC & _WDT_OFF & _LVP_OFF
key EQU 0x20 ;Count for keys
rows EQU 0x21
CODE1 EQU 0x22 ;code1
CODE2 EQU 0x23 ;code2
CODE3 EQU 0x24 ;code3
CODE4 EQU 0x25 ;code4
KEY1 EQU 0x26 ;register for keyed attempts
KEY2 EQU 0x27
KEY3 EQU 0x28
KEY4 EQU 0X29
_ON RETLW B'00011101' ;o
MOVWF PORTB
RETLW B'00010101' ;n
MOVWF PORTC
_OFF RETLW B'00011101' ;o
MOVWF PORTA
RETLW B'01000111' ;f
MOVWF PORTB
RETLW B'01000111' ;f
MOVWF PORTB
Initialise movlw D'2' ;set 4 digit secret code
movwf CODE1
movlw D'5'
movwf CODE2
movlw D'8'
movwf CODE3
movlw D'0'
movwf CODE4
;SETPORTS
BANKSEL TRISD ;
MOVLW B'00001111' ; Set RD0-RD3 as inputs for Rows 1,2,3,4
MOVWF TRISD ; and RD4-RD7 as outputs for Columns 1,2,3
BANKSEL PORTD
CLRF PORTA ;clear 7-segment porta
BANKSEL TRISA
CLRW ; Set PORTA as outputs
MOVWF TRISA
BANKSEL PORTA
CLRF PORTA
CLRF PORTB ;clear 7-segment portb
BANKSEL TRISB
CLRW ; Set PORTB as outputs
MOVWF TRISB
BANKSEL PORTB
CLRF PORTB
CLRF PORTC ;clear 7-segment portc
BANKSEL TRISC
CLRW ; Set PORTC as outputs
MOVWF TRISC
BANKSEL PORTC
CLRF PORTC
GOTO main
Chk_Code movf CODE1, w ;test first digit
subwf KEY1, w
btfss STATUS, Z
goto _OFF
movf CODE2, w ;test second digit
subwf KEY2, w
btfss STATUS, Z
goto _OFF
movf CODE3, w ;test third digit
subwf KEY3, w
btfss STATUS, Z
goto _OFF
movf CODE4, w ;test fourth digit
subwf KEY4, w
btfss STATUS, Z
goto _OFF
goto _ON
; Read keypad
main CALL scan
MOVWF KEY1
CALL scan
MOVWF KEY2
CALL scan
MOVWF KEY3
CALL scan
MOVWF KEY4
CALL Chk_Code
;GOTO main; Repeat
scan BSF PORTD,4 ; Column 1 = 1
BCF PORTD,5 ; Column 2 = 0
BCF PORTD,6 ; Column 3 = 0
BTFSC PORTD,0 ; Test and skip if Row 1 = 0
RETLW D'1' ; Key = 1
BTFSC PORTD,1 ; Test and skip if Row 2 = 0
RETLW D'4' ; Key = 4
BTFSC PORTD,2 ; Test and skip if Row 3 = 0
RETLW D'7' ; Key = 7
BTFSC PORTD,3 ; Test and skip if Row 4 = 0
RETLW D'10' ; Key = Clear
BCF PORTD,4 ; Column 1 = 0
BSF PORTD,5 ; Column 2 = 1
BTFSC PORTD,0 ; Test and skip if Row 1 = 0
RETLW D'2' ; Key = 2
BTFSC PORTD,1 ; Test and skip if Row 2 = 0
RETLW D'5' ; Key = 5
BTFSC PORTD,2 ; Test and skip if Row 3 = 0
RETLW D'8' ; Key = 8
BTFSC PORTD,3 ; Test and skip if Row 4 = 0
RETLW D'0' ; Key = 0
BCF PORTD,5 ; Column 2 = 0
BSF PORTD,6 ; Column 3 = 1
BTFSC PORTD,0 ; Test and skip if Row 1 = 0
RETLW D'3' ; Key = 3
BTFSC PORTD,1 ; Test and skip if Row 2 = 0
RETLW D'6' ; Key = 6
BTFSC PORTD,2 ; Test and skip if Row 3 = 0
RETLW D'9' ; Key = 9
BTFSC PORTD,3 ; Test and skip if Row 4 = 0
RETLW D'12' ; Key = #/Enter 12
END
But when I ran the PIC simulator IDE, I've got an error saying "Hardware Stack Overflow", What did I do wrong?