Hello, welcome to our forum.

It looks like you have registered but you have not yet posted and messages. Our requirements are that you must post at least two messages, to allow the moderators to review your registration, before you will be allowed access to the full range of forum areas.

Please make a couple of posts, until then you may see a notice that says you are banned from certain forum areas.


Thank you.

Remove Text Formatting
Loading...

+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2011
    Location
    GA, U.S.A.
    Posts
    5

    Default Ports don't stay on when sequencing them.

    Below is the simple program I am working with and it should work. However, the outputs on port B will not stay on. Portb.0 will come on then go off after the 2 second pause, them portb.1 will come on for 2 seconds and go off then portb.2 comes on and stays on. I am using a PIC16F882, simply because I have several laying around.

    It has been several years since I worked with PICs and with PBP so I am certain there is something stupidly simple to fix this.

    Thank you to anyone who will assist me on this,

    Here is the code:

    adcon1 = 111
    define osc = 8
    porta = %00000000
    portb = %00000000
    portc = %00000000
    trisa = %11111111
    trisb = %00000000
    trisc = %00001111

    'Alias define
    power1 var portb.0
    power2 var portb.1
    power3 var portb.2

    main:
    if portc.0 = 1 then
    gosub Startup
    endif

    if portc.1 = 1 then
    gosub shutdown
    endif

    goto main

    startup:
    pause 500
    high power1
    pause 2000
    high power2
    pause 2000
    high power3
    'pause 2000
    'portb.3 = 1
    'pause 2000
    'portb.4 = 1
    'pause 2000
    'portb.5 = 1
    'pause 500
    return

    shutdown:
    pause 500
    'portb.5 = 0
    'pause 2000
    'portb.4 = 0
    'pause 2000
    'portb.3 =0
    'pause 2000
    low power3
    pause 2000
    low power2
    pause 2000
    low power1
    pause 500
    return

    end
    Last edited by cnc002; - 28th July 2017 at 23:02.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    1,155

    Default Re: Ports don't stay on when sequencing them.

    classic RMW read modify write
    watch this
    http://www.microchip.com/webinars.mi...cName=en556253
    click on
    View streaming media version:
    This is more entertaining than Free to Air TV

  3. #3
    Join Date
    Feb 2011
    Location
    GA, U.S.A.
    Posts
    5

    Default Re: Ports don't stay on when sequencing them.

    Quote Originally Posted by richard View Post
    classic RMW read modify write
    watch this
    http://www.microchip.com/webinars.mi...cName=en556253
    click on
    View streaming media version:
    Can you give me the complete url path? The one above appears to be missing part of the address and of course I get a 404 error when I click on it.

    Thanks

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    1,155

    Default Re: Ports don't stay on when sequencing them.

    sorry the link did not paste in properly
    http://www.microchip.com/webinars.mi...cName=en556253
    This is more entertaining than Free to Air TV

  5. #5
    Join Date
    Feb 2011
    Location
    GA, U.S.A.
    Posts
    5

    Default Re: Ports don't stay on when sequencing them.

    Quote Originally Posted by richard View Post
    sorry the link did not paste in properly
    http://www.microchip.com/webinars.mi...cName=en556253
    No problem, your reminding me about the RMW made me remember the "glitch" in the 16F series PIC. I simply changed my code to writing to the complete port at once rather than individual bits. I.E. portb = %00000001 to turn on portb.0 and portb = %00000011 to keep portb.0 on while turning on portb.1. Works like a charm, many thanks for the assistance.

    Randy Abernathy

  6. #6
    Join Date
    Apr 2014
    Posts
    29

    Default Re: Ports don't stay on when sequencing them.

    Bit masking is another method, using the AND and OR (& = AND, | = OR). AND is a way to turn off selected pins without affecting others: LATB = PORTB & 111110 would turn off PORTB.0. LATB = PORTB | 000001 would turn on PORTB.0. LATB = PORTB & 110000 would turn off the low nibble while LATB = PORTB | 001111 would turn on the lower nibble. Doing it this way leaves the pins you don't want to mess with alone. They remain totally unaffected. This would apply to pins tied to PWM, INTERRUPTS, or anything else.

Similar Threads

  1. Trying to stay on wifi network
    By Hylan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th October 2015, 16:34
  2. Understanding 3 phase sequencing
    By ardhuru in forum General
    Replies: 3
    Last Post: - 22nd June 2008, 10:14
  3. output doesn't stay high
    By dfort in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th November 2007, 22:37
  4. Stay or Go deleted.
    By Darrel Taylor in forum Forum Requests
    Replies: 3
    Last Post: - 13th July 2007, 22:57
  5. 3 phase sequencing
    By ardhuru in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2007, 07:35

Members who have read this thread : 21

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