MLX90614红外测温模块程序

发布者:CreativeMind最新更新时间:2020-07-13 来源: 51hei关键字:MLX90614  红外测温模块 手机看文章 扫描二维码
随时随地手机看文章

MLX90614ESF+传感器+红外非接触温度测量传感器模块程序源代码,用msp430的单片机


电路原理图如下:

单片机源程序如下:

//*****************************************************************************

//   MSP430x42x0 Demo - SD16_A, LCD

//*****************************************************************************


//MLX90614 Pin Config


//GND-----6.0.....I/O supply the MLX90614

//SDA-----6.1

//SCL-----6.2

//POW-----6.3.....I/O supply the MLX90614


#include 


void LCD_CHECK(void);

void Init_LCD(void);

unsigned int A1,A2,A3,A4,A5;


#define a 0x01

#define b 0x02

#define c 0x04

#define d 0x80

#define e 0x40

#define f 0x10

#define g 0x20

#define h 0x08


const char char_gen[] = {                   // definitions for digits

  a+b+c+d+e+f,                              // Displays "0"

  b+c,                                      // Displays "1"

  a+b+d+e+g,                                // Displays "2"

  a+b+c+d+g,                                // Displays "3"

  b+c+f+g,                                  // Displays "4"

  a+c+d+f+g,                                // Displays "5"

  a+c+d+e+f+g,                              // Displays "6"

  a+b+c,                                    // Displays "7"

  a+b+c+d+e+f+g,                            // Displays "8"

  a+b+c+d+f+g,                              // Displays "9"

};


//*************************************************************

//*************************************************************


void Delay(unsigned int n);

void start_bit();

void stop_bit();

void send_bit(unsigned char bit_out);

unsigned char receive_bit();

unsigned char slave_ack();

void TX_byte(unsigned char TX_buffer);

unsigned char RX_byte(unsigned char ack_nack);

unsigned char PEC_cal(unsigned char pec[],int n);

unsigned long int MEM_READ( unsigned char slave_addR, unsigned char cmdR );                                                

void CALTEMP(unsigned long int TEMP);


void mlx90614_POW_0() { P6OUT &= ~0x08;}  // define P6.3 ---> POW

void mlx90614_POW_1() { P6OUT |= 0x08;}


void mlx90614_GND_0() { P6OUT &= ~0x01;}  // define P6.0 ---> GND

void mlx90614_GND_1() { P6OUT |= 0x01;}


void mlx90614_SCL_0() { P6OUT &= ~0x04;}  // define P6.2 ---> SCL

void mlx90614_SCL_1() { P6OUT |= 0x04;}


void mlx90614_SDA_0() { P6OUT &= ~0x02;}  // define P6.1 ---> SDA

void mlx90614_SDA_1() { P6OUT |= 0x02;}



#define _SDA_OUTPUT P6DIR |=0x02; //Set SDA as Output

#define _SDA_INPUT P6DIR &=~0x02; //Set SDA as Input


#define SDA ((P6IN & BIT1)>>1) //define input pin


//*************************************************************

//*************************************************************


void Delay(unsigned int n)

