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 } //----------------------------------------------------------------------------------------------------------------------------------------// //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
上一篇:MSP430直流电机控制以及测速+仿真
下一篇:基于MSP430的电池电压检测仿真
推荐阅读最新更新时间:2024-11-18 15:18
设计资源 培训 开发板 精华推荐
- LTM8029 的典型应用 - 具有 5uA 静态电流的 36VIN、600mA 降压模块转换器
- IP5328P 充电宝【已验证】
- PSoC5LP、U-MoBo ExM PsoC5LP 基于赛普拉斯 PSoC CY8C5868AXI-LP035 MCU
- LT6656AIDC-1.25、1.25V 低功率精密高压电源监视器的典型应用
- 使用 STMicroelectronics 的 TS4601BEIJT 的参考设计
- 可调版本使能600mA CMOS LDO稳压器的典型应用
- LTC4419CMSE 高效备用电源的典型应用电路
- RGB灯板(已经测试,放心打板)
- LTC1092、两线、700V 隔离和供电的 10 位数据采集系统
- 使用 NXP Semiconductors 的 MCIMX6Q6AVT10AC 的参考设计