I need help please!
I found a code for the ir sensor mlx90614 but this code is for mikropascal and i need it in mikroc because is the compilator that i have and im using a bigpic6
If someone can help with the code for mikroc compiler i appreciate it very much!
The code that i found is this
{******************************************************************************
This program is open source, anyone and everyone can use it for educations or
whatever you like.
This is an attempt to help convert the poorly documented C-Code for the
MLX90614 IR Infared Thermal Sensor by
Melexis 'Microelectronic Integrated Systems'
over to AVR PASCAL and too help explain some of the code and addresses.
by: Robert Underwood
Email: k0ru@arrl.net
Date: April 5, 2011
Source: MikroElektronika mikroPASCAL PRO for AVR MCU
Enjoy!
Any feedback would be greatly appreciated:
===============================================================================}
program MLX90614_ATMega16_v1;
var
ReadStr, MLX_Temp, MLX_FTemp, MLX_CTemp : array[23] of char;
Sensor, MLX_LSB, MLX_MSB, MLX_PEC : Word;
MLX_Calc, MLX_F, MLX_C : Real;
CRC8 : LongInt;
const
SA : Word = 0x0000; // 0x00 calls all on bus, 0x5A is factory default address
DTemp : Word = 0x06; // Object2 Temp $08 Object1 Temp $07 Device Ambient Temp $06
OTemp1 : Word = 0x07; // Ambient Temp is actually the devices own temp
OTemp2 : Word = 0x08;
{ Declarations section }
// LCD module connections
var LCD_RS : sbit at PORTD2_bit;
var LCD_EN : sbit at PORTD3_bit;
var LCD_D4 : sbit at PORTD4_bit;
var LCD_D5 : sbit at PORTD5_bit;
var LCD_D6 : sbit at PORTD6_bit;
var LCD_D7 : sbit at PORTD7_bit;
var LCD_RS_Direction : sbit at DDD2_bit;
var LCD_EN_Direction : sbit at DDD3_bit;
var LCD_D4_Direction : sbit at DDD4_bit;
var LCD_D5_Direction : sbit at DDD5_bit;
var LCD_D6_Direction : sbit at DDD6_bit;
var LCD_D7_Direction : sbit at DDD7_bit;
// End LCD module connections
// ** Performs calculations on CRC to ensure we received a valid reading
Function CalcCRC8(CRC8:byte; v : Byte) : Byte;
var n : byte;
begin
v := v XOR CRC8;
for n:=0 to n<8 do
begin
if (v and 0x80) then v := (v shl 1) XOR 0x07
else v := v shl 1;
end;
Result:=v;
end;
//** Read Scada bus for IR Infared Thermal Temperature Device MLX90614
Procedure MLX_ReadCMD();
begin
Repeat
If Not(TWI_Busy) then TWI_Stop(); // Ensure the Scada is STOPPED!
If Not(TWI_Busy) then TWI_Start(); // Start Read Config Addresses
If Not(TWI_Busy) then TWI_Write((SA * 2) or 0x00); // Write the Slave Address OR with the WRITE CMD of 0x00
If Not(TWI_Busy) then TWI_Write(Sensor); // Write the Sensor Address Object2 Temp $08 Object1 Temp $07 Ambient Temp $06
If Not(TWI_Busy) then TWI_Start(); // Start Temperature Read
If Not(TWI_Busy) then TWI_Write((SA * 2) or 0x01); // Write the Slave Address OR with the Read CMD of 0x01
If Not(TWI_Busy) then MLX_LSB :=TWI_Read(1); // Read the LSB first
If Not(TWI_Busy) then MLX_MSB :=TWI_Read(1); // Read the MSB next
If Not(TWI_Busy) then MLX_PEC :=TWI_Read(0); // Read the PEC (CRC sum for string confirmation calc'ing)
If Not(TWI_Busy) then TWI_Stop(); // Stop Scada
CRC8:=0x00; // Zero out CRC sums and prepare to confirm stream total sum
CRC8:=CalcCRC8(CRC8, (SA * 2)); // Send CRC with Slave Address for WRITE to confirm sumation
CRC8:=CalcCRC8(CRC8, Sensor); // Send CRC with Object Temp Address to confirm sumation
CRC8:=CalcCRC8(CRC8, SA * 2 + 1);// Send CRC with Slave Address for READ to confirm sumation
CRC8:=CalcCRC8(CRC8, MLX_LSB); // Send CRC with Temp LSB to confirm sumation
CRC8:=CalcCRC8(CRC8, MLX_MSB); // Send CRC with Temp MSB to confirm sumation
CRC8:=CalcCRC8(CRC8, MLX_PEC); // Send CRC Sumation to ensure no xfer error on the scada
if Not(CRC8=0) then
begin
LCD_CMD(_LCD_CLEAR);
LCD_Out(1,1,'CRC Checksum');
LCD_Out(2,1,'Check Sensor');
Delay_ms(1000);
LCD_CMD(_LCD_CLEAR);
TWI_Stop(); // Force Stop Scada and try to restart
TWI_Stop(); //
Delay_ms(1000);
end;
Until CRC8=0; // Continue trying to talk to Sensor until CRC8 checksum is good.
//=== Calculate Celsius and Ferinheit Temperature Readings
MLX_Calc:=0x00; // Zero Out MLX Previous Calc Value
MLX_Calc := (MLX_MSB * 256) + MLX_LSB; // Calculate Kelvin Value first
MLX_C:= (MLX_Calc * 0.02) - 273.70; // Convert Kelvin Value to Celsius the number 273.70 is used for compensation 273.15 is spec'd
MLX_F:= ((MLX_C * 9) / 5) + 32; // Convert Celsius Value to Ferinheit Value for us dumb American's
// MLX_F:= (MLX_C * 1. + 32; // Convert Celsius Value to Ferinheit Value for us dumb American's
end;
Function MLX_DigitFormat(Reading:Real): array[23] of char;
var
Temp1, Temp2 : array[23] of char;
Tres, Tiptr : Real;
IntRes, IntIptr : LongInt;
begin
Tres:=modf(Reading, Tiptr);
IntRes:=Integer(Tres*10);
IntIptr:=Integer(TIptr);
IntToStr(IntIptr,Temp1);
Ltrim(temp1);
While length(temp1)<3 do StrAppendPre(' ',temp1);
IntToStr(IntRes,Temp2);
Ltrim(temp2);
ReadStr:=Temp1+'.'+Temp2;
While length(ReadSTr)<5 do StrAppendSuf(ReadStr,' ');
Result:=ReadStr;
end;
begin
{ Main program }
DDRA:= %00000001;
PORTA:=%00000000;
TWI_Init(100000);
Delay_ms(10);
MLX_LSB:=0;
MLX_MSB:=0;
MLX_PEC:=0;
MLX_Temp:='';
MLX_CTemp:='';
MLX_FTemp:='';
LCD_Init();
LCD_CMD(_LCD_CURSOR_OFF);
Delay_ms(10);
LCD_Out(1,1,'MLX90614 IR TEMP');
LCD_Out(2,1,' SENSOR ');
Delay_ms(1000);
LCD_CMD(_LCD_CLEAR);
Delay_ms(10);
Sensor:=OTemp1;
LCD_Out(1,16,'O');
While TRUE do
begin
if (PinA and 1) then
begin
if Sensor=OTemp1 then
begin
Sensor:=DTemp;
LCD_Out(1,16,'D');
end
else
begin
Sensor:=OTemp1;
LCD_Out(1,16,'O');
end;
// Delay_ms(250);
While (PinA and 1) do begin end;
end;
MLX_ReadCmd();
MLX_Temp:=MLX_DigitFormat(MLX_Calc)+'K';
MLX_CTemp:=MLX_DigitFormat(MLX_C)+'C';
MLX_FTemp:=MLX_DigitFormat(MLX_F)+'F';
LCD_Out(1,5,MLX_Temp); // Display Kelvin Temp Reading
LCD_Out(2,1,MLX_FTemp); // Display Ferinheit Temp Reading
LCD_Out(2,10,MLX_CTemp); // Display Celsiur Temp Reading
end;
end.
Tnx for help me!!!
MLX90614
General discussion on mikroC.
Author
Message
Re: MLX90614
#2 Post by filip » 09 Mar 2012 13:56
Hi,
Please, I believe I have answered you here :
http://www.mikroe.com/forum/viewtopic.php?f=13&t=47288
Regards,
Filip.
Please, I believe I have answered you here :
http://www.mikroe.com/forum/viewtopic.php?f=13&t=47288
Regards,
Filip.
Jump to
- NECTO Studio
- ↳ IDE
- ↳ IDE General
- ↳ IDE Beta Testing
- ↳ IDE Wish List
- ↳ ARM AI Compilers
- ↳ mikroC AI for ARM
- ↳ mikroC AI for ARM General
- ↳ mikroC AI for ARM Beta Testing
- ↳ mikroC AI for ARM Wish List
- ↳ PIC AI compilers
- ↳ mikroC AI for PIC
- ↳ mikroC AI for PIC General
- ↳ mikroC AI for PIC Beta Testing
- ↳ mikroC AI for PIC Wish List
- ↳ PIC32 AI Compilers
- ↳ mikroC AI for PIC32
- ↳ mikroC AI for PIC32 General
- ↳ mikroC AI for PIC32 Beta Testing
- ↳ mikroC AI for PIC32 Wish List
- ↳ dsPIC AI Compilers
- ↳ mikroC AI for dsPIC
- ↳ mikroC AI for dsPIC General
- ↳ mikroC AI for dsPIC Beta Testing
- ↳ mikroC AI for dsPIC Wish List
- ↳ AVR AI Compilers
- ↳ mikroC AI for AVR
- ↳ mikroC AI for AVR General
- ↳ mikroC AI for AVR Beta Testing
- ↳ mikroC AI for AVR Wish List
- ↳ Additional Software
- ↳ Visual TFT AI
- ↳ Visual TFT AI General
- ↳ Visual TFT AI Beta Testing
- ↳ Visual TFT AI Wish List
- PRO Compilers
- ↳ PIC PRO Compilers
- ↳ PIC Compilers General
- ↳ mikroC PRO for PIC
- ↳ mikroC PRO for PIC General
- ↳ mikroC PRO for PIC Beta Testing
- ↳ mikroC PRO for PIC Wish List
- ↳ mikroBasic PRO compiler for PIC
- ↳ mikroBasic PRO for PIC General
- ↳ mikroBasic PRO for PIC Beta Testing
- ↳ mikroBasic PRO for PIC Wish List
- ↳ mikroPascal PRO for PIC
- ↳ mikroPascal PRO for PIC General
- ↳ mikroPascal PRO for PIC Beta Testing
- ↳ mikroPascal PRO for PIC Wish List
- ↳ dsPIC PRO Compilers
- ↳ dsPIC Compilers General
- ↳ mikroC PRO for dsPIC30/33 and PIC24
- ↳ mikroC PRO for dsPIC30/33 and PIC24 General
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 General
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 General
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Wish List
- ↳ PIC32 PRO Compilers
- ↳ PIC32 Compilers General
- ↳ mikroC PRO for PIC32
- ↳ mikroC PRO for PIC32 General
- ↳ mikroC PRO for PIC32 Beta Testing
- ↳ mikroC PRO for PIC32 Wish List
- ↳ mikroBasic PRO for PIC32
- ↳ mikroBasic PRO for PIC32 General
- ↳ mikroBasic PRO for PIC32 Beta Testing
- ↳ mikroBasic PRO for PIC32 Wish List
- ↳ mikroPascal PRO for PIC32
- ↳ mikroPascal PRO for PIC32 General
- ↳ mikroPascal PRO for PIC32 Beta Testing
- ↳ mikroPascal PRO for PIC32 Wish List
- ↳ AVR PRO Compilers
- ↳ AVR Compilers General
- ↳ mikroC PRO for AVR
- ↳ mikroC PRO for AVR General
- ↳ mikroC PRO for AVR Beta Testing
- ↳ mikroC PRO for AVR Wish List
- ↳ mikroBasic PRO compiler for AVR
- ↳ mikroBasic PRO for AVR General
- ↳ mikroBasic PRO for AVR Beta Testing
- ↳ mikroBasic PRO for AVR Wish List
- ↳ mikroPascal PRO for AVR
- ↳ mikroPascal PRO for AVR General
- ↳ mikroPascal PRO for AVR Beta Testing
- ↳ mikroPascal PRO for AVR Wish List
- ↳ FT90x PRO Compilers
- ↳ FT90x Compilers General
- ↳ mikroC PRO for FT90x
- ↳ mikroC PRO for FT90x General
- ↳ mikroC PRO for FT90x Beta Testing
- ↳ mikroC PRO for FT90x Wish List
- ↳ mikroBasic PRO compiler for FT90x
- ↳ mikroBasic PRO for FT90x General
- ↳ mikroBasic PRO for FT90x Beta Testing
- ↳ mikroBasic PRO for FT90x Wish List
- ↳ mikroPascal PRO for FT90x
- ↳ mikroPascal PRO for FT90x General
- ↳ mikroPascal PRO for FT90x Beta Testing
- ↳ mikroPascal PRO for FT90x Wish List
- ↳ 8051 PRO Compilers
- ↳ 8051 Compilers General
- ↳ mikroC PRO for 8051
- ↳ mikroC PRO for 8051 General
- ↳ mikroC PRO for 8051 Beta Testing
- ↳ mikroC PRO for 8051 Wish List
- ↳ mikroBasic PRO compiler for 8051
- ↳ mikroBasic PRO for 8051 General
- ↳ mikroBasic PRO for 8051 Beta Testing
- ↳ mikroBasic PRO for 8051 Wish List
- ↳ mikroPascal PRO for 8051
- ↳ mikroPascal PRO for 8051 General
- ↳ mikroPascal PRO for 8051 Beta Testing
- ↳ mikroPascal PRO for 8051 Wish List
- ↳ ARM PRO Compilers
- ↳ ARM Compilers General
- ↳ mikroC PRO for ARM
- ↳ mikroC PRO for ARM General
- ↳ mikroC PRO for ARM Beta Testing
- ↳ mikroC PRO for ARM Wish List
- ↳ mikroBasic PRO for ARM
- ↳ mikroBasic PRO for ARM General
- ↳ mikroBasic PRO for ARM Beta Testing
- ↳ mikroBasic PRO for ARM Wish List
- ↳ mikroPascal PRO for ARM
- ↳ mikroPascal PRO for ARM General
- ↳ mikroPascal PRO for ARM Beta Testing
- ↳ mikroPascal PRO for ARM Wish List
- ↳ Older versions of Compilers
- ↳ Older versions of mikroC Compilers
- ↳ mikroC for PIC
- ↳ mikroC General
- ↳ mikroC Beta Testing
- ↳ mikroC Wish List
- ↳ mikroC for dsPIC30/33 and PIC24
- ↳ mikroC for dsPIC30/33 and PIC24 General
- ↳ mikroC for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC for dsPIC30/33 and PIC24 Wish List
- ↳ RSC-4x mikroC
- ↳ RSC-4x mikroC General
- ↳ RSC-4x mikroC Wish List
- ↳ mikroC Beta testing
- ↳ Older versions of mikroBasic Compilers
- ↳ mikroBasic compiler for PIC
- ↳ mikroBasic General
- ↳ mikroBasic Beta Testing
- ↳ mikroBasic Wish List
- ↳ mikroBasic compiler for dsPIC30/33 and PIC24
- ↳ mikroBasic for dsPIC30/33 and PIC24 General
- ↳ mikroBasic for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroBasic compiler for AVR
- ↳ mikroBasic for AVR General
- ↳ mikroBasic for AVR Wish List
- ↳ mikroBasic Beta testing
- ↳ Older versions of mikroPascal Compilers
- ↳ mikroPascal compiler for PIC
- ↳ mikroPascal FAQ
- ↳ mikroPascal General
- ↳ mikroPascal Beta Testing
- ↳ mikroPascal Wish List
- ↳ mikroPascal Bug List
- ↳ mikroPascal compiler for dsPIC30/33 and PIC24
- ↳ mikroPascal for dsPIC30/33 and PIC24 General
- ↳ mikroPascal for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroPascal compiler for AVR
- ↳ mikroPascal for AVR General
- ↳ mikroPascal for AVR Wish List
- ↳ mikroPascal Beta testing
- ↳ Library Development Discussion
- ↳ Code Requests
- Additional Software
- ↳ Visual TFT Software
- ↳ Visual TFT General
- ↳ Visual TFT Beta Testing
- ↳ Visual TFT Wish List
- ↳ Visual GLCD Software
- ↳ Visual GLCD General
- ↳ Visual GLCD Beta Testing
- ↳ Visual GLCD Wish List
- ↳ Package Manager Software
- ↳ Package Manager General
- ↳ Package Manager Beta Testing
- ↳ Package Manager Wishlist
- ↳ GLCD Font Creator Software
- ↳ SpeakUp Software
- ↳ Timer Calculator
- ↳ CAN Calculator
- ↳ mikroBootloader
- Hardware
- ↳ Development Boards
- ↳ CODEGRIP programmer and debugger
- ↳ Mikromedia
- ↳ mikroProg™ programmer and debugger
- ↳ Development Boards Wishlist
- ↳ Review
- ↳ Click Boards release
- ↳ Hexiwear
- Website & Forums
- ↳ Libstock Discussion
- ↳ Product Announcements
- ↳ Website & Forums General Discussion
- ↳ Website & Forums Wishlist
- ↳ User Projects