PDA

View Full Version : Portc 16F913 problem



Andre_Pretorius
- 1st May 2012, 16:31
Hi all
I am trying to use a PIC16F913 to read a keypad, the problem is i can not get PortC.2 to go to a high state ,can anyone please point me in a direction, Pin 0 and 1 works fine



INCLUDE "MODEDEFS.BAS"
Asm
ERRORLEVEL -306
Endasm

DEFINE OSC 20 ' Define crystal as 20Mhz
LCDCON = 0
TRISC = %11110000 'Set PORTC for keypad
TRISB = %00000000 'Sert PORTb as outputs and for use with the ICD2
VAR1 VAR BYTE
VALUE VAR BYTE
PortB.0 = 0

keyPad: portc=1

if portc.4=1 then
for VAR1=0 to 10
if portc.4=1 then VAR1 = 0
next
VALUE=1
goto getPin
endif
if portc.5=1 then
for VAR1=0 to 10
if portc.5=1 then VAR1 = 0
next
VALUE=4
goto getPin
endif
if portc.6=1 then
for VAR1=0 to 10
if portc.6=1 then VAR1 = 0
next
VALUE=7
goto getPin
endif
if portc.7=1 then
for VAR1=0 to 10
if portc.7=1 then VAR1 = 0
next
VALUE=10 '* button
goto getPin
endif
portc=2
if portc.4=1 then
for VAR1=0 to 10
if portc.4=1 then VAR1 = 0
next
VALUE=2
goto getPin
endif
if portc.5=1 then
for VAR1=0 to 10
if portc.5=1 then VAR1 = 0
next
VALUE=5
goto getPin
endif
if portc.6=1 then
for VAR1=0 to 10
if portc.6=1 then VAR1 = 0
next
VALUE=8
goto getPin
endif
if portc.7=1 then
for VAR1=0 to 10
if portc.7=1 then VAR1 = 0
next
VALUE=0
goto getPin
endif
portc=4

if portc.4=1 then
for VAR1=0 to 10
if portc.4=1 then VAR1 = 0
next
VALUE=3
goto getPin
endif
if portc.5=1 then
for VAR1=0 to 10
if portc.5=1 then VAR1 = 0
next
VALUE=6
goto getPin
endif
if portc.6=1 then
for VAR1=0 to 10
if portc.6=1 then VAR1 = 0
next
VALUE=9
goto getPin
endif
if portc.7=1 then
for VAR1=0 to 10
if portc.7=1 then VAR1 = 0
next
VALUE=11 '# button
goto getPin
endif
goto keypad
getpin:
PortB.0 = 1
return

END

Demon
- 1st May 2012, 18:44
For starters, GETPIN is a subroutine, use GOSUB to call it, not GOTO.

Robert

Andre_Pretorius
- 1st May 2012, 19:28
Thanks i'll do so - I did a bit of reading and it seems it has something to do with the "read modify write" functions on portC.2 and 5.
I moved the pins to portB as they are spare and all seems to be working now

shahidali55
- 10th May 2012, 13:40
On 16F913, Port C is shared with the VLCD module. To uses this as digital I/O, you will need to clear the VLCDEN bit in LCDCON register.