Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

4x4 Keypad Interrupt on Change PORTB

Status
Not open for further replies.
hi,
No the Oshonsoft isnt freeware, but it has a 28day or 30 power ups trial period.

The ISR is called at power on because the INTCON,RBIF bit is set, you are clearing the RBIF after enabling the interrupts.
I have moved the line up.

Code:
MAIN_PROGRAM
	BCF     INTCON, RBIF
        BSF     INTCON, GIE
        BSF     INTCON, PEIE
        BSF     INTCON, RBIE

The reason that the ISR isnt being called on PORTB change, with a key press, is because your PORTB outputs that drive the 16 key matrix are set low, so pushing a key causes no change.!!

There may be more problems, lets know how it goes.
 
Last edited:
Just before I test it...

You say
The reason that the ISR isnt being called on PORTB change, with a key press, is because your PORTB outputs that drive the 16 key matrix are set low, so pushing a key causes no change.!!

But doesn't setting the weak pull ups, pull-up the inputs to give them a high logic level?
Then on a keypress because the outputs are low, the input goes low, and theres your change.

Please correct me if im wrong here.
 
Just before I test it...

You say


But doesn't setting the weak pull ups, pull-up the inputs to give them a high logic level?
Then on a keypress because the outputs are low, the input goes low, and theres your change.

Please correct me if im wrong here.

The Oshonsoft is showing them as low.??? I will look futher
 
clearing bit 7 off the option reg is supose to turn pull ups on
 

Attachments

  • option reg.jpg
    option reg.jpg
    96.5 KB · Views: 161
hi jakes,
The keyscan routine in the ISR will not identify a particular key press.

Code:
        BTFSS   PORTB, COL1         ; Scan COL 1
        MOVLW   D'1'                ;    BTN_POWERUP
        BTFSS   PORTB, COL2         ; Scan COL 2
        MOVLW   D'2'                ;    BTN_STOP            ;
        BTFSS   PORTB, COL3         ; Scan COL 3
        MOVLW   D'3'                ;    BTN_STOPPOWERDOWN   ;
        BTFSS   PORTB, COL4         ; Scan COL 4
        MOVLW   D'4'                ;    BTN_READADDRESS     ;

        BTFSS   PORTB, COL1         ;
        MOVLW   D'5'                ;    BTN_PLAY            ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'6'                ;    BTN_SETPLAY         ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'7'                ;    BTN_SS              ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'8'                ;    BTN_ADDRESSINC      ;

        BTFSS   PORTB, COL1         ;
        MOVLW   D'9'                ;    BTN_RECORD          ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'10'               ;    BTN_SETRECORD       ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'11'               ;    BTN_CLK             ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'12'               ;    BTN_ADDRESSDEC      ;

        BTFSS   PORTB, COL1         ;
        MOVLW   D'13'               ;    BTN_MESSAGECUE      ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'14'               ;    BTN_SETMESSAGECUE   ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'15'               ;    BTN_MOSI            ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'16'               ;
        MOVWF   KEYSTORE
 
Last edited:
oh i forgot to add the polling lines in

does this look better:

Code:
        MOVLW   B'0111'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ; Scan COL 1
        MOVLW   D'1'                ;    BTN_POWERUP
        BTFSS   PORTB, COL2         ; Scan COL 2
        MOVLW   D'2'                ;    BTN_STOP            ;
        BTFSS   PORTB, COL3         ; Scan COL 3
        MOVLW   D'3'                ;    BTN_STOPPOWERDOWN   ;
        BTFSS   PORTB, COL4         ; Scan COL 4
        MOVLW   D'4'                ;    BTN_READADDRESS     ;

        MOVLW   B'1011'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ;
        MOVLW   D'5'                ;    BTN_PLAY            ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'6'                ;    BTN_SETPLAY         ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'7'                ;    BTN_SS              ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'8'                ;    BTN_ADDRESSINC      ;

        MOVLW   B'1101'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ;
        MOVLW   D'9'                ;    BTN_RECORD          ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'10'               ;    BTN_SETRECORD       ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'11'               ;    BTN_CLK             ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'12'               ;    BTN_ADDRESSDEC      ;

        MOVLW   B'1110'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ;
        MOVLW   D'13'               ;    BTN_MESSAGECUE      ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'14'               ;    BTN_SETMESSAGECUE   ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'15'               ;    BTN_MOSI            ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'16'               ;
        MOVWF   KEYSTORE
        CALL    DELAY_50mS

        BCF     INTCON, RBIF
 
