For next loop using: Led var Byte


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2008
    Posts
    8

    Default For next loop using: Led var Byte

    I am trying to get Chucks second project from his book to work, which is Scrolling led's.
    They do flash but not correctly.
    This is the programme pasted from his book.

    LED var Byte 'LED variable setup as byte

    PortB = %00000000 'Initiate all port B pins to low
    Trisb = %00000000 'Setup port b as all outputs
    main: 'Label for beginning of main loop

    ' *********** Light LEDs in right direction

    for led = 0 to 7 'Loop through all LEDs
    portB.0[LED] = 1 'Set each pin of portb high (5 volts) which turns the LED on
    pause 1000 'Pause 1000 milliseconds (1 second) with LED on
    portb.0[LED] = 0 'Set each pin of portb low (0 volts) which turns the LED off
    next 'Continue until all 7 have been lit once

    ' *********** Light LEDs in left direction

    for led = 7 to 0 step -1 'Loop through all LEDs backwards

    portb.0[led] = 1 'Set pin 0 of portb high (5 volts) which turns the LED on
    pause 1000 'Pause 1000 milliseconds (1 second) with LED on
    portb.0[led] = 0 'Set pin 0 of portb low (0 volts) which turns the LED off
    next 'Continue until all 7 have been lit once

    goto main 'Jump to the main label and do it all again and again

    END 'This line is not needed but its safe to put it here just in case
    ' the program gets lost.

    Thanks to anyone who can help,
    Quester.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by quester View Post
    They do flash but not correctly.
    How do they flash?
    'NOT CORRECTLY' leaves a lot up to the imagination...

  3. #3
    Join Date
    Mar 2006
    Location
    Pennsylvania, USA.
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Try it without the for next loop, just to make sure that your wiring is fine,
    portb.0 = 1
    pause 1000
    portb.0 = 0
    pause 1000
    portb.1 = 1
    pause 1000
    portb.1 = 0
    pause 1000
    portb.2 =1

    etc. etc.

    Jerry
    If your oscilloscope costs more than your car...

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


    Did you find this post helpful? Yes | No

    Default

    Insert PAUSE 1000 after each portb.0[led] = 0.
    Regards,

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

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. LCD freeze
    By harryweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th October 2009, 08:01
  3. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  4. large program oddity
    By lsteensl in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th April 2007, 06:28
  5. 16F877 RAM Question
    By Art in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 6th August 2005, 11:47

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