Shop OBEX P1 Docs P2 Docs Learn Events
DAT block help — Parallax Forums

DAT block help

stilgarstilgar Posts: 47
edited 2010-12-16 20:34 in Propeller 1
Hello,
I am looking for help on how to use a DAT block. I am wanting to make a data array so I can control 12 pins.

the data i would like to look like this.

111111111111 110010001000

the program would read the 12 bit word and directly control pins connected to that bit

another example would be

pin 12 13 14 15 16 17 18 19 20 21 22 23
1 1 0 0 0 1 1 1 1 1 0 0

1= high 0=low


thanks

Comments

  • kwinnkwinn Posts: 8,697
    edited 2010-12-16 14:49
    Not quite clear on what you want to do. Are you writing a PASM program to control these pins or is it spin? Also pinouts are different between the DIP and LQFP/QFN packages so I am assuming you mean P12 - P23 (ports 12 - 23 rather than pins).
  • stilgarstilgar Posts: 47
    edited 2010-12-16 17:21
    Hello,

    Kwinn, I am using the DIP package. if ports are the same as pins on this package, then yes, ports 12-23.
    I am wanting to use spin for the programing. May I ask if you write it, please use lots of comments, so I can understand and learn from it. basically what I want to do is, control a matrix of LEDs. the matrix is 8 LEDs tall and 4 LEDS wide.


    thanks,
    stilgar
  • AribaAriba Posts: 2,690
    edited 2010-12-16 18:04
    You can access the data in the DAT section like variables and arrays.
    With Spin it is very easy to write a number of contiguous pins with 1 command:
    outa[23..12] := value
    this writes the lower 12 bits of value to pins 12..23

    Here is a little example which combine these:
    PUB main | i
      dira[23..12] := %111111111111  'set the 12 portpins as output
    
      'write data from DAT to 12 port pins
      repeat i from 0 to 15
        outa[23..12] := pattern1[i]  'write word from DAT to port
        waitcnt(clkfreq/4 + cnt)     'short delay
       
    DAT
    pattern1  word %100111110000, %101000001010, %111100001111
              word %000011110000, %010110100101, ....16 words
    
    pattern2  word %111111110001, %001000001000, %111111111111, ...
    
    ' a word has 16 bits, we use only the lower 12
    
    (untested)

    Andy
  • stilgarstilgar Posts: 47
    edited 2010-12-16 19:21
    Hello,
    Thanks Andy, It works. only question, how do I calculate the delay to resemble 15 hertz? the manual is a bit low on this area.

    thanks again,
    stilgar
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-16 19:37
    stilgar wrote: »
    ... how do I calculate the delay to resemble 15 hertz? the manual is a bit low on this area.

    I assume you read the 4 pages detailing waitcnt (p.218-221). AFAICS there is all the info you need. Which bit do you think is inadequate?

    To answer your question: waitcnt(clkfreq/15 + cnt).
  • stilgarstilgar Posts: 47
    edited 2010-12-16 20:34
    HELLO,
    Thanks, I am going to have to read it better, I got myself confused because I am using a outside crystal of 5 MHz. I think I have it now, until the next question.

    Thanks again everyone,
    stilgar
Sign In or Register to comment.