PIC's ports individual bits manipulation - how to?


Closed Thread
Results 1 to 39 of 39

Hybrid View

  1. #1
    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

  2. #2
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    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

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I think you've got the variable declarations backwards.
    Try myport.0 = porta.0, etc. instead of the way you have it.

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


    Did you find this post helpful? Yes | No

    Default

    this won't work indeed... and you make it too complicated for what it need to be.

    Code:
    Start:
        for LOOP = 0 to 3
            PORTA.0[Loop] = 1  'High
            PAUSE 500
            PORTA.0[loop] = 0  'Low
        next
        goto start
    END
    MyPORT.0=PORTA.0 will work only once, If you want to alias a variable bit to a PORT bit... it's an all different story..
    Steve

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

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default must be tricky

    I've attached two pictures about what I can see.

    The first picture "Before Loop Start" shows that my PORTA.0 to 3 are set to "1". This is because I need them to be at this state before the main loop starts (driving CA Leds).

    I did the same for PORTA.6 (=1) just for testing purpose. PORTA.6 will be used for something else in my program if I can handle the actual problem.

    When I start the execution of the program, PORTA.6 goes to "0" witch is unwanted here.

    Mister_E you're right, using DCD will modify all ports.... Was not a good idea on my side. Thank you for making me aware.
    Attached Images Attached Images   
    Roger

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


    Did you find this post helpful? Yes | No

    Default

    I should have see it first... You must set the TRIS register, unless those pin are set as input.
    Code:
    MYPORT  var PORTB
    Loop    var BYTE
    TRISB=0
    PORTB.6 = 1 'Test to check port's state change in simulator...
    
    Start:
        for LOOP = 0 to 3
            myport.0[Loop] = 1  'High
            PAUSE 500
            myport.0[loop] = 0  'Low
        next
        goto start
    END
    Steve

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

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    I've attached two pictures about what I can see.

    The first picture "Before Loop Start" shows that my PORTA.0 to 3 are set to "1". This is because I need them to be at this state before the main loop starts (driving CA Leds).

    I did the same for PORTA.6 (=1) just for testing purpose. PORTA.6 will be used for something else in my program if I can handle the actual problem.

    When I start the execution of the program, PORTA.6 goes to "0" witch is unwanted here.

    Mister_E you're right, using DCD will modify all ports.... Was not a good idea on my side. Thank you for making me aware.
    Looks like it might be a bug in the simulator. PortA.6 on the F88 is also OSC2/CLKO. I may have missed something, ya never know. Try it on the real thing and see what happens.

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


    Did you find this post helpful? Yes | No

    Default

    Never mind.. misread the original code...
    Steve

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

  9. #9
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default I have to do it in "real"...

    You may be right!

    I just noticed that, using an additional microcontroler view in the simulator, the port doesn't change.

    So I'm going to make it in "real".

    Another thing; I have declared PORTA.6 as an Input (TRISA = %11110000). When I change this to an Output (TRISA = %10110000), the port will keep it's status as it should be.

    Unfortunalety, I will need it as an Input.

    I'll go back to my breadboard....
    Roger

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    You may be right!

    I just noticed that, using an additional microcontroler view in the simulator, the port doesn't change.

    So I'm going to make it in "real".

    Another thing; I have declared PORTA.6 as an Input (TRISA = %11110000). When I change this to an Output (TRISA = %10110000), the port will keep it's status as it should be.

    Unfortunalety, I will need it as an Input.

    I'll go back to my breadboard....
    Actually, I believe I heard both mister_e and DT both say that they don't trust simulators one bit.
    However, I trust the Microchip simulator almost implicitly. Why don't you try running your code on that and keeping an eye on the port values?

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