Reading multiple ports


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Posts
    44

    Default Reading multiple ports

    I have a project where i need read several inputs in one hit and as quick as possible. 16f648

    Ideally I'd like to read PORTB and display the results on an LCD.
    This could be in binary e.g.0000001 when button one is pressed or 00001001 when one and four are pressed.
    ( I was thinking I could assign TRISB to a VAR?)

    I then need to access each byte of PORTB to display some text e.g
    if PORTB.0 = 1 then do something.
    if PORTB.1 = 1 then do something else.

    I've been playing but can't seem to read the ports without usung the button commands and lots of IFs.

    Rob

  2. #2
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default

    Rob,

    I would read the entire PortB, and then do a CASE senario based on the values at the Port so that if two buttons are pressed at the same time you can detect it.

    For example:
    <table border="1" padding="3" spacing="3"><tr><td>
    B0 var byte
    TRISB = %11111111 'MAKE PORT B INPUT
    B0 = PORTB

    START:
    SELECT CASE B0

    CASE 0
    ' NO SWITCHED PRESSED
    CASE 1
    ' SWITCH ONE PRESSED
    CASE 2
    ' SWITCH TWO PRESSED
    CASE 3
    ' SWITCH'S ONE AND TWO
    CASE N
    ' WHAT EVER
    END SELECT

    GOTO START
    <br></td></tr></table>
    Last edited by Squibcakes; - 18th May 2004 at 11:34.

  3. #3
    Join Date
    Mar 2004
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Squibcakes

    This seems like an easy way of reading the ports.

    Thanks for the reply.


    Rob

Similar Threads

  1. Replies: 1
    Last Post: - 29th September 2007, 18:05
  2. How to drive 7 segment using multiple ports?
    By guess79 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:43
  3. multiple ports ===> one symbol?
    By PICMAN in forum General
    Replies: 4
    Last Post: - 8th March 2005, 22:24
  4. Problem reading multiple ADC ports
    By jswayze in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th November 2004, 16:46
  5. Reading multiple ADC channels FAST
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st April 2004, 22:37

Members who have read this thread : 2

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