PIC's ports individual bits manipulation - how to?


Closed Thread
Results 1 to 39 of 39

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891

    Default PIC's ports individual bits manipulation - how to?

    Hello,

    In one of my projects, I have to adress the first (LSB) four bits of my PIC's PORTA.

    This is done within a FOR...NEXT loop so the bits are adressed as a variable ("Digit").

    I would like to use the other four bits for other purpose (Button, any Input...) but I can't make this the way I did it up to now.

    How is it possible to handle ONLY those four bits wihtout modifying the other (MSB) four bits?

    I've attached my code if you like to see how I've done it. Any comments/critics are very welcome.
    Roger

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi flotulopex,

    Check this http://www.picbasic.co.uk/forum/showthread.php?t=3753

    May give you some ideas.


    ------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default yes, but...

    Thank you sayzer,

    I found this thread already. I tried Melanie's way but it doesn't work.

    First, it looks as "Digit" won't increment from 0 to 3.

    Second, I have put a "spy" before entering the loop. I put PORTA.6 = 1.

    Since I use PIC Simulator, I can see the port status and as soon as the program has started, PORTA.6 goes back to 0 (!?).

    Am I doing something wrong?

    In my code's FOR...NEXT loop, I have put:
    Code:
        for Digit = 0 to 3
            value_d = value dig digit
            lookup value_d, [$7E,$0C,$B6,$9E,$CC,$DA,$FA,$0E,$FE,$DE], Segments
            PORTA.0(Digit) = ~DCD Digit
            PORTB = Segments
        next
    Roger

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    Code:
        for Digit = 0 to 3
            value_d = value dig digit
            lookup value_d, [$7E,$0C,$B6,$9E,$CC,$DA,$FA,$0E,$FE,$DE], Segments
            PORTA.0(Digit) = ~DCD Digit
            PORTB = Segments
        next
    I'm not so sure that ~DCD Digit will work. I could be wrong. Maybe: ~ (DCD Digit) ?
    And I don't see an initial 'ENABLE' in the program itself...not sure if that's needed either or if interrupts are 'ENABLE'd by default.
    Ha...just found the answer to that last 'not sure'. Page 183 of the PBP manual states that interrupts are NOT enabled by default...so, you have to turn them on.
    Last edited by skimask; - 25th February 2007 at 20:10.

  5. #5
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    How about something simple, like:

    Code:
    PORTA.0 = Digit.0
    PORTA.1 = Digit.1
    PORTA.2 = Digit.2
    PORTA.3 = Digit.3
    HTH,
    SteveB

  6. #6
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Testing...

    I just made this piece of code as test.
    Code:
    MYPORT  var PORTA
    Loop    var BYTE
    PORTA.0 = MYport.0
    PORTA.1 = MYport.1
    PORTA.2 = MYport.2
    PORTA.3 = MYport.3
    
    PORTA.6 = 1 'Test to check port's state change in simulator...
    
    Start:
        for LOOP = 0 to 3
            myport.0[Loop] = 1  'High
            myport.0[loop] = 0  'Low
        next
        goto start
    END
    It works except the PORTA.6 will change it's status from 1 to 0 when the firt loop will be executed.
    Last edited by flotulopex; - 25th February 2007 at 20:42.
    Roger

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    PORTA.0(Digit) = ~DCD Digit
    as you write to a BIT, it have to be 0 or 1 ONLY.

    Use a LCD or a serial comm to see the results of ~DCD digit... it return 254, 253, 251, 247.

    i bet PORTA.0[Digit]=1 is what you're looking for.
    Last edited by mister_e; - 25th February 2007 at 20:17.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Individual Variable bits
    By tazntex in forum General
    Replies: 4
    Last Post: - 31st January 2008, 18:27
  3. Equating Ports to Data Bits
    By Osiris in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd March 2006, 15:00
  4. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31
  5. pics with 3 hardware PWM ports
    By CBUK in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th August 2004, 00:14

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