How to use For Next Loop to run sequence light ?


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Thanks.

    Ok Now all the LEDs light up.

    BUT only PortB.0 and PortB.1 Blinks.

    Again, this the code:
    Code:
    @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT, MCLR_OFF
    CMCON = 7
    TRISA = 0 ' Make them all outputs
    TRISB = 0
    
    Counter var Byte
    
    SubRoutine:
    
    For Counter = 0 to 2
    high PortB.0[Counter]
    high PortA.0[Counter]
    Next Counter
    
    Pause 600
    
    For Counter = 0 to 2
    Low PortB.0[Counter]
    Low PortA.0[Counter]
    Next Counter
    
    pause 100
    Goto SubRoutine

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bracer View Post
    Thanks.

    Ok Now all the LEDs light up.

    BUT only PortB.0 and PortB.1 Blinks.

    Again, this the code:
    Code:
    @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT, MCLR_OFF
    CMCON = 7
    TRISA = 0 ' Make them all outputs
    TRISB = 0
     
    Counter var Byte
     
    SubRoutine:
     
    For Counter = 0 to 2
    high PortB.0[Counter]
    high PortA.0[Counter]
    Next Counter
     
    Pause 600
     
    For Counter = 0 to 2
    Low PortB.0[Counter]
    Low PortA.0[Counter]
    Next Counter
     
    pause 100
    Goto SubRoutine
    Hi, Bracer

    I suspect a RMW issue ... as HIGH and LOW already cares of driving inputs and outputs

    How much current do you send to your Leds ???

    try to limit it to 5 mA per Led ... as a first try.

    as a second try ...

    Code:
    @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT, MCLR_OFF
    CMCON = 7
    TRISA = 0 ' Make them all outputs
    TRISB = 0
     
    Counter var Byte
     
    SubRoutine:
     
    PORTA = PORTA | % 00000111
    PORTB = PORTB | % 00000111
    Pause 600
     
    PORTA = PORTA & % 11111000
    PORTB = PORTB & % 11111000
     
    pause 100
     
    Goto SubRoutine
    a scheme of your circuit really would be welcome ...

    Alain
    Last edited by Acetronics2; - 29th August 2010 at 17:03.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Aug 2010
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    I am getting a
    Code:
    WARNING Line 20: Bad token "%".
    WARNING Line 21: Bad token "%".
    WARNING Line 24: Bad token "%".
    WARNING Line 25: Bad token "%".
    WARNING Line 24: 11111000 Numeric overflow, value truncated. (Test.pbp)
    WARNING Line 25: 11111000 Numeric overflow, value truncated. (Test.pbp)
    When I copy and paste the code your exact codes.


    You are right Acetronics, I am using a +6V, but I did try the manual "High PortA.0" way to manually set each pin and it works.
    Every single pins are all functional, so it couldn't have been a pin damage issue.

    The schematic is really empty, Pin 5 to the negative and Pin 14 to the positive,
    PortB.0 ~ PortB.2 to LEDs.
    PortA.0 ~PortA.2 to LEDs, that's all.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bracer View Post
    I am getting a
    Code:
    WARNING Line 20: Bad token "%".
    WARNING Line 21: Bad token "%".
    WARNING Line 24: Bad token "%".
    WARNING Line 25: Bad token "%".
    WARNING Line 24: 11111000 Numeric overflow, value truncated. (Test.pbp)
    WARNING Line 25: 11111000 Numeric overflow, value truncated. (Test.pbp)
    When I copy and paste the code your exact codes.


    You are right Acetronics, I am using a +6V, but I did try the manual "High PortA.0" way to manually set each pin and it works.
    Every single pins are all functional, so it couldn't have been a pin damage issue.

    The schematic is really empty, Pin 5 to the negative and Pin 14 to the positive,
    PortB.0 ~ PortB.2 to LEDs.
    PortA.0 ~PortA.2 to LEDs, that's all.
    There is no space betweeen the % and the binaty number; Example: %00000111

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

    Anonymous

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Hi, Bracer

    sorry for the "space" ...

    For your leds ... place a series resistor : 220 Ohms as a minimum @ 6v supply ...

    I know some do not use resistors ... but it creates RMW issues !!!

    You MUST keep current inside the specified limits ( ABSOLUTE limits: 25 ma - 100 mA per full port ) , but do not rely on the internal limitation ... or you'll get surprises !!!

    Alain
    Last edited by Acetronics2; - 30th August 2010 at 09:38.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Aug 2010
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    WOW Acetronics....
    You are so cool!


    Code:
    Make PortA and PortB's 0~2 lights up.
    PORTA = PORTA | %00000111
    PORTB = PORTB | %00000111
    
    Make PortA and PortB's 0~2 lights Down.
    PORTA = PORTA & %11111000
    PORTB = PORTB & %11111000
    Completely works...wow...in just one line you have set 3 lights from PortB to light up...

    It suddenly makes this whole "High PortB.0" look barbaric!
    I don't exactly know "How" you set it, but I did try to experiment, I went ahead and try to make the light goes from the outside two lights to the inside one light, basically:

    Code:
    High PortB.0
    High PortB.2
    Low PortB.1
    
    Pause 500
    
    Low PortB.0
    Low PortB.2
    High PortB.1
    
    Pause 500
    Low PortB.0
    Low PortB.2
    Low PortB.1
    
    Pause 500
    But me...trying to "copy" your way, not knowing what I am doing, do this:
    Code:
    PORTA = PORTA | %00000101
    PORTB = PORTB | %00000101
    Pause 500
     
    PORTA = PORTA & %00000010
    PORTB = PORTB & %00000010
     
    pause 500
    Let's just say the lights acted weird, I have no idea what "|" in the code does either than it's probably "Or" ?
    Not to mention "&" either than C's "And" ?

    But they are single and not in pairs...some sort of bit shifters ?

    Must trying to understand this concept...one line to control all Port Outputs....so powerful...but so mysterious to me...

    Anyway thanks Acetronics, I use a 470 ohm for the LEDs under +6V

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bracer View Post
    But me...trying to "copy" your way, not knowing what I am doing, do this:

    Code:
    PORTA = PORTA | %00000101
    PORTB = PORTB | %00000101
    Pause 500
     
    PORTA = PORTA & %00000010
    PORTB = PORTB & %00000010
     
    pause 500
    PORTA = PORTA | %00000101 = Read PORTA and set to 1 ports A0 and A2

    PORTA = PORTA & %00000010 = Read PORTA and clear ports A0 and A2

    you use " | " ( OR ) to SET portspins and & ( AND ) to clear them ... but no mix allowed

    you can try ...
    Code:
     
    PORTA = PORTA | %00000101
    PORTB = PORTB | %00000101
    .
    .
    .
    .
     
    Subroutine:
     
    PORTA = PORTA ^ %00000111 ' FLIPS the bits with a " 1 " 
    PORTB = PORTB ^ %00000111
     
    pause 500
    GOTO Subroutine
    see your manual " Bitwise Operators " section $4.16.17

    Alain
    Last edited by Acetronics2; - 30th August 2010 at 19:44.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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