4 byte in a real...

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
piort
Posts: 1379
Joined: 28 Dec 2005 16:42
Location: Laval,Québec,Canada,Earth... :-)
Contact:

4 byte in a real...

#1 Post by piort » 11 Jun 2011 20:07

Hi
I explore the MMB MX4 and want make some write-read operation on the EEPROM 24AA01 (12C).
I want write a real variable (in fact is ADC result) in EEPROM and be able to read back. For the write operation i have use the "in line" function lo,hi,higher and highest but for read back, those function dosent exist. Normally, with 8 bit PIC, i use the ORG trick (4 byte var sharing the same memory space than a real var) but i cant use it with a 32 bit memory PIC... so i have try this :

Code: Select all

 function EEPROM_24AA01_Read(EEAddr : byte) : byte; // adapted from example for lv-P32MX v6
  begin
    I2C1_Start();              // issue I2C start signal
    I2C1_Write(0xA0);          // send byte via I2C  (device address + W)
    I2C1_Write(EEAddr);         // send byte (data address)
    I2C1_Restart();            // issue I2C signal repeated start
    I2C1_Write(0xA1);          // send byte (device address + R)
    result := I2C1_Read(1);     // Read the data (NO acknowledge)
    I2C1_Stop();
    delay_ms(5);              // small delay between read action if serial
  end;

procedure B_read_eepromClick();
var tempo2 : real;
var temp_byte : byte ;
begin
  for i := 3 downto 0 do // real = 4 byte = 4 adress
   case i of     // operation on bit to transfert the 4 bytes in one real
   3 :  
    begin // highest
    temp_byte := EEPROM_24AA01_Read(i);
      for j := 31 downto 24 do
          begin
          kk := j - 24;
          tempo2.j := temp_byte.kk ; <<<<-----compiler error msg....
          end;
    end;
   2 :
   begin   //higher
    temp_byte := EEPROM_24AA01_Read(i);
      for j := 23 downto 16 do
         begin
         kk := j - 16
         tempo2.j := temp_byte.kk ;
         end;
    end;
   1:
   begin    // hi
    temp_byte := EEPROM_24AA01_Read(i);
      for j := 15 downto 8 do
         begin
         kk : j - 8
         tempo2.j := temp_byte.kk ;
         end;
    end;
   0:
   begin  //lo
    temp_byte := EEPROM_24AA01_Read(i);
      for j := 7 downto 0 do
          tempo2.j := temp_byte.j ;
    end;
   
   end; // end case
end;
Maybe isnt the best way to do it, but at least that look like logical but the compiler say :

Code: Select all

129 341 Operator "shl" not applicable to these operands "1" temp_sensor_events_code.mpas
Someone have a idea why the compiler say that ? Or someone know a better way to do it ?

Thx for any hlp ;-)

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: 4 byte in a real...

#2 Post by janni » 11 Jun 2011 22:50

piort wrote:I want write a real variable (in fact is ADC result) in EEPROM and be able to read back. For the write operation i have use the "in line" function lo,hi,higher and highest but for read back, those function dosent exist.
Actually, one may use these operators both ways:

Code: Select all

byte_var:=Lo(real_var);
Lo(real_var):=byte_var;
Normally, with 8 bit PIC, i use the ORG trick (4 byte var sharing the same memory space than a real var) but i cant use it with a 32 bit memory PIC...
Yes, you can:

Code: Select all

var  x:real;
     arr:array[4] of byte at x;

arr[0]:=7; // equivalent to Lo(x):=7;

piort
Posts: 1379
Joined: 28 Dec 2005 16:42
Location: Laval,Québec,Canada,Earth... :-)
Contact:

Re: 4 byte in a real...

#3 Post by piort » 12 Jun 2011 01:57

Thx Janni, you make my day ;-)

Post Reply

Return to “mikroPascal PRO for PIC32 General”