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.

newb help 16F628 - keypad

Status
Not open for further replies.

Jekyll

New Member
Hi I am doing my first microcontroller project. I am trying to hook up a keypad that trigers an output when I certain code sequence is entered.

I have been struggling with this for a little while so I'm fairly frustrated. Anyway here's what I have:

PIC-PG2 programmer from sparkfun.
16F628 microcontroller.
4x3 keypad.
WinPIC software [I also have icprog].

I hooked up the icsp and am finally succesfully using it. Anway the problem I'm having is that I'm trying to scan inputs on port A to see which button has been pressed. For some reason I can see inputs on RA6 and RA7 but zilch on RA1 and RA0!!

Attached is my C code which I developed in mikroC. Where am I going wrong here?

BTW when I press the buttons I am seeing the input pins go high w/ my multimeter...
 

Attachments

  • keypad_prj.c
    2.5 KB · Views: 348
The chip defaults to analogue comparator mode for the ports that support it - RA0,1 have analogue functions but RA6,7 are digital only.
You need to initialize the ports to digital as shown in the data sheet example below to make them work digitally.

EXAMPLE 5-1: Initializing PORTA
CLRF PORTA ;Initialize PORTA by
;setting output data latches
MOVLW 0x07 ;Turn comparators off and
MOVWF CMCON ;enable pins for I/O
;functions
BCF STATUS, RP1
BSF STATUS, RP0;Select Bank1
MOVLW 0x1F ;Value used to initialize
;data direction
MOVWF TRISA ;Set RA<4:0> as inputs
;TRISA<5> always
;read as ‘1’.
;TRISA<7:6>
;depend on oscillator mode
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top