How to set a pin high an keep it there?


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Jun 2007
    Posts
    20

    Default How to set a pin high an keep it there?

    Utter newbie here... I have three different LEDs on a PIC16F688. Here is my code:
    Code:
    symbol  GREEN = PORTA.1
    symbol  ORANGE = PORTA.0
    symbol  BLUE = PORTA.2
    
    porta = %00000000
    trisa = %00000000
    
    main:
    high orange
    pause 1000
    high green
    pause 1000
    high blue
    pause 1000
    
    end
    This code obviously lights the LEDs in sequence. However each LED turns off before the next one is set high. How do light one, then two, and then all three? Thanks!

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Try this:
    Code:
    main:
    
    PORTA = %00000001
    pause 1000
    PORTA = %00000011
    pause 1000
    PORTA = %00000111
    PAUSE 1000
    
    end
    It looks like you are experiencing a read-modify-write problem. You can search for more info on this forum.
    Charles Linquist

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Code:
    INCLUDE "AllDigital.pbp"
    
    symbol  GREEN = PORTA.1
    symbol  ORANGE = PORTA.0
    symbol  BLUE = PORTA.2
    
    porta = %00000000
    trisa = %00000000
    
    main:
    high orange
    pause 1000
    high green
    pause 1000
    high blue
    pause 1000
    
    end
    DT

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Code:
    ANSEL=%00000000
    CMCON0=%00000111
    Will do the same as Darrel's suggestion and this
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    plus the data sheet will actually help you learn why.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    ...
    Will do the same as Darrel's suggestion and this
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    plus the data sheet will actually help you learn why.
    Sure,
    But if you run ALLDIGITAL first, then you know where to look in the datasheets, because it's already told you what settings you need to use.
    If you want to learn, look them up.

    People never find the analog registers they need to set by looking in the datasheet first.
    DT

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Sure,
    But if you run ALLDIGITAL first, then you know where to look in the datasheets, because it's already told you what settings you need to use.
    If you want to learn, look them up.

    People never find the analog registers they need to set by looking in the datasheet first.
    If you keep going with all of your add ons (includes) you will have any PIC as easy as a STAMP.

    What is the maximum amount of includes you have used in a program?
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Exclamation

    I hope not ... Stamp's don't bring back any memories of "Easy" for me.
    What is the maximum amount of includes you have used in a program?
    Probably 12-15, but I've never really counted.

    90% of my programs only have 2 includes.
    care to guess which ones?
    <br>
    DT

  8. #8
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by DT

    90% of my programs only have 2 includes.
    care to guess which ones?
    Care if I take a shot? Must be DT_ints and PBP_reenter.


  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Ding Ding Ding ... Give that man a cigar!

    If you smoke cigars
    <br>
    DT

  10. #10
    Join Date
    Jun 2007
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Thanks for the replies!

    Including "ALLDIGITAL.pbp" didn't affect anything (as far as I can tell). Attempting to set those registers simply gives me a couple of compiler errors about an "undefined symbol." Charle's example, however, did the trick. Any idea why the other suggestions didn't work?

  11. #11


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    90% of my programs only have 2 includes.
    care to guess which ones?
    <br>
    BS1DEFS.BAS and BS2DEFS.BAS? lol

  12. #12
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ShortBus View Post
    Thanks for the replies!

    Including "ALLDIGITAL.pbp" didn't affect anything (as far as I can tell). Attempting to set those registers simply gives me a couple of compiler errors about an "undefined symbol." Charle's example, however, did the trick. Any idea why the other suggestions didn't work?
    You might have the wrong chip selected in the Device drop-down box.
    Because those are the registers you need to set for a 16F688.
    <br>
    DT

  13. #13
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    BS1DEFS.BAS and BS2DEFS.BAS? lol
    Reply With Quote
    Very funny! Made me smile.

  14. #14


    Did you find this post helpful? Yes | No

    Default

    Darrel's not speaking to me now

    [gives Darrel a little prod]

  15. #15
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by comwarrior View Post
    Darrel's not speaking to me now
    Did I miss something?

    I've got that "Paying the rent" thing going on, haven't talked to hardly anyone recently.
    Why can't it be the 24th century, so we don't need money anymore?

    If you meant post #11 ...
    My opinions should be well known ...

    DT

  16. #16
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Red face

    Ouch, that brings back painful memories of the time i stepped on an IC lying on it's back. No, i was not wearing shoes at the time ......

  17. #17
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ingvar View Post
    Ouch, that brings back painful memories of the time i stepped on an IC lying on it's back. No, i was not wearing shoes at the time ......
    One of the reasons I like surface mounts...
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. SERIN MIDI out of Synch?
    By jncortes in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th June 2009, 20:08
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

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