How can I use for next like PORTB.MYVARIABLE ???


Closed Thread
Results 1 to 11 of 11
  1. #1
    obaskirt's Avatar
    obaskirt Guest

    Question How can I use for next like PORTB.MYVARIABLE ???

    '-------------[LED BLINKING SHOW]--------------

    LED VAR BYTE ' Our variable name is LED.

    TRISB = %0000000 ' All pins of port B are output.
    PORTB = 0 ' initially turn off all leds.

    LED=0 ' Make LED variable initially zero.

    Loop:

    FOR LED=0 to 7
    HIGH PORTB.LED ' --> problem occured.
    PAUSE 1000
    LOW PORTB.LED ' --> problem occured.
    PAUSE 1000
    NEXT LED

    GOTO Loop

    End



    IS there any simple way to do this???

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    for LED=0 to 7
         HIGH LED
        PAUSE 500
        LOW LED
        PAUSE 500
        NEXT
    Steve

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

  3. #3
    obaskirt's Avatar
    obaskirt Guest


    Did you find this post helpful? Yes | No

    Red face

    Quote Originally Posted by mister_e
    Code:
    for LED=0 to 7
         HIGH LED
        PAUSE 500
        LOW LED
        PAUSE 500
        NEXT
    My problem is; I can not define PORTB.LED??? and in your example which port did you make high or low? For example, I connected 8 leds to PIC 16F84's PortB. How can you turn on then turn of these leds by using for next loop. Also you can do this by left and right shift operator but I am curious about how can this problem accomplish by using for-next loop. Thankss..

  4. #4
    MaurI's Avatar
    MaurI Guest


    Did you find this post helpful? Yes | No

    Default

    i var byte
    x var byte

    TRISB=0

    i=0
    begin
    For i=0 to 7

    Lookup i,[1,2,4,8,16,32,64,128],x
    PORTB=x
    Pause 200
    next i
    i=0
    goto begin

    end


    Well in this little sample there is For next so check it out!

    And don't use those High and Low if it is possible better use =0, =1 - it will save your code space
    Last edited by MaurI; - 2nd September 2005 at 11:55.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by obaskirt
    My problem is; I can not define PORTB.LED??? and in your example which port did you make high or low? For example, I connected 8 leds to PIC 16F84's PortB. How can you turn on then turn of these leds by using for next loop. Also you can do this by left and right shift operator but I am curious about how can this problem accomplish by using for-next loop. Thankss..
    low = 0 does the same thing as low portb.0. You can address portb 0-7 and portc 8-15 like this. I'm not sure if you can access other ports in this fashion or not though.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

  7. #7
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Lightbulb

    tou can make it that way:

    Code:


    TRISB = 0
    INTCON = 0

    X VAR BYTE

    FOR X = 0 TO 7
    PORTB.0[X] = 1
    PAUSE 500
    PORTB.0[X] = 0
    PAUSE 500
    NEXT X

    END
    Last edited by crematory; - 2nd September 2005 at 17:35.

  8. #8
    Join Date
    Oct 2005
    Posts
    35


    Did you find this post helpful? Yes | No

    Question Port Pin Steering Variable

    Hello,

    Following the thread above, the code below does not work unless the value of k is made a constant as in: SOUND PORTC.5,[115,120,113,118]. I have never been able to use a variable to steer outputs to a specific pin. Any ideas?


    pic16f8783

    'sound on pin k port c

    TRISC= %00000000
    k var byte


    start:
    k=5
    SOUND PORTC.0[k],[115,120,113,118]
    GOTO START



    "I don't know, Marge. Trying is the first step towards failure."

  9. #9


    Did you find this post helpful? Yes | No

    Default

    You should be able to use:

    sound x,[115,120,113,118]

    Where is x is between 0-15 with PORTA.0 being 0 and PORTC.7 being 15.

  10. #10
    Join Date
    Oct 2005
    Posts
    35


    Did you find this post helpful? Yes | No

    Thumbs up

    WOOHOO!

    Thanks, yes that works, but I have never seen it written that ports A and C are linked and addressed this way. So then, PortC.5 is 13? I never would have thought of this. Is that only for the sound command? What about the addressing for port B.







    "Asleep at the switch? I wasn't asleep, I was drunk."

  11. #11
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    It's all in the PBP Manual, section 4.11 Pins...

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