Just need to clarify...


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default

    Tazntex,

    In your first post you said

    I understand how it repeats until i is equal to 7 then moves on but what does the [i] in PORTB.0[i] do?
    Technically speaking, it repeats until I=8 then it exits the loop. Of course, it won't execute the line PORT[I]=0 for I=8.

    Robert

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Thanks goes to all for you help and interest.

  3. #3
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Random Portx.Bit

    While were on the subject of Port.Bits. I would like to use a random generator to set a single bit in an output port while working with an 8x8 dot matrix display. Is there any way to use a VARiable to set a RANDOM single Bit on an output port?

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Is there any way to use a VARiable to set a RANDOM single Bit on an output port?
    Ran_Word var word

    Ini:
    RANDOM Ran_Word
    pause 100
    PortB = Ran_Word.byte0
    Pause 100
    PortB = Ran_Word.byte1
    Goto Ini

    This code should suite your need.

    Al.
    All progress began with an idea

  5. #5
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Reply to Al

    Al, thanks for your replay. I ran your code. it sets the whole port at a random value. I need to figure out how to set a single bit within the port. I want to turn on a single led on the 8x8 display, then PAUSE, then loop to routine. Any idea how to single out one bit randomized?

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    I want to turn on a single led on the 8x8 display, then PAUSE, then loop to routine. Any idea how to single out one bit randomized?
    This has been shown at the begining of the thread. Anyhow in your case:




    Code:
    Ran_Word var word
    AA0         var Byte
    
    Ini:
    RANDOM Ran_Word
    For AA0= 0 to 7
    Pause 100
    PortB.0[AA0] = Ran_Word.0[AA0]
    pause 100
    PortC.0[AA0] = Ran_Word.0[AA0 + 8]
    Next AA0
    goto Ini
    In the above example I assume you are using portB and PortC, if not then change them as per your need.

    Al.
    All progress began with an idea

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


    Did you find this post helpful? Yes | No

    Default

    Try this;
    Code:
    X VAR WORD
    OldVal VAR BYTE
    PortVal VAR BYTE
    
    TRISB = 0
    
    Main:
       RANDOM X
       PortVal = DCD X.HighByte       ' get bit #
       IF PortVal = 0 THEN Main       ' value should always be > 0
       IF OldVal = PortVal THEN Main  ' value should be different on every pass
       PORTB = PortVal
       OldVal = PortVal               ' record old value for next pass
       PAUSE 200
       GOTO Main
    
       END
    Regards,

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

  8. #8
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default reply to Al

    Al, closer but not there yet. Sorry for the delay, I had to adjust your code to invert the Collumn port for this display. Bruce I haven't tested yours yet but I had started in that direction.

    Bitgenerator:
    Bvar=-0
    random Ran_Word
    Avar= Ran_Word.byte0
    if Avar.0=1 then Bvar=Bvar+1
    if Avar.1=1 then Bvar=Bvar+2
    if Avar.2=1 then Bvar=Bvar+4 ;isolate a random number 0to7
    Cvar=1
    Cvar=Cvar<<Bvar ;set a single bit in the byte
    Cvar=Cvar^$FF ;invert for a low on one bit
    rcol=Cvar ;set port
    Bvar=0
    random Ran_Word
    Avar= Ran_Word.byte0
    if Avar.0=1 then Bvar=Bvar+1
    if Avar.1=1 then Bvar=Bvar+2
    if Avar.2=1 then Bvar=Bvar+4
    Cvar=1
    Cvar=Cvar<<Bvar
    Row=Cvar
    pause 100
    goto Bitgenerator

    (Wierd: code tag nor the editor would accept << in the code)


    this method works (sorry you can't see all the code) but gives some repetition in general pattern on the diagonal. I will use the DCD. I'm still trying to understand Al's "Ran_Word.0[AA0 + 8]" . What is this doing to the PortC.0[AA0], is it resetting to a number less than 8?
    thanks guys, I'll have to chew on this for a while.
    Last edited by MOUNTAIN747; - 30th March 2010 at 21:05. Reason: post editor doesn't like <<

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