undocumented code


Closed Thread
Results 1 to 7 of 7
  1. #1
    ilteris's Avatar
    ilteris Guest

    Default undocumented code

    Hi list,
    I just have found about this code in this forum but when I tried to make it work, it seems it is not working, I am trying to keep my pins in an array to re-call them later and it seems this way is no go, so if you advice me a way to do it I'd appreciate it so much.

    ilteris.

    TRISC = 0
    myArray var PORTC
    i var byte

    main:
    for i = 0 to 7
    myArray.0[i]= 1
    myArray.0[i-1] = 0
    pause 500
    next
    goto main

  2. #2
    mikefox's Avatar
    mikefox Guest


    Did you find this post helpful? Yes | No

    Default

    I'm not at home, so I can't compile this, but I think it should work. I assumed you wanted to write back to the port again. As far as i know, you can't write an array in one go, you need to write each byte seperately.

    TRISC = 0
    i var byte

    main:
    for i = 0 to 7
    PORTC.i = 1
    PORTC.(i-1) = 0
    pause 500
    next
    goto main

  3. #3
    ilteris's Avatar
    ilteris Guest


    Did you find this post helpful? Yes | No

    Default

    thanks for the quick reply mike. I dont have any problems compiling the code although when I try it on my circuit it is giving me weird things, only making the first pin high mode and then setting it low and giving to the rest a lil bit current, I can see a very brief light on them.

    All I want is just to makethem high and make them stay at that way.

    any comments?

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


    Did you find this post helpful? Yes | No

    Default

    You don't mention which PIC you're using, but assuming it doesn't have some peripheral functions on portC, you're using limiting resistors on the LED's, and have them connected properly, your code should work fine.

    You may want to change the myArray.0[i-1] = 0 however.

    On the 1st pass, 0-1 = 255 which probably isn't doing what you may expect.
    On the last pass, 7-1 = 6, and you'll never clear RC7.

    Try something like this;
    Code:
    main:
        for i = 0 to 7
          myArray.0[i]= 1
          pause 50 ' or whatever
          myArray.0[i]= 0
        next
        goto main
    If I run the above example on a 16F876A, it turns on/off 8 LED's on portb in ~50mS intervals. I don't have a board with 8 LED's available on portc, but it should work all the same on any available 8-bit port. Assuming this port on the PIC you're using doesn't have some peripheral functions you have enabled.
    Regards,

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

  5. #5
    ilteris's Avatar
    ilteris Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for the response Bruce. I am using 18f452 and what if I try to change your code like this below:

    Code:
    main:
        for i = 0 to 7
          myArray.0[i]= 1
        next
        goto main
    does this mean they are all going to be high and stay at that position? I have been trying to do this for 2 days now wit no dice.

  6. #6
    Join Date
    Nov 2004
    Location
    Fribourg, Switzerland
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    Hi Ilteris,

    If I do remember what the manual says about pins, using the index on a 40 pin chip it will make reference to Port B and C. So index from 0 to 7 refers to Port B and 8 to 15 to port C.

    So if you want to high pin PortC.0 you can address to it like this:

    High PortB.0[8]

    so your code should look look like this:

    TRISC = 0
    myArray var PORTB
    i var byte

    main:
    for i = 8 to 15
    myArray.0[i]= 1
    myArray.0[i-1] = 0
    pause 500
    next
    goto main

    Hope this help.

    Hans

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


    Did you find this post helpful? Yes | No

    Default

    Yes.

    If you use the following, then each pin on portC will stay high.
    Code:
    main:
        for i = 0 to 7
          myArray.0[i]= 1
        next
        goto main
    All you are doing with myArray var PORTC is creating an alias or another name for portC. This does NOT create a normal variable using RAM. It only creates another name or alias to portC that is used only at compile time. Each reference to myArray will reference portC.

    Using myArray.0[i] just indexes individual bits or pins on portC. The .0 after the name just tells PBP it's a bit index.

    You would get the same result with something like;
    Code:
    main:
        for i = 0 to 7
          PORTC.0[i]= 1 ' <-- make PORTC.Bit i high
        next
        goto main
    The method mentioned above by Hans will work also. However, just which pins this will work on is dependent on the PIC you're compiling for.

    You have to be careful with this method of array.bit indexing (or any other array) since PBP does perform bounds checking.

    I.E. if you have an array (myArray) limited to 16-bits in size, it would hold 16-bits from 0 to 15. You can still index a bit position outside the bounds of this array with something like myArray.0[16]=1. This will not generate an error at compile time, and it will set a bit outside the bounds of your array. So you need to be careful. You can affect areas outside the bounds of an array.
    Last edited by Bruce; - 19th October 2005 at 16:22.
    Regards,

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

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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