Last edited:
Still doesn't work. On power up the LED come one and stays on.

Just making sure we have the same code here::
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                                                  ;
;                                     ISD 4002 Programmer                                          ;
;                                   Author: Jake Sutherland                                        ;
;                                                                                                  ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        LIST            p=pic16f72
        INCLUDE         "P16F72.INC"
        __config _BOREN_OFF & _CP_OFF & _PWRTEN_ON & _WDTEN_OFF & _WDT_OFF & _XT_OSC
        ERRORLEVEL      -302        ;Eliminate bank warning

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                                                  ;
;                                     PIC16F72 Microcontroller                                     ;
;                                            ____ ____                                             ;
;                                     MCLR -|    -    |- RB7  Keypad Column 1   I                  ;
;                    O                 RA0 -|         |- RB6  Keypad Column 2   I                  ;
;                    O                 RA1 -|         |- RB5  Keypad Column 3   I                  ;
;                    O       LED       RA2 -|         |- RB4  Keypad Column 4   I                  ;
;                    I                 RA3 -|         |- RB3  Keypad Row 1      O                  ;
;                    O                 RA4 -|         |- RB2  Keypad Row 2      O                  ;
;                    O                 RA5 -|         |- RB1  Keypad Row 3      O                  ;
;                                      VSS -|         |- RB0  Keypad Row 4      O                  ;
;                                     OSC1 -|         |- VDD                                       ;
;                                     OSC2 -|         |- VSS                                       ;
;                    O                 RC0 -|         |- RC7                    O                  ;
;                    O                 RC1 -|         |- RC6                    O                  ;
;                    O                 RC2 -|         |- RC5                    O                  ;
;                    O                 RC3 -|_________|- RC4                    O                  ;
;                                                                                                  ;
;                                                                                                  ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Set EQU vales and registers
CBLOCK  0x20
GPR1    ; Countdown Reg
GPR2    ; For storing command codes
GPR3    ; Countdown Reg
GPR4    ; Countdown Reg
DELAYGPR1
DELAYGPR2
KEYSTORE
ENDC

W_TEMP      EQU 0X7F
STATUS_TEMP EQU 0X7E

; PORTB bits
COL1    EQU     7
COL2    EQU     6
COL3    EQU     5
COL4    EQU     4
ROW1    EQU     3
ROW2    EQU     2
ROW3    EQU     1
ROW4    EQU     0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


        ORG     0x00                ; Program starts at 0x00
        GOTO    START

        ORG     0x04                ; Interupt vector jumps here
        GOTO    ISR

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
START
SETIO  ; This rountine sets up the chips Inputs and Outputs
        BCF     STATUS,RP0          ; Bank 0
        BCF     STATUS,RP1          ; Bank 0
        CLRF    PORTA               ; Initialize PORTA by clearing output data latches
        CLRF    PORTB               ; Initialize PORTB by clearing output data latches
        CLRF    PORTC               ; Initialize PORTC by clearing output data latches
        BSF     STATUS,RP0          ; Bank 1
        BCF     STATUS,RP1          ; Bank 1
        MOVLW   0x06                ; Configure all pins
        MOVWF   ADCON1              ; as digital inputs
        MOVLW   B'00001000'         ; Value used to initialize data direction
        MOVWF   TRISA               ; Set RA<1:0> as outputs
                                    ; RA<3> as inputs
                                    ; RA<5:4> as outputs
                                    ; TRISA<7:6> are always
                                    ; read as ‘0’.

        MOVLW   B'11110000'         ; Value used to initialize data direction
        MOVWF   TRISB               ; Set RB<7:4> as outputs
                                    ; RB<3:0> as inputs

        MOVLW   B'00000000'         ; Value used to initialize data direction
        MOVWF   TRISC               ; Set RC<7:0> as outputs

        BCF     OPTION_REG, NOT_RBPU; Set PORTB weak pull-ups on

        BCF     STATUS,RP0          ; Bank 0
        BCF     STATUS,RP1          ; Bank 0

        MOVLW   D'1'                ; This is so when the program goes to MAIN_PROGRAM the LED goes on, then to SLEEP
        MOVWF   KEYSTORE            ;

        GOTO    MAIN_PROGRAM

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Interrupt Sevice Routine
ISR
        BCF     INTCON, GIE

        MOVWF   W_TEMP
        SWAPF   STATUS, W
        CLRF    STATUS
        MOVWF   STATUS_TEMP
