Archangel
- 23rd August 2006, 19:31
Hi, All,
I copied this demo program from "Programming PIC Microcontrollers with Pic Basic" ,by Chuck Hellebuyck. Its function is to scroll across LEDs hooked up to each pin on port B like the lights on the front of the Knight Rider car, so as to demonstrate how the FOR NEXT statements count.
My question is why does it do its counting by switching pins, instead of counting only on 1 pin? To my UNTRAINED Eye it does not mention the other pins, yet it works just as he promises.
<quote> 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.
</quote>
I copied this demo program from "Programming PIC Microcontrollers with Pic Basic" ,by Chuck Hellebuyck. Its function is to scroll across LEDs hooked up to each pin on port B like the lights on the front of the Knight Rider car, so as to demonstrate how the FOR NEXT statements count.
My question is why does it do its counting by switching pins, instead of counting only on 1 pin? To my UNTRAINED Eye it does not mention the other pins, yet it works just as he promises.
<quote> 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.
</quote>