New user: port configuration problem/unexpected interaction/16F887


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: New user: port configuration problem/unexpected interaction/16F887

    Quote Originally Posted by Experimenter View Post
    mainloop:
    gosub getkey
    lcdout 254, 192, "key=",#key, " " ; line 2
    if portD.0 = 0 then gosub flash
    goto mainloop
    flash:
    portD.4=1
    pause 500
    portD.4=0
    return

    getkey:
    pause 50 ;debounce


    getkeyu:
    ' Wait for all keys up
    PORTB = 0 ;all output pins low
    TRISB = 110000 ;bottom 4 pins out, top 4 pins in
    If ((PORTB >> 4) != 001111) Then getkeyu ' If any keys down, loop
    Pause 50 ;debounce


    getkeyp:
    ' Wait for keypress
    For col = 0 To 3 ' 4 columns in keypad
    PORTB = 0 ' All output pins low
    TRISB = (dcd col) ^ $ff ' Set one column pin to output
    row = PORTB >> 4 ' Read row
    If row != 001111 Then gotkey ' If any keydown, exit
    Next col
    Goto getkeyp ' No keys down, go look again


    ' Change row and column to key number 1-12
    gotkey:
    key = (col * 3) + (ncd (row ^ 001111)) ;4RX3C matrix
    return
    Your program starts at Mainloop then gosubs to getkey and loops round getkeyp until a key is pressed when a key is pressed then it returns to mainloop. So it never will execute the 'if portD.0 = 0 then gosub flash' statement until the keypad is pressed. This why the push button does not work. Also portD.0 must be 0 when the button is not pressed as it flashes when the keypad is pressed.

    Hope this helps.

    I like your programing style as it is easy for me to follow.

  2. #2
    Join Date
    Mar 2014
    Location
    England
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: New user: port configuration problem/unexpected interaction/16F887

    Thank you very much for this, Steve.

    I 'll correct the program flow as you describe and will then investigate the voltages on D.0;

    I think I will need to simplify the wiring first, get it working and then reconnect the complicated bits ...

    Tony

Similar Threads

  1. pic 16f887 port holding problems
    By lockjawz in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th April 2011, 14:01
  2. 18F2520 - problem configuring fuse for port B as digital port.
    By hwhisperer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th October 2010, 11:41
  3. Problem driving lcd from PIckit2 and 16F887
    By Davidmarks in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st January 2010, 18:28
  4. 16f877 port configuration & interrupts
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th April 2005, 17:30
  5. User Configuration Interface in PBP
    By Radiance in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th February 2004, 08:00

Members who have read this thread : 0

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