; KEYPAD ROUTINES
; This routine scans the keypad for a button press
        MOVLW   B'0111'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ; Scan COL 1
        MOVLW   D'1'                ;    BTN_POWERUP
        BTFSS   PORTB, COL2         ; Scan COL 2
        MOVLW   D'2'                ;    BTN_STOP            ;
        BTFSS   PORTB, COL3         ; Scan COL 3
        MOVLW   D'3'                ;    BTN_STOPPOWERDOWN   ;
        BTFSS   PORTB, COL4         ; Scan COL 4
        MOVLW   D'4'                ;    BTN_READADDRESS     ;

        MOVLW   B'1011'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ;
        MOVLW   D'5'                ;    BTN_PLAY            ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'6'                ;    BTN_SETPLAY         ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'7'                ;    BTN_SS              ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'8'                ;    BTN_ADDRESSINC      ;

        MOVLW   B'1101'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ;
        MOVLW   D'9'                ;    BTN_RECORD          ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'10'               ;    BTN_SETRECORD       ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'11'               ;    BTN_CLK             ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'12'               ;    BTN_ADDRESSDEC      ;

        MOVLW   B'1110'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ;
        MOVLW   D'13'               ;    BTN_MESSAGECUE      ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'14'               ;    BTN_SETMESSAGECUE   ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'15'               ;    BTN_MOSI            ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'16'               ;
        MOVWF   KEYSTORE
        CALL    DELAY_50mS

        BCF     INTCON, RBIF

        SWAPF   STATUS_TEMP, W
        MOVWF   STATUS
        SWAPF   W_TEMP, F
        SWAPF   W_TEMP, W
        RETFIE

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MAIN_PROGRAM
        BCF     INTCON, RBIF
        BSF     INTCON, GIE
        BSF     INTCON, PEIE
        BSF     INTCON, RBIE



        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_ON   ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_ON              ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_ON              ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_ON              ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_ON              ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_ON              ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_ON              ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_ON              ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_OFF             ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_OFF             ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_OFF             ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_OFF             ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_OFF             ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_OFF             ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_OFF             ;

        DECF    KEYSTORE, F         ;
        BTFSC   STATUS, Z           ;
        GOTO    LED_OFF             ;

        GOTO    MAIN_PROGRAM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

LED_ON
        BSF     PORTA, 2
        SLEEP
        NOP
        GOTO    LED_ON

LED_OFF
        BCF     PORTA, 2
        SLEEP
        NOP
        GOTO    LED_OFF

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; DELAY ROUTINES
; Actual delay = 0.001 seconds = 1000 cycles
DELAY_1mS
        MOVLW    0xC6                ;
        MOVWF    DELAYGPR1           ;
        MOVLW    0x01                ;
        MOVWF    DELAYGPR2           ;
DELAY_1mS_0                          ;
        DECFSZ   DELAYGPR1, f        ;
        GOTO     $+2                 ;
        DECFSZ   DELAYGPR2, f        ;
        GOTO     DELAY_1mS_0         ; 993 cycles
        GOTO     $+1                 ;
        NOP                          ; 3 cycles
        RETURN                       ; 4 cycles (including call)


; Actual delay = 0.05 seconds = 50000 cycles
DELAY_50mS
        MOVLW    0x0E                ;
        MOVWF    DELAYGPR1           ;
        MOVLW    0x28                ;
        MOVWF    DELAYGPR2           ;
DELAY_50mS_0                         ;
        DECFSZ   DELAYGPR2, f        ;
        GOTO    $+2                  ;
        DECFSZ  DELAYGPR2, f         ;
        GOTO    DELAY_50mS_0         ; 49993 cycles
        GOTO    $+1                  ;
        NOP                          ; 3 cycles
        RETURN                       ; 4 cycles (including call)


; Actual delay = 0.25 seconds = 250000 cycles
DELAY_250mS
        MOVLW    0x4E                ;
        MOVWF    DELAYGPR1           ;
        MOVLW    0xC4                ;
        MOVWF    DELAYGPR2           ;
