Bank1
bcf option_reg,7 ;pull-ups are enabled by individual port latch values
Dear BigDog,
Thanks for reply
I red all tutorials that you provided to me
lot of cct's use external pullups, that mean internal pullups does not support for keypad , I am I correct?
Please advice
Dear All
This is reference to pic 16f877a MCU keypad 4x4
I am writing a program for Keypad, so I used portb without interrupt
0 - 3 as out put and 4 - 7 as in put with PORTB internal pull_up
I masked it when I pressed number 1, the RC0 LED tern on and press 2, the RC1 LED tern on and so on
It is working with some errors, I mean when I touch the keypad LED will tern on here and there and toggle
finally I add external pull_up ( four 2.2k resistors to Vcc to RB4,RB5,RB6,RB7) You will wonder now it is working fine
Can I have Advice on this
I need to drive this CCt without external pull_ups
Thanks in advance
eak pull-up is automatically turned off when the port pin is configured as an output.
Dear papunblg thanks for reply
I set PORTB LSB as output and MSB as input. and as I Know this may not effect to disable pull_ups
can you kindly explain what is the reason that may not work when I enable the internal pull_ups and it is working well when I enable the external pull_ups
Thanks in advance
status equ 0x03
portb equ 0x06
trisb equ 0x86
portc equ 0x07
trisc equ 0x87
portd equ 0x08
trisd equ 0x88
option_reg equ 0x81
del1 equ 0x20
del2 equ 0x21
#include <p16f877a.inc> ;include the defaults for the chip
__config 3f39 ;sets the configuration settings
org 0x00 ;org sets the origin, 0x0000 for the 16F877A
start goto main ;this is where the program starts running
main clrwdt
call sys_init
loop call keypad
goto loop
keypad movlw b'11110000' ;Set all output pins low
movwf portb
movwf portb
btfss portb,7 ;Determine Columns
goto row1
btfss portb,6 ;Determine Columns
goto row2
btfss portb,5 ;Determine Columns
goto row3
btfss portb,4
goto row4 ;Determine Columns
return
;------------------------------
;The MCU will need to determine which of the keys is being pressed
;WHICH KEYS CONNECTED ROW1
row1 bcf portb,0
bsf portb,3
btfsc portb,7
goto one
bcf portb,3
bsf portb,2
btfsc portb,7
goto two
bcf portb,2
bsf portb,1
btfsc portb,7
goto three
bcf portb,1
bsf portb,0
btfsc portb,7
goto A
goto keypad
;------------------------------
;Determine which of the keys is being pressed of row2
row2 bcf portb,0
bsf portb,3
btfsc portb,6
goto one
bcf portb,3
bsf portb,2
btfsc portb,6
goto two
bcf portb,2
bsf portb,1
btfsc portb,6
goto three
bcf portb,1
bsf portb,0
btfsc portb,6
goto A
goto keypad
;------------------------------
;Continuve the prgram to determine which of the keys is being pressed of row3
row3 bcf portb,0
bsf portb,3
btfsc portb,5
goto one
bcf portb,3
bsf portb,2
btfsc portb,5
goto two
bcf portb,2
bsf portb,1
btfsc portb,5
goto three
bcf portb,1
bsf portb,0
btfsc portb,5
goto A
goto keypad
;------------------------------
;Continuve the prgram to determine which of the keys is being pressed of row4
row4 bcf portb,0
bsf portb,3
btfsc portb,4
goto one
bcf portb,3
bsf portb,2
btfsc portb,4
goto two
bcf portb,2
bsf portb,1
btfsc portb,4
goto three
bcf portb,1
bsf portb,0
btfsc portb,4
goto A
goto keypad
;------------------------------
one movlw b'00000001'
movwf portc
call delay ;determine the key has been released.
call delay
goto keypad
two movlw b'00000010'
movwf portc
call delay ;determine the key has been released.
call delay
goto keypad
three
movlw b'00000100'
movwf portc
call delay ;determine the key has been released.
call delay
goto keypad
A movlw b'00001000'
movwf portc
call delay ;determine the key has been released.
call delay
goto keypad
;------------------------------ ;Delay routines
delay movlw .100
movwf del1
s2 decfsz del1
goto s1
return
s1 movlw .255
movwf del2
decfsz del2
goto $-1
goto s2
;------------------------------ ;end of Delay routines
sys_init bsf status,5 ;select bank 1
movlw b'11110000' ;set keypad pins
movwf portb ;half in, half out
clrf trisc ;
clrf trisd
bcf option_reg,7
bcf status,5 ;select bank 0
clrf portc
clrf portd
return
end
[ATTACH=CONFIG]72768._xfImport[/ATTACH]
;status equ 0x03 ALL DEFINED IN THE #INCLUDE FILE
;portb equ 0x06
;trisb equ 0x86
;portc equ 0x07
;trisc equ 0x87
;portd equ 0x08
;trisd equ 0x88
;option_reg equ 0x81
del1 equ 0x20
del2 equ 0x21
title " Keypad Controller"
list p=16F877A,r=hex,n=80,x=off,st=off
#include <p16f877a.inc> ;include the defaults for the chip
;__config 3f39 ;sets the configuration settings BETTER TO USE THE NEXT LINE
; SO YOU CAN SEE WHAT PARAMETERS ARE SET
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
org 0x00 ;org sets the origin, 0x0000 for the 16F877A
start goto main ;this is where the program starts running
main clrwdt ; WATCHDOG IS TURNED OFF IN THE CONFIG
call sys_init
loop call keypad
goto loop
keypad movlw b'11110000' ;Set all output pins low
movwf portb
movwf portb
btfss portb,7 ;Determine Columns
goto row1
btfss portb,6 ;Determine Columns
goto row2
btfss portb,5 ;Determine Columns
goto row3
btfss portb,4
goto row4 ;Determine Columns
return
;------------------------------
;The MCU will need to determine which of the keys is being pressed
;WHICH KEYS CONNECTED ROW1
row1 bcf portb,0
bsf portb,3
btfsc portb,7
goto one
bcf portb,3
bsf portb,2
btfsc portb,7
goto two
bcf portb,2
bsf portb,1
btfsc portb,7
goto three
bcf portb,1
bsf portb,0
btfsc portb,7
goto A
goto keypad
;------------------------------
;Determine which of the keys is being pressed of row2
row2 bcf portb,0
bsf portb,3
btfsc portb,6
goto one
bcf portb,3
bsf portb,2
btfsc portb,6
goto two
bcf portb,2
bsf portb,1
btfsc portb,6
goto three
bcf portb,1
bsf portb,0
btfsc portb,6
goto A
goto keypad
;------------------------------
;Continuve the prgram to determine which of the keys is being pressed of row3
row3 bcf portb,0
bsf portb,3
btfsc portb,5
goto one
bcf portb,3
bsf portb,2
btfsc portb,5
goto two
bcf portb,2
bsf portb,1
btfsc portb,5
goto three
bcf portb,1
bsf portb,0
btfsc portb,5
goto A
goto keypad
;------------------------------
;Continuve the prgram to determine which of the keys is being pressed of row4
row4 bcf portb,0
bsf portb,3
btfsc portb,4
goto one
bcf portb,3
bsf portb,2
btfsc portb,4
goto two
bcf portb,2
bsf portb,1
btfsc portb,4
goto three
bcf portb,1
bsf portb,0
btfsc portb,4
goto A
goto keypad
;------------------------------
one movlw b'00000001'
movwf portc
call delay ;determine the key has been released.
call delay
goto keypad
two movlw b'00000010'
movwf portc
call delay ;determine the key has been released.
call delay
goto keypad
three
movlw b'00000100'
movwf portc
call delay ;determine the key has been released.
call delay
goto keypad
A movlw b'00001000'
movwf portc
call delay ;determine the key has been released.
call delay
goto keypad
;------------------------------ ;Delay routines
delay movlw .100
movwf del1
s2 decfsz del1
goto s1
return
s1 movlw .255
movwf del2
decfsz del2
goto $-1
goto s2
;------------------------------ ;end of Delay routines
sys_init bsf status,5 ;select bank 1 USE BANKSEL TRIS etc, AGAIN MUST EASIER TO FOLLOW
movlw b'11110000' ;set keypad pins
movwf portb ;half in, half out SHOULD BE TRISB SETTING THE PORTS TO INPUT OR OUTPUT
clrf trisc ;
clrf trisd
bcf option_reg,7 ; CLEARING THE RBPU BIT TURNS THE PULLUPS ON !! SEE THE DATASHEET - OPTION REG RBUP
; BETTER TO CODE IT AS BCF OPTION_REG,RBPU THN YOU KNOW WHICH BIT YOUR ARE REFERING TO
bcf status,5 ;select bank 0
clrf portc
clrf portd
return
END
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?