PIC's ports individual bits manipulation - how to?


Closed Thread
Results 1 to 39 of 39

Hybrid View

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

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

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

  4. #4
    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?

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


    Did you find this post helpful? Yes | No

    Default Simulator...

    Well, the simulator I use is wrong. I checked with my logic probe, and this one says true.

    Skimask, I have tried to use the MELABS simulator if this is the one you're talking about.

    But, compared to the one I use, it was such a hassle to make it work that I abandonned this one.

    Is it the one you use?
    Last edited by flotulopex; - 25th February 2007 at 21:36.
    Roger

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    flotulopex,
    INPUTDATA = PORTA >> 4 'LOWER 4 BITS OF INPUTDATA ARE NOW UPPER 4 BITS OR PORTA (INPUT PINS)
    PORTA = PORTA & %11110000 'STRIP LOWER 4 BITS OF PORTA
    PORTA = PORTA | (DIGIT & %00001111) 'REPLACE LOWER 4 BITS WITH NEW DIGIT DATA

    Now your upper 4 bits are stored in variable INPUTDATA. The lower 4 bits of PORTA have just been updated with the lower 4 bits of variable DIGIT.

    If I'm incorrect about your original question? I can't think of any easier method.

    Dave Purola,
    N8NTA

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


    Did you find this post helpful? Yes | No

    Default

    Flotulopex,
    as far as i'm aware of MELABS don't do any Simulator... but i could be wrong.

    Skimask talked about the built-in MPLAB simulator (Debugger>Select Tool>>MPLAB Sim) one.

    To use it, you need to add some 'Watch' (View>Watch) and then you enjoy seeing them changing.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Thanks Dave, this is another way to solve my problem.

    Indexing the port may be faster in the loop's execution (I need speed).
    Roger

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


    Did you find this post helpful? Yes | No

    Default

    Right then Mister_e, that's the one I had a hard time to make work...

    Maybe I should insist a little more.

    The simulator I use is that easy... but maybe not fully reliable so it may be worth to spend more time on the MELABS Sim programmer.
    Roger

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    Right then Mister_e, that's the one I had a hard time to make work...

    Maybe I should insist a little more.

    The simulator I use is that easy... but maybe not fully reliable so it may be worth to spend more time on the MELABS Sim programmer.
    I don't know if the MPLABs simulator is 'hard to use', at least I don't think so anyways. There is a bit of an initial learning curve to figure out which windows to use, which keystrokes and which functions key are really handy, etc.
    All I do it pull up MPSIM, load the .asm file that PBP gave me, and run it, or single step it or whatever. Yes, you need to have some input values, and maybe a stimulus file, but I don't use any of that and just set my program up to 'fake' those values.
    All I can say is that MPSIM has always treated me right...and I especially like the 'stopwatch' function.

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


    Did you find this post helpful? Yes | No

    Default

    Well it's actually pretty simple once you know how.

    Start a new project using the usual method, then Select MPLAB Sim and compile your code.

    Go to View> Watch, right to Add Symbol chose the variable you want to monitor and add them in the list.

    If you want to monitor a PORT ouput, you go on the Add SFR side.

    Once done, press f9 and enjoy the show.

    If you have some PAUSE, PAUSEUS in your code... comment them.

    You can use and create your Code in MPLAB and use the animate mode... it works. You just need to install properly the MPLAB plug-in. Easier to figure out than the .ASM file.

    Today i notice that Microchip have added the VSM plug-in. I need to laugh and waste some time... i'll try it...
    Last edited by mister_e; - 25th February 2007 at 22:07.
    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