Portc 16F913 problem


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default Portc 16F913 problem

    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

    Code:
    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

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Portc 16F913 problem

    For starters, GETPIN is a subroutine, use GOSUB to call it, not GOTO.

    Robert

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Portc 16F913 problem

    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

  4. #4
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Re: Portc 16F913 problem

    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.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts