Why does this program switch pins?


Results 1 to 8 of 8

Threaded View

  1. #6
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Wink

    Joe -
    The author is using a different method for telling the micro which pin to turn on or off. He's using an array. With this method you can minimize the amount of code needed, and hence the cleaner, tidier code. Let's walk through it with some more comments.
    Code:
    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 
    This variable not only counts up, but also indicates which pin
    should turn on or off. 
    portB.0[LED] = 1 'Set each pin of portb high (5 volts) which turns the LED on
    The first time through the loop, LED = 0.  So the statement
    PORTB.0[LED]  = 1 is the same as writing portB.0 = 1.
    The next time through the loop, LED will = 1, which is the same
    as writing portB.1 = 1 and so on.
    Think of it as turn on PORTB.0 + the value in the LED variable.
    pause 1000 'Pause 1000 milliseconds (1 second) with LED on
    Now look at Sayzer's post and it should make much more sense.
    Last edited by rhino; - 23rd August 2006 at 23:31.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

Similar Threads

  1. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  2. Replies: 11
    Last Post: - 6th November 2008, 10:27
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 14:30
  5. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10

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