{

  unsigned int i;

  for(i=0;i  _NOP();

}


//----------------------------------------------------------------------------------------------------------------------------------------//

//Name: start_bit

//----------------------------------------------------------------------------------------------------------------------------------------//

void start_bit()

{

  _SDA_OUTPUT; //Set SDA as output

  Delay(5);

  mlx90614_SDA_1();

  //Delay(30);

  mlx90614_SCL_1();

  

  Delay(30);

  mlx90614_SDA_0();

  Delay(30);

  mlx90614_SCL_0();

  Delay(30);

  

}


//----------------------------------------------------------------------------------------------------------------------------------------//

//Name: stop_bit

//----------------------------------------------------------------------------------------------------------------------------------------//

void stop_bit()

{

  _SDA_OUTPUT; //Set SDA as output

  Delay(1);

  //mlx90614_SCL_0();

  mlx90614_SDA_0();

  Delay(2);

  mlx90614_SCL_1();

  Delay(2);

  mlx90614_SDA_1();

}


//----------------------------------------------------------------------------------------------------------------------------------------//

//Name: send_bit

//----------------------------------------------------------------------------------------------------------------------------------------//

void send_bit(unsigned char bit_out)

{

  _SDA_OUTPUT; //Set SDA as output

  Delay(5);

  if(bit_out==0) {mlx90614_SDA_0();}else{mlx90614_SDA_1();}

  Delay(5);

  mlx90614_SCL_1();

  Delay(30);

  mlx90614_SCL_0();

  Delay(30);

}


//----------------------------------------------------------------------------------------------------------------------------------------//

//Name: receive_bit

//----------------------------------------------------------------------------------------------------------------------------------------//

unsigned char receive_bit()

{

  unsigned char bit_in;

  _SDA_INPUT; //Set SDA as input

  Delay(5);

  mlx90614_SCL_1();

  Delay(5);

  if(SDA==1){bit_in=1;}else{bit_in=0;}

  Delay(10);

  mlx90614_SCL_0();

  Delay(30);

  return bit_in;

}


//----------------------------------------------------------------------------------------------------------------------------------------//

//Name: slave_ack

//1 - ACK

//0 -NACK

//----------------------------------------------------------------------------------------------------------------------------------------//

unsigned char slave_ack()

{

  unsigned char ack;

  ack=0;

  _SDA_INPUT; //Set SDA as input

  Delay(5);

  mlx90614_SCL_1();

  Delay(10);

  if(SDA==1){ack=0;}else{ack=1;}

  Delay(10);

  mlx90614_SCL_0();

  Delay(30);

  return ack;

}


//----------------------------------------------------------------------------------------------------------------------------------------//

//Name: TX_byte

//----------------------------------------------------------------------------------------------------------------------------------------//

void TX_byte(unsigned char TX_buffer)

{

  unsigned char Bit_counter;

  unsigned char bit_out;

  for(Bit_counter=8;Bit_counter;Bit_counter--)

  {

    if(TX_buffer&0x80){bit_out=1;}else{bit_out=0;}

    send_bit(bit_out); //Send the current bit on SMBus

    TX_buffer<<=1; //Get next bit to check

  }

}


//----------------------------------------------------------------------------------------------------------------------------------------//

//Name: RX_byte

//Parameters: unsigned char ack_nack (acknowledgment bit)

//0 - Master device sends ACK

//1 - Master device sends NACK

//----------------------------------------------------------------------------------------------------------------------------------------//

unsigned char RX_byte(unsigned char ack_nack)

{

        unsigned char RX_buffer;

        unsigned char Bit_counter;

        for(Bit_counter=8;Bit_counter;Bit_counter--)

        {

         if(receive_bit()==1) //Read a bit from the SDA line

          {

           RX_buffer<<=1; //If the bit is HIGH save 1 in RX_buffer

           RX_buffer|=0x01;

          }

         else //If the bit is LOW save 0 in RX_buffer

          {

           RX_buffer<<=1;

           RX_buffer&=0xfe;

          }

        }

        send_bit(ack_nack); //Sends acknowledgment bit

        return RX_buffer;

}



//----------------------------------------------------------------------------------------------------------------------------------------//

//CALCULATE THE PEC PACKET

//----------------------------------------------------------------------------------------------------------------------------------------//

unsigned char PEC_cal(unsigned char pec[],int n)

{

    unsigned char crc[6];

    unsigned char Bitposition=47;

    unsigned char shift;

    unsigned char i;

    unsigned char j;

    unsigned char temp;

  do{

    crc[5]=0; //Load CRC value 0x000000000107

    crc[4]=0;

    crc[3]=0;

    crc[2]=0;

    crc[1]=0x01;

    crc[0]=0x07;

    Bitposition=47; //Set maximum bit position at 47

    shift=0;        //Find first 1 in the transmitted bytes

    i=5; //Set highest index (package byte index)

    j=0; //Byte bit index, from lowest

    while((pec[i]&(0x80>>j))==0 && (i>0))

    {

     Bitposition--;

     if(j<7){ j++;}

     else {j=0x00;i--;}

    }//the position of highest "1" bit in Bitposition is calculated

    shift=Bitposition-8; //Get shift value for CRC value

        

[1] [2]
关键字:MLX90614  红外测温模块 引用地址:MLX90614红外测温模块程序

上一篇:MSP430直流电机控制以及测速+仿真
下一篇:基于MSP430的电池电压检测仿真

推荐阅读最新更新时间:2024-11-08 21:31

MLX90601系列红外测温模块的原理及应用
摘要:MLX90601系列模块是一组通用的红外测温模块。在出厂前该模块已进行校验及线性化,精度高、体积小,被测物体温度和环境温度能分双通道输出,并且有多种输出接口,在多种精密设备装置中都有广泛的应用。文中以MLX90601EZA-CAA为例介绍其原理及应用方法。 关键词:MLX90601EZA-CAA;红外测温;PWM;SPI 中图分类号:TP216 文献标识码:B 文章编号:1006-6977(2006)01-0047-04 1 引言 一般来说,测温方式可分为接触式和非接触式,接触式测温只能测量被测物体与测温传感器达到热平衡后的温度,所以响应时间长,且极易受环境温度的影响;而红外测温是根据被测物体的红外辐射能量来
[测试测量]
小广播
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

换一换 更多 相关热搜器件

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved