Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

KEYPAD and Interrupt on Changing PORTB

Status
Not open for further replies.

mtkee2003

Full Member level 2
Joined
Sep 24, 2005
Messages
132
Helped
4
Reputation
10
Reaction score
1
Trophy points
1,298
Activity points
2,356
hi

i want to implement a keypad using PicBasic PRO, and i want to use the interrupt on change of PORTB. i am using 16F877 and i can't use "polling routine" in this project with , also i can't use any Keypad IC (like 74C922).

i wrote a program and i attach its PROTEUS file its schematic.
Code:
'****************************************************************
'*  Name    : PORTB_CHANGE.BAS                                  *
'*  Author  : Mostafa Taghavi Kani                              *
'*  Notice  : Copyright (c) 2006 Embedded Technology            *
'*          : All Rights Reserved                               *
'*  Date    : 2006/12/14                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'****************************************************************

'include "modedefs.bas"

define  OSC 4


DEFINE LCD_DREG PORTA
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTA
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 0
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

GIE     VAR  INTCON.7
PEIE    VAR  INTCON.6
T0IE    VAR  INTCON.5
INTE    VAR  INTCON.4
RBIE    VAR  INTCON.3
T0IF    VAR  INTCON.2
INTF    VAR  INTCON.1
RBIF    VAR  INTCON.0

RBPU    VAR  OPTION_REG.7
INTEDG  VAR  OPTION_REG.6
T0CS    VAR  OPTION_REG.5
T0SE    VAR  OPTION_REG.7
PSA     VAR  OPTION_REG.3
PS2     VAR  OPTION_REG.2
PS1     VAR  OPTION_REG.1
PS0     VAR  OPTION_REG.0

i       VAR  BYTE
'PORTB   VAR  BYTE[3]
x       VAR  BYTE
ROW     VAR  BYTE
COL     VAR  BYTE
J       VAR  BYTE
R       VAR  BIT
C       VAR  BIT

TRISB=%11110000 : 'PORTB=%11111111
TRISD=%00000000
i=0

'OPTION_REG=%01010111       'ONLY FOR CAMPACTING THE PROGRAM
INTCON = %10001000
RBPU=0

ON INTERRUPT GOTO TEST

MAIN:
'    PORTD=$FF
'    PAUSE 200
'    PORTD=$00
'    PAUSE 500
    IF I==0 THEN
        LCDOUT $FE,1,"PRESS ANY KEY!"
    ELSE
        LCDOUT $FE,1,"(ROW,COLUMN)=","(",#R,",",#C,")"
    ENDIF

    PORTB=(PORTB & %11110010)
'    PAUSE 20
    PORTB=(PORTB & %11110100)
'    PAUSE 20
    PORTB=(PORTB & %11111000)
'    PAUSE 20
'    FOR J=1 TO 3
'        PORTB=%00000001
'        PORTB=PORTB << 1
'    NEXT J
'    WHILE(J)
'            J
    GOTO MAIN

DISABLE
TEST:
    @ MOVF PORTB,W  'IMPORTANT:reads PORTB and moves the value to W register!!! 
'   @ MOVE?BA PORTB  'another ALTERNATE for above line!
    ROW=(PORTB & %11110000)
    COL=(PORTB & %00001110)
    SELECT CASE ROW
           CASE %00010000
                R=1
           CASE %00100000
                R=2
           CASE %01000000
                R=3
           CASE %10000000                
                R=4
    END SELECT
    
'    FOR K=1 TO 3
'        IF COL.K=1
'    NEXT K

    SELECT CASE COL
           CASE %00000010
                C=1
           CASE %00000100
                C=2
           CASE %00001000
                C=3
    END SELECT
    i=i+1
'    LCDOUT $FE,1,"PORTB CHANGES=",#I
    RBIF=0
'   PORTD=$00
    RESUME
ENABLE


END

67_1166374156.JPG


thanks in advance,
with best regards.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top