DELAY_250mS_0                          ;
        DECFSZ   DELAYGPR1, f        ;
        GOTO     $+2                 ;
        DECFSZ   DELAYGPR2, f        ;
        GOTO     DELAY_250mS_0         ; 249993 cycles
        GOTO     $+1                 ;
        NOP                          ; 3 cycles
        RETURN                       ; 4 cycles (including call)

STOP    GOTO    STOP
END
 
Last edited:
Thanks Eric.

It seems fairly straight forward doesn't it.

1 LED
1 Keypad.

press key light goes on.
press key light goes off.

And SLEEPing in between with an interrupt to wake it up.

It will be the smallest little thing thats F ing the whole code up.
 
hi jakes,
Look at the state of the PORTB pins on the sim,[ see image] all pins are low, so the keypress will not be detected, so the ISR will never be called.

If a add a line of code enabling the PORTB output pins I can cause an ISR call when a key is pressed.??
 

Attachments

  • AAesp01.gif
    AAesp01.gif
    34.4 KB · Views: 190
Ok.

I can understand that.

But why shouldn't they be low.

The Weak Pull-ups are holding the 4 inputs high (RB4,5,6&7),
So if PORTB (RB0,1,2&3) are all low, when a key is pressed, one of the inputs will change from high to low.

Wont it?
and wont that trigger the interrupt?

once again please correct me if im wrong, or you mean something else.
 
Last edited:
I think it's time I post my code that I know works :p, Try using external pull ups


Code:
;*************************************
; Author  : Mike Baird
; Program : 3x4 Keypad
; Date    : September 23rd, 2009
;*************************************

	List	P=16F628a
	#include	"P16F628a.INC"
	__CONFIG	_PWRTE_ON  & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _BODEN_ON & _LVP_OFF & _CP_OFF & _MCLRE_OFF

;*** Cblock ***

	CBLOCK	0x20		 
	d1									; For Delay
	d2									; For Delay
	NumbStore1							; Following 4 to store number location in table
	NumbStore2							;
	NumbStore3							;
	NumbStore4							;
	NumbTable1							; Following 4 to store which of the 7 segments leds to turn on
	NumbTable2							;
	NumbTable3							;
	NumbTable4							;
	W_TEMP								; For saving during an interrupt
	STATUS_TEMP							; "    "       "     "   "
	Temp								;
	Counter								; Used as a temporary and a counter
	ENDC

;*** Defines ***

; PORTA

#Define 	Bits 		PORTA,0
#Define 	Clock		PORTA,7
#Define 	Latch		PORTA,6
#Define 	Digit1		PORTA,3
#Define 	Digit2		PORTA,2
#Define		Digit3		PORTA,1
#Define 	Digit4		PORTA,4

; PORTB

#Define		Column1		PORTB,0
#Define		Column2		PORTB,1
#Define		Column3		PORTB,2

;*** Macro ***

HC595 MACRO Var,Var1

	Local 	Loop						; Local Label
	MOVLW 	.8							; Transfer 8 bits
  	MOVWF 	Var1						; Initializing counter

Loop	
	RLF 	Var,f						; Rotate "Var" one place to the left
	BTFSS 	STATUS,C					; Is carry 1?
	BCF 	Bits						; If not set data line to 0
	BTFSC 	STATUS,C					; Is carry 0?
	BSF 	Bits						; If not set data line to 1

	BSF 	Clock						; Generate one clock
	BCF 	Clock						;

	DECFSZ 	Var1,f						; Has 8 bits been sent?
	GOTO 	Loop						; If not, repeat

	BSF 	Latch						; If all 8 bits have been sent, set latch
	BCF 	Latch

	RLF		Var,f						; Reset orginal variable 
	ENDM

;*** START OF RAM ***

	ORG	0x000							; Start of program vector
	GOTO	Start						;
	ORG	0x004							; Interrupt vector

;*** ISR ***

ISR:
	MOVWF W_TEMP						; Context Saving	
	SWAPF STATUS,W   					; 
	MOVWF STATUS_TEMP					;
	BCF INTCON,RBIF						; Clear RB Port Change Interrupt Flag bit
	BCF INTCON,GIE						; Turn off all interrupt (good practice)
	BCF	INTCON,RBIE						; Turn off RB interrupts (used to debounce)
;*** Code Insert ***
	
