Simultaneous outputs


Closed Thread
Results 1 to 7 of 7
  1. #1

    Default Simultaneous outputs

    Just starting out with the PIC's and don't understand why I can't get three LED's to all flash on and off at a 1/2 second rate. Using 12F675 with PBP with the following code:

    Start: HIGH 0
    HIGH 1
    HIGH 2
    PAUSE 500
    LOW 0
    LOW 1
    LOW 2
    PAUSE 500
    GOTO Start:

    With this code GPIO.0 goes on and off at a ~1.7mS rate. GPIO.1 and GPIO.2 are always off. Shouldn't all three go on and off?

    I can rewrite the code and drop off the first pause and put the GOTO in it's place and all three will come on and stay on as expected.
    All three outputs can be programmed individually to flash in any order or rate.
    Looking for ideas please?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    The HIGH & LOW commands take care of the TRIS registers for you to make your I/O-pins outputs, but they don't take care of certain built-in hardware peripheral features.

    In this case, that would be the onboard comparator & A/D modules.

    Try this;

    Code:
     
    CMCON = 7 ' Comparators off
    ANSEL = 0   ' A/D off, set I/O to all digital
    
    Start:
          HIGH 0
          HIGH 1
          HIGH 2
          PAUSE 500
          LOW 0
          LOW 1
          LOW 2
          PAUSE 500
          GOTO Start
    Take a peek in the datasheet under the Comparator Module & Analog-to-Digital sections to see why this makes it work.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce, that cleared up everything. I didn't find it in the config. setup as an option in the MicroCode Studio. Will code it in as necessary from now on. FB

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


    Did you find this post helpful? Yes | No

    Default

    You can also do your task in less line and it will take less of your code space.

    Code:
    CMCON = 7
    ANSEL = 0 
    
    Start: 
    
             GPIO=7
             PAUSE 500
             GPIO=0         
             PAUSE 500
             GOTO Start

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Close, but you forgot to configure your pins as outputs.
    All I/O-pins are inputs on power-up by default.

    This would work.

    Code:
    CMCON = 7
    ANSEL = 0
    TRISIO = 0 ' GPIO = outputs
    
    Start: 
             GPIO=7
             PAUSE 500
             GPIO=0         
             PAUSE 500
             GOTO Start
    And if you're really stingy on code space, you could do it something like this;

    Code:
    CMCON = 7
    ANSEL = 0
    TRISIO = 0 ' GPIO = outputs
    GPIO = 7
    
    Start: 
             GPIO = GPIO ^ 7 ' Toggle GPIO.0, 1 and 2
             PAUSE 500
             GOTO Start
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    well done again Bruce. I was aware of this TRSIO line since i've never use this before considering that PBP was suppose to do. But after experimenting i realise that was important to include in this case. I'll use this TRIS in future as a safe programming way.

    that's for sure there's many way to blink a led. XOR function are one example . code also working without GPIO=7 but it's also a safe way.
    Steve

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

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Wow , many ways of doing things better with the first lines of code. Great eye opener. Thans to the group. FB

Similar Threads

  1. 30 PWM outputs on one chip?
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th September 2009, 16:32
  2. 8 pin DIP w/6 outputs ?
    By Sam in forum General
    Replies: 12
    Last Post: - 14th September 2009, 20:15
  3. PIC16F62X outputs
    By Deadeye in forum General
    Replies: 6
    Last Post: - 31st May 2005, 21:20
  4. making ports outputs on a 12F629
    By bartman in forum mel PIC BASIC
    Replies: 2
    Last Post: - 14th November 2004, 17:47
  5. Replies: 0
    Last Post: - 28th May 2004, 17:25

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