Port Digital Output Not Changing Properly


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637

    Default Port Digital Output Not Changing Properly

    Hi,

    I'm using a 18F4550 PIC code that's running on PBP2.50. I'm pulling my hair out trying to figure out why this code won't work.

    Code:
    DUMMYVAR VAR BYTE
    
    TRISB = %00000000        'SET ALL B PORTS AS OUTPUTS
    ADCON1 = %00001111     'SET ALL PORTS TO DIGITAL
    
    MAIN:
    
    PORTA.0 = 1
    PORTA.1 = 1
    
    DO SOME STUFF......
    
    GOTO MAIN
    PORTA.0 stays low and never changes to high. However, if I do the following, then the code works and I get both ports high.

    Code:
    DUMMYVAR VAR BYTE
    
    TRISB = %00000000        'SET ALL B PORTS AS OUTPUTS
    ADCON1 = %00001111     'SET ALL PORTS TO DIGITAL
    
    MAIN:
    
    DUMMYVAR = 3
    PORTA.0 = DUMMYVAR.0 : PORTA.1 = DUMMYVAR.1
    
    DO SOME STUFF......
    
    GOTO MAIN
    So, why does the second code works and the first one doesn't? Do you need a pause or delay when changing individual port settings in the same port bank? Does the commands HIGH and LOW resolve this issue?

    Thanks,

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Port Digital Output Not Changing Properly

    classic RMW read modify write
    watch this
    http://www.microchip.com/webinars.mi...cName=en556253
    click on
    View streaming media version:
    Warning I'm not a teacher

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: Port Digital Output Not Changing Properly

    Richard, wow I wasn't aware of this issue. Check out the following article. It explains in detail exactly what happened in my code.

    https://download.mikroe.com/document...c/help/rmw.htm
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  4. #4
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: Port Digital Output Not Changing Properly

    Also, is it possible to use LATCH instead or PORTx.x in PBP? How would you use the LATCH register?
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Port Digital Output Not Changing Properly

    yes it's not the most thrilling video but it does explain the issue in easy to understand terms.

    is it possible to use LATCH instead or PORTx.x in PBP?

    pretty easy for chips with LAT regs

    in your case
    LATA.0 =1
    LATA.1 =1

    note LAT(X) cannot be used with compound commands THAT auto set TRIS regs like SERIN,I2CIN,TOGGLE etc
    Warning I'm not a teacher

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: Port Digital Output Not Changing Properly

    Thanks Richard. That helps a lot.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

Similar Threads

  1. Can't properly configure RA3,Ra4 as digital out (PIC16F876A)
    By luxornet in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th July 2014, 17:10
  2. Changing output state after 2 minutes
    By carljbrooks in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st February 2014, 06:28
  3. Replies: 11
    Last Post: - 13th January 2013, 11:25
  4. 18F2520 - problem configuring fuse for port B as digital port.
    By hwhisperer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th October 2010, 12:41
  5. open drain output as digital output?
    By droptail in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th November 2006, 04:11

Members who have read this thread : 1

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