Uber noob needs clarity!


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Posts
    24

    Default Uber noob needs clarity!

    Hello all,

    Just to keep things simple and not going into alot of details here is my question:

    Can you use a variable in the port settings?

    Example....

    main:
    for I = 0 to 7
    if portb.I = 1 then xxxxx
    next I
    goto main

    If so how do you setup the variable? (I var byte)

    I have tired and tried and it always says:
    "ERROR Line X: Bad variable modifier: .I."

    What I am trying to do is scan a port for changes with out using 8 seperate If...then lines.

    Any help is always appreciated.

    Thanks,
    Bill12780

    SETUP:
    16f873
    easypic4 dev board
    picbasic pro v2.47
    using PM as compiler

  2. #2
    Join Date
    Jul 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default May I suggest this

    UNTESTED, but with no compile error.

    You can try

    main:
    for I = 0 to 7
    if (portb & DCD I) = 1 then xxxxx
    next I
    goto main


    J-P

  3. #3
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile See if this helps....

    Hi Bill12780,
    Take a look at this post and see if it helps.
    Bits, Bytes Words and Arrays - Melanie
    http://www.picbasic.co.uk/forum/showthread.php?t=544
    -Adam-

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I think this is what you are looking for. In the manual under "Ports and other Registers".

    Code:
    anyvar = PORTB & $0f   'Isolate lower 4 bits of PORTB and place result into anyvar
    $0f = 00001111
    $00ff = 11111111

    Now you can check "anyvar" for changes.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Apr 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Thanks a bunch man!

    Thanks everyone...

    These are some really good idea's. I had to "walk away" for awhile. I will read Melanie's post(man she is a wealth of knowledge....Bet she was born with a PBP manual in her hand!), try a few things. and get back with you all tonight.

    Thanks for the tips.

    Bill12780

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    This will work;
    Code:
    X VAR BYTE
    
    main:
      for X = 0 to 7
          if PortB.0[X] = 1 then xxxxx
      next X
      goto main
    PortB.0 <-- zero after PortB indicates you're dealing with a bit.

    PortB.0[X] <-- [X] = the bit index pointer.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. NOOB in need of help
    By studysession in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th January 2009, 23:01
  2. Replies: 2
    Last Post: - 7th March 2008, 02:16
  3. Help a noob out?
    By yasiryassin in forum mel PIC BASIC
    Replies: 2
    Last Post: - 15th January 2008, 06:37
  4. Crystals & Caps - Super noob question??
    By kevj in forum General
    Replies: 4
    Last Post: - 24th September 2007, 17:11

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