我之前做的醫(yī)用非接觸式溫度監(jiān)測
使用的MLX90614傳感器作為檢測芯片;
STC15W408作為主控芯片;
下面是我的程序源碼;
電路原理圖如下:
TIM截圖20190325105545.jpg (43.7 KB, 下載次數: 82)
下載附件
原理圖
2019-3-25 10:56 上傳
單片機源程序如下:
- //**********************************************************************************************
- // BASIC INFORMATION ABOUT THIS PROGRAM
- //***********************************************************************************************
- //File name: main.c
- //Version: 01.00
- //Company:
- //Details: SMBus comunication with MLX90614 using 89C52
- // Language C: uVision4 compiler
- // Fosc=24MHz, Tcy=0.5us,Pull-up Resister 2k
- //Author:
- //*****************************************************************************************************************
- // HEADER FILES
- //*****************************************************************************************************************
- //#include <reg52.h>
- #include "main.h"
- #include "delay.h"
- unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,};
- unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,};
- sbit PP7=P1^0;
- sbit PP6=P3^6;
- sbit PP5=P3^3;
- sbit PP4=P1^4;
- sbit PP3=P1^1;
- sbit PP2=P3^7;
- sbit PP1=P3^2;
- sbit PP0=P1^3; //a
- sbit led=P5^5;
- void Data(unsigned char da)
- {
- PP7=(bit)(da&0x80);
- PP6=(bit)(da&0x40);
- PP5=(bit)(da&0x20);
- PP4=(bit)(da&0x10);
- PP3=(bit)(da&0x08);
- PP2=(bit)(da&0x04);
- PP1=(bit)(da&0x02);
- PP0=(bit)(da&0x01);
- }
- //*****************************************************************************************************************
- // FUNCTION'S DEFINITIONS
- //*****************************************************************************************************************
- void MCUinit(void)
- {
- //IO setting-up
- // P1=0xFF; //All chanels are digital I/O
- // P3=0xFF;
- //P2M0=0x00;P2M1=0xff;
- //SMBus setting-up
- SDA = mSDA_HIGH; //The bus is in idle state
- SCL = mSCL_HIGH; //SDA and SCL are in high level from pull up resitors
- }//End of init()
-
- //-----------------------------------------------------------------------------------------------------------------
- unsigned int MemRead(unsigned char uSlaveAddress,unsigned char UC_command)
- {
- unsigned int StData; // Data storage (DataH:DataL)
- unsigned char Pec; // PEC byte storage
- unsigned char DataL; // Low data byte storage
- unsigned char DataH; // High data byte storage
- unsigned char arr[6]; // Buffer for the sent bytes
- unsigned char PecReg; // Calculated PEC byte storage
- unsigned char ErrorCounter; // Defines the number of the attempts for communication with MLX90614
- unsigned char SLA;
- ErrorCounter=0x0F; // Initialising of ErrorCounter
- SLA = uSlaveAddress<<1;
- do{
- repeat:
- STOP_bit(); //If slave send NACK stop comunication
- --ErrorCounter; //Pre-decrement ErrorCounter
- if(!ErrorCounter){ //ErrorCounter=0?
- break; //Yes,go out from do-while{}
- }
- START_bit(); //Start condition
-
- if(TX_byte(SLA)){ //Send SlaveAddress
- goto repeat; //Repeat comunication again
- }
- if(TX_byte(UC_command)){ //Send command
- goto repeat; //Repeat comunication again
- }
- START_bit(); //Repeated Start condition
-
- if(TX_byte(SLA+1)){ //Send SlaveAddress
- goto repeat; //Repeat comunication again
- }
- DataL=RX_byte(ACK); //Read low data,master must send ACK
- DataH=RX_byte(ACK); //Read high data,master must send ACK
- Pec=RX_byte(NACK); //Read PEC byte, master must send NACK
- STOP_bit(); //Stop condition
-
-
- arr[5]=SLA; //
- arr[4]=UC_command; //
- arr[3]=SLA+1; //Load array arr
- arr[2]=DataL; //
- arr[1]=DataH; //
- arr[0]=0; //
- PecReg=PEC_calculation(arr);//Calculate CRC
-
- }while(PecReg != Pec); //If received and calculated CRC are equal go out from do-while{}
-
- StData = DataH*256+DataL; //改用這種方法時正確
-
- return StData;
- }
- /**
- //---------------------------------------------------------------------------------------------
- void SendRequest(void)
- {
- SCL = mSCL_LOW; //SCL 1 ____________|<-----80ms------->|______________
- delay(DEL80ms); // 0 |__________________|
- SCL = mSCL_HIGH;
- }
- //---------------------------------------------------------------------------------------------
- void DummyCommand(unsigned char byte)
- {
- START_bit(); //Start condition
- TX_byte(byte); //Send Slave Address or whatever,no need ACK checking
- STOP_bit(); //Stop condition
- }
- //---------------------------------------------------------------------------------------------
- **/
- float CalcTemp(unsigned int value)
- {
- float temp;
-
- temp=(value*0.02)-273.15;
-
- return temp;
- }
- void Display (unsigned int tempreture)
- {
-
- // unsigned char numb1; //b
- unsigned char numb2; //s
- unsigned char numb3; //g
- unsigned char numb4;//xiao s
- // numb1=(unsigned char)(tempreture/1000);
- numb2=(unsigned char)((tempreture%1000)/100);
- numb3=(unsigned char)((tempreture%100)/10);
- numb4=(unsigned char)(tempreture%10);
-
- Data(table[numb2]);LED3=0; delay(5);LED3=1;
-
- Data(table1[numb3]);LED2=0; delay(5);LED2=1;
-
-
- Data(table[numb4]);LED1=0; delay(5);LED1=1;
- }
- //*****************************************************************************************************************
- // MAIN PROGRAM
- //*****************************************************************************************************************
- void main(void)
- {
- unsigned char SlaveAddress; //Contains device address
- unsigned char uCommand; //Contains the access command
- unsigned int uData; //Contains data value
- float t; //Contains calculated temperature in degrees Celsius
- unsigned int tt;
- // LCD_Initial(); //LCD initialization
- MCUinit(); //MCU initialization
- SlaveAddress=SA<<1; //Set device address
- uCommand=RAM_Access|RAM_Tobj1; //Form RAM access command + RAM address
-
- // SendRequest(); //Switch to SMBus mode - this is need if module is in PWM mode only
- // DummyCommand(SlaveAddress); //This is need if Request Command is sent even when the module is in SMBus mode
- // delay(DEL200ms); //Wait after POR,Tvalid=0.15s
- delay200ms();
-
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
醫(yī)用溫度檢測-代碼及原理圖.zip
(165.02 KB, 下載次數: 128)
2019-3-25 10:54 上傳
點擊文件名下載附件
10 下載積分: 黑幣 -5
|