Interpret to Picbasic Code ¿?!!


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2013
    Posts
    12

    Default Interpret to Picbasic Code ¿?!!

    Hello,

    As I interpret this in Picbasic code:
    It is for the IC MAX17040, Project GauGauge
    Clearly are functions or subroutines.

    The lines 111 and 123, I think are Subrutines.
    The lines 117 and 118 , I think variable reg MSB,LSB
    The lines 113 and 125, I think calls to chip
    The lines 129 and 130, I think variable reg MSB,LSB

    But the lines 114, 115 ,120 and 132 I don´t understand.

    -------------------------------------------------------------
    Code:
    111 static void max17040_get_vcell(struct i2c_client *client)
    112 {
    113         struct max17040_chip *chip = i2c_get_clientdata(client);
    114         u8 msb;
    115         u8 lsb;
    116 
    117         msb = max17040_read_reg(client, MAX17040_VCELL_MSB);
    118         lsb = max17040_read_reg(client, MAX17040_VCELL_LSB);
    119 
    120         chip->vcell = (msb << 4) + (lsb >> 4);
    121 }
    122 
    123 static void max17040_get_soc(struct i2c_client *client)
    124 {
    125         struct max17040_chip *chip = i2c_get_clientdata(client);
    126         u8 msb;
    127         u8 lsb;
    128 
    129         msb = max17040_read_reg(client, MAX17040_SOC_MSB);
    130         lsb = max17040_read_reg(client, MAX17040_SOC_LSB);
    131 
    132         chip->soc = msb;
    133 }
    134
    THX.

  2. #2
    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

  3. #3
    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.

  4. #4
    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 : 1

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