Interpret to Picbasic Code ¿?!!


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Interpret to Picbasic Code ¿?!!

    Well, I'm no C wisard but the lines 114,115 are defines for what looks like 2 variables called "msb" and "lsb". These are defined as unsigned 8 bit variables. Now with out any more code I can only quess that line 120 is taking the "msb" variable and doing a left shift 4 places and adding the "lsb" variable being right shifted by 4 places together then placing the result into "chip->vcell". Thats my take on it...
    Dave Purola,
    N8NTA
    EN82fn

  2. #2
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Re: Interpret to Picbasic Code ¿?!!

    It's been a while, but I'd agree about

    u8 msb;
    u8 lsb;

    as being declarations of those variables in each function and what they will hold.

    Those whole thing just looks like it's reading in I2C data, and maybe swapping the bit order?

    Man, it's been so long since I had to work with something like that.

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Interpret to Picbasic Code ¿?!!

    Code:
    chip->vcell = (msb << 4) + (lsb >> 4);
    This is already basic on the right side of the equal sign,
    on the other side it’s addressing an element of a structure (a list)
    which can be done with any PBP array with a variable index like:
    Code:
    var word vcell
    var byte/word chip[size]
    
    ...
    
    chip[vcell] = value or sum
    I don’t know why they are doing it, the four bytes that roll off each end would be discarded in both languages (not carried).

    For both of these, this is a call to a function (subroutine in basic):
    Code:
    msb = max17040_read_reg(client, MAX17040_VCELL_MSB);
    You have not posted the function, but I assume it’s the lower level I2C function (I2CREAD/WRITE...).

    The parameters in brackets are arguments passed to the function as input which would be the address.
    The return value is when is written into the value to the left of the equal sign for calling the function.
    The basic subroutine would read a variable for the EEPROM address that was set by the main loop,
    and set another variable with the result data, later read by the main loop that called the subroutine.

    In PBP the I2C commands would probably be just the same written inline with the main program loop.
    In the C code the functions might be an eyesore to throw at the bottom of your page.

Similar Threads

  1. Ghange code picbasic
    By savnik in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 21st June 2011, 16:16
  2. MPXA4115A picbasic code
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 103
    Last Post: - 3rd March 2011, 17:25
  3. MPPT code in picbasic
    By showtime in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd October 2007, 01:11
  4. is there cd player code in picbasic
    By mech in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 5th December 2006, 19:43
  5. PicBasic code relocating
    By orsobruno in forum General
    Replies: 0
    Last Post: - 2nd November 2005, 21:40

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