RF12 module need to convert some C to Basic


Closed Thread
Results 1 to 40 of 44

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    void WriteCMD( uint CMD ) <-uint CMD takes in an unsigned integer
    {
        uchar n=16; <-unsigned character (byte) set to 16
        SCK=0; <- SCK to logic low
        nSEL=0; <- nSEL to logic low
        while(n--) <- while/wend loop, n gets decremented by 1 each time thru
        {
            if(CMD&0x8000) <- if high bit of CMD is set then
              Write1(); <-call the Write1() sub
            else
              Write0(); <-otherwise do this one
            CMD=CMD<<1; <-shift it left by one
        }
        SCK=0; <- SCK to logic low
        nSEL=1; <- nSEL to logic high
    }
    I might be totally wrong...not that familiar with C...but to me this means:

    Code:
    WriteCMD:
    n = 16 : SCK = 0 : nSEL = 0
    for nn = 16 to 0 step -1
    if cmd.15 = 1 then
    gosub write1
    else
    gosub write0
    endif
    cmd = cmd << 1 : sck = 0 : nSel = 1 : return
    
    Write0:
    SDI = 0 : SCK = 0 : pauseus 16 : SCK = 1 : return
    
    Write1:
    SDI = 1 : SCK = 0 : pauseus 16 : SCK = 1 : return
    And your issue might've been that you didn't turn the nSEL line on/off before writing out to the port...unless you didn't include that part in the posts.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,175


    Did you find this post helpful? Yes | No

    Default

    I really wonder if the skimask's example will work because is the same shiftout command.

    I have also ordered a couple of the modules (the high power ones) but will be delay and cannot test them right now.

    Ioannis

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    I really wonder if the skimask's example will work because is the same shiftout command.
    Ioannis
    It is the same...
    I think the only difference is toggling the SEL line.

  4. #4
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default nSEL

    Skimask,

    Thankyou for doing that... From the little bit of C that I have learnt in the last 24 hours, that looks good.

    I did try nSEL last night with a couple of code attempts, but I did not try it consistantly.

    I did also try to use the SSP last night for a short period. No luck yet, but I didn't expect it to be easy, I haven't used the SSP yet.

    I am off to work now, but will try again later today.


    Thanks for the assistance.
    Last edited by davewanna; - 10th June 2008 at 00:09.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,175


    Did you find this post helpful? Yes | No

    Default

    It could be a timing issue. No time to check now. If anyone could?

    Ioannis

  6. #6
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default word to bit[16]

    I am just getting started on this again tonight...

    I the example from Skimask above, the variable CMD is I assume an array of 16 bits? so I should declare..

    Code:
    CMD  VAR  bit[16]
    Am I correct?


    My next question is how do I get my word variable into series of 16 bits?

    Code:
    dout = $D0F7
    
    for n = 16 to 0 step -1
      CMD[n] = %dout.15
      dout << 1
    next n


    Keep in mind I am almost certain that the above example will not work... It's just to show that I am trying, not just asking everyone else to make my project for me...

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,175


    Did you find this post helpful? Yes | No

    Default

    For this CMD[n] = %dout.15 try as:

    CMD.0[n] = %dout.15

    Ioannis

Similar Threads

  1. Version Control
    By btaylor in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 16th October 2011, 18:12
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  3. Replies: 1
    Last Post: - 27th July 2008, 07:14
  4. using AND as an IF statement
    By dw_pic in forum mel PIC BASIC
    Replies: 27
    Last Post: - 8th June 2006, 19:05
  5. convert Basic Stamp2 (BS2) => Pic
    By bs2rdu in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th September 2005, 20:55

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