COLUMN3	
	BTFSC 	Column3						; Is Column3 pressed?
	GOTO 	COLUMN2						; No, check Column2
	BTFSS	PORTB,4						;
	MOVLW	d'2'						;
	BTFSS	PORTB,4						;
	MOVWF	Temp						;
	BTFSS	PORTB,5						; Check which row was pressed and fill Temp with appropriate value
	MOVLW	d'5'						;
	BTFSS	PORTB,5						;
	MOVWF	Temp						;
	BTFSS	PORTB,6						;
	MOVLW	d'8'						;
	BTFSS	PORTB,6						;
	MOVWF	Temp						;
	BTFSS	PORTB,7						;
	MOVLW	d'11'						;
	BTFSS	PORTB,7						;
	MOVWF	Temp						;
	
COLUMN2
	BTFSC 	Column2						; Is Column2 pressed?
	GOTO 	COLUMN1						; No, check Column1
	BTFSS	PORTB,4						;
	MOVLW	d'3'						;
	BTFSS	PORTB,4						;
	MOVWF	Temp						;
	BTFSS	PORTB,5						;
	MOVLW	d'6'						;
	BTFSS	PORTB,5						;
	MOVWF	Temp						;
	BTFSS	PORTB,6						; 
	MOVLW	d'9'						;
	BTFSS	PORTB,6						;
	MOVWF	Temp						;
	BTFSS	PORTB,7						;
	MOVLW	d'1'						;
	BTFSS	PORTB,7						;
	MOVWF	Temp						;

COLUMN1
	BTFSC 	Column1						; Is Column1 pressed?
	GOTO 	FullTestA					; No, another must have been pressed goto check where to store data
	BTFSS	PORTB,4						;	
	MOVLW	d'4'						;
	BTFSS	PORTB,4						;
	MOVWF	Temp						;
	BTFSS	PORTB,5						;
	MOVLW	d'7'						;
	BTFSS	PORTB,5						;
	MOVWF	Temp						; 
	BTFSS	PORTB,6						;
	MOVLW	d'10'						;
	BTFSS	PORTB,6						;
	MOVWF	Temp						;
	BTFSS	PORTB,7						;
	GOTO	ClearNumbers				;

FullTestA
	MOVF	NumbStore4,W				; Move Number location in W
	XORLW	0x0							; Test if 0
	BTFSS	STATUS,Z					; If zero Z will = 1
	Goto	FullTestB					; If full check next
	MOVF	Temp,W						; Otherwise move Temp
	MOVWF	NumbStore4					; into this location
	GOTO	Exit						; Number has been stored, exit interrupt

FullTestB
	MOVF	NumbStore3,W				;
	XORLW	0x0							;
	BTFSS	STATUS,Z					;
	Goto	FullTestC					;
	MOVF	Temp,W						;
	MOVWF	NumbStore3					;
	GOTO	Exit						;

FullTestC
	MOVF	NumbStore2,W				;
	XORLW	0x0							;
	BTFSS	STATUS,Z					;
	Goto	FullTestD					;
	MOVF	Temp,W						;
	MOVWF	NumbStore2					;
	GOTO	Exit						;

FullTestD
	MOVF	NumbStore1,W				;
	XORLW	0x0							;
	BTFSS	STATUS,Z					;
	Goto	Exit						;
	MOVF	Temp,W						;
	MOVWF	NumbStore1					;
	GOTO	Exit						;

ClearNumbers
	CLRF	NumbStore1					; All numbers are off
	CLRF	NumbStore2					;
	CLRF	NumbStore3					;
	CLRF	NumbStore4					;

;*** End of Insert ***

Exit:
	CLRF	Counter						; Counter = 0
	BSF		INTCON,GIE					; Enable interrupts

	SWAPF 	STATUS_TEMP,W				; Restore Status and W	
	MOVWF 	STATUS						;
	SWAPF 	W_TEMP,F					;
	SWAPF 	W_TEMP,W					;

	RETFIE								


;*** Configuration ***

Start
	MOVLW	0x07						; Turn comparators off and enable pins for I/O
	MOVWF	CMCON						; ^
	CLRF	PORTA						; PortA all low
	CLRF	PORTB						; PortB all low
	
	BSF		STATUS,RP0					; Bank 1
	MOVLW	b'00100000'					; Or 0x20 Hex
	MOVWF	TRISA						; PortA all output except MCLR
	MOVLW 	0xF0						; Half input half output (for interrupt on change)
	MOVWF	TRISB						; Move to PortB
	BCF		STATUS,RP0					; Bank 0

