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-18 15:18

基于TTS模块的语音播报红外数字测温计设计
引言 由于现代医学发展的需要,在某些场合传统的温度计已经满足不了快速而又准确的测温要求。而红外测温技术打破了传统测温模式,兼具响应速度快、测量精度高、测量范围广等特点,为测量人体体温提供了一种快捷、非接触的测量手段,广泛应用于密集人群的体温排查,例如在车站和机场等人口密度较大的地方进行人体温度检测。此外,红外测温在诸如机车轴温巡检等类似需要非接触测温的工业领域也有着良好的应用前景。本文给出一种基于红外测温模块及TTS语音模块的语音播报非接触式红外测温计设计方案。 硬件系统设计 系统总体结构 非接触式语音红外数字测温计硬件电路主要包括单片机控制模块、红外测温模块、语音合成模块、LCD显示模块,按键模块、电源模块等。图
[电源管理]
基于TTS<font color='red'>模块</font>的语音播报<font color='red'>红外</font>数字<font color='red'>测温</font>计设计
小广播
设计资源 培训 开发板 精华推荐

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

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

换一换 更多 相关热搜器件

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

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