;*** RB Pin Change Interrupt Set Up ***

	BSF 	INTCON,RBIE					; RB Port Change Interrupt Enable bit	
	BSF 	INTCON,PEIE					; Peripheral Interrupt Enable bit
	BSF 	INTCON,GIE					; Global Interrupt Enable bit

;*** Starting Numbers ***

	MOVLW	d'11'						; All numbers start off as dashes
	MOVWF	NumbStore1					; Which is #11 on the table
	MOVLW	d'11'						;
	MOVWF	NumbStore2					;
	MOVLW	d'11'						;
	MOVWF	NumbStore3					;
	MOVLW	d'11'						;
	MOVWF	NumbStore4					;

	CALL	TurnOffNumbers				; Begin with all Segments off


Main:
	
	INCF	Counter,F					; The following 6 lines are to debounce the buttons
										; It will take 25.549 mSecs before you can cause 
	MOVF	Counter,W					; a PORTB interrupt again
	XORLW	0x03						;
	BTFSC	STATUS,Z					;
	BSF		INTCON,RBIE					; Enable RB Interrupts

	CALL 	TurnOffNumbers				; Turn off all numbers
	MOVF	NumbStore1,W				; Move number location in table
	Call 	Table						; Retrieve 7 segment display equivalent
	MOVWF	NumbTable1					; Move to Number display variable
	HC595 	NumbTable1,Temp				; Display using HC595 Macro (Found at beginning of program)
	BSF		Digit1						; Once 595 is locked on, turn on the matching segment digit
	CALL 	Delay						; Turn on Delay (3 mSecs but you can change) to create persistance of vision effect

	BCF		Column1						; Turn on Column1  Each column is on for 3.187 mSecs		

	CALL 	TurnOffNumbers				;
	MOVF	NumbStore2,W				;
	Call 	Table						;
	MOVWF	NumbTable2 					;
	HC595	NumbTable2,Temp				;
	BSF		Digit2						;
	CALL	Delay						;

	BSF		Column1						; Turn off Column1
	BCF		Column2						; Turn on  Column2	

	CALL 	TurnOffNumbers				;
 	MOVF	NumbStore3,W				;
	CALL 	Table						;
	MOVWF	NumbTable3					;
	HC595 	NumbTable3,Temp				;
	BSF		Digit3						;
	CALL 	Delay						;

	BSF		Column2						; Turn off Column2
	BCF		Column3						; Turn on  Column3

	CALL	TurnOffNumbers				;
 	MOVF	NumbStore4,W				;
	Call 	Table						;
	MOVWF	NumbTable4					;
	HC595 	NumbTable4,Temp				;
	BSF		Digit4						;
	CALL 	Delay						;

	BSF		Column3						; Turn off Column3

	GOTO 	Main

TurnOffNumbers:

	BCF 	Digit1						; Turn off all 7 segments
	BCF 	Digit2						;
	BCF 	Digit3						;
	BCF 	Digit4						;
	RETURN	

Table:

	ADDWF 	PCL
	RETLW 	b'00000000' 				; Clear
	RETLW 	b'00111111' 				; 0
	RETLW 	b'00000110' 				; 1 
	RETLW 	b'01011011' 				; 2
	RETLW 	b'01001111' 				; 3 
	RETLW 	b'01100110' 				; 4
	RETLW 	b'01101101' 				; 5
	RETLW 	b'01111101' 				; 6		
	RETLW 	b'00000111' 				; 7
	RETLW 	b'01111111' 				; 8
	RETLW 	b'01101111' 				; 9 
	RETLW 	b'01000000' 				; Dash
	RETLW	b'01110111'					; A	

; *** Delay ***

Delay:		
	MOVLW	d'4'						; 4* 255 = ~3mS delay	
	MOVWF	d2
D2:	
	DECFSZ	d1,F
	GOTO	D2
	DECFSZ	d2,F
	GOTO	D2
	RETURN

;***

	END

;********************************
; Table
;		    					    (f) Left Top = bit5
;		    __   (a) Top    = bit0 	(b) Righ Top = bit1   
;		   |__|  (g) Middle = bit6  (e) Left Bot = bit4
;		   |__|  (d) Bottom = bit3	(c) Righ Bot = bit2
;
;  = b'00000000'
;0 = b'00111111'
;1 = b'00000110'
;2 = b'01011011'
;3 = b'01001111'
;4 = b'01100110'  
;5 = b'01101101'  
;6 = b'01111101'  			
;7 = b'00001111'  
;8 = b'01111111'  
;9 = b'01101111'  
;
; That's all folks!
;*********************************
 
hi Jakes,
Checking the keyscan ISR shows it will bever give the correct keycode even when called.

For test, by adding the ;+++ I can get the ISR called from a keypress, but the keyscan code dosnt work correctly, where is the code from.?

Code:
	MOVLW   0x0f;++++++++
        MOVWF   PORTB;+++++++++

        SWAPF   STATUS_TEMP, W
        MOVWF   STATUS
        SWAPF   W_TEMP, F
        SWAPF   W_TEMP, W
        RETFIE

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MAIN_PROGRAM
        BCF     INTCON, RBIF
        BSF     INTCON, GIE
        BSF     INTCON, PEIE
        BSF     INTCON, RBIE

	MOVLW   0x0f;++++++++
        MOVWF   PORTB;++++++++
 
hi Jakes,
Checking the keyscan ISR shows it will bever give the correct keycode even when called.

are you using the keyscan ISR i just added.
Some of the one's i posted were not polling the keypad.

This is the one I'm using:
Because the rows are connected to the outputs RB4,5,6,7, And the weak pullups are holding the inputs RB0,1,2,3 high, I lower one of the four outputs and then test the inputs. I do this for each row.
If nothing is pressed, the routing should skip right through because it will be reading the high logic levels from the pull ups. (BTFSU)
If a key is pushed, an input goes low, and a value is placed in a GPR, then the rest of the routine is skipped.

Code:
; This routine scans the keypad for a button press
        MOVLW   B'0111'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ; Scan COL 1
        MOVLW   D'1'                ;    BTN_POWERUP
        BTFSS   PORTB, COL2         ; Scan COL 2
        MOVLW   D'2'                ;    BTN_STOP            ;
        BTFSS   PORTB, COL3         ; Scan COL 3
        MOVLW   D'3'                ;    BTN_STOPPOWERDOWN   ;
        BTFSS   PORTB, COL4         ; Scan COL 4
        MOVLW   D'4'                ;    BTN_READADDRESS     ;

        MOVLW   B'1011'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ;
        MOVLW   D'5'                ;    BTN_PLAY            ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'6'                ;    BTN_SETPLAY         ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'7'                ;    BTN_SS              ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'8'                ;    BTN_ADDRESSINC      ;

        MOVLW   B'1101'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ;
        MOVLW   D'9'                ;    BTN_RECORD          ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'10'               ;    BTN_SETRECORD       ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'11'               ;    BTN_CLK             ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'12'               ;    BTN_ADDRESSDEC      ;

        MOVLW   B'1110'
        MOVWF   PORTB
        BTFSS   PORTB, COL1         ;
        MOVLW   D'13'               ;    BTN_MESSAGECUE      ;
        BTFSS   PORTB, COL2         ;
        MOVLW   D'14'               ;    BTN_SETMESSAGECUE   ;
        BTFSS   PORTB, COL3         ;
        MOVLW   D'15'               ;    BTN_MOSI            ;
        BTFSS   PORTB, COL4         ;
        MOVLW   D'16'               ;
        MOVWF   KEYSTORE
        CALL    DELAY_50mS
 
hi Jakes,
That last code you have just posted is the one I was using.

As I said earlier for some reason the 'weak pu' appear to be not working as one would expect.
The keypad pins PB3 > 0 are held low , so that a change on PB7 > 4 isnt seen by the program so the interrupt is never called.

The two lines I added force the PB3 > 0 lines high, so that when a key is pressed the ISR is called OK.

The ISR sub then sets each row in turn low and tests for the keycode, but in your code the key test feature dosn't work correctly.

For ref only look at this pdf.
 

Attachments

  • 00566b.pdf
    98.9 KB · Views: 383
Last edited:
Ok, whats wrong with it?

Hi,
The pullup feature dosnt appear to work in Oshonsoft, I will have to confirm this.?

Look at these two attachments, they may help.
 

Attachments

  • 00552.zip
    8.2 KB · Views: 132
  • 00552e.pdf
    96.2 KB · Views: 275
Status
Not open for further replies.

Latest threads

Back
Top