無(wú)線測(cè)溫裝置
液晶12864是并口帶中文字庫(kù)的。單片機(jī)型號(hào)是STC89C52 晶振11.0592MHz Keil軟件是Keil uVision4 修改環(huán)境溫度和目標(biāo)溫度校準(zhǔn)方法: (1) 在12864.c程序中修改液晶和你的單片機(jī)開發(fā)板相對(duì)應(yīng) file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.gif (2) 修改環(huán)境溫度和目標(biāo)溫度校準(zhǔn)值 在90614.c程序中更改OffSetValue(環(huán)境溫度校準(zhǔn))和OffSetValue2(目標(biāo)溫度校準(zhǔn))的值。如果測(cè)量的溫度比實(shí)際的溫度高了,那校準(zhǔn)值要為負(fù)數(shù),如想把校準(zhǔn)值降低2.1度就寫-21 file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image005.gif
下面是部分源碼預(yù)覽:
- #include<reg52.h>
- #include <intrins.h>
- #include <stdio.h>
- #include"math.h"
- #define PAUSE_INT EA=0;
- #define START_INT EA=1;
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- ulong OffSetValue=-20;//環(huán)境溫度校準(zhǔn)值,假如你測(cè)量
- //的溫度比實(shí)際的偏高了,這個(gè)
- //值就要用負(fù)數(shù),如-20,就是減少2度
- ulong OffSetValue2=0; //目標(biāo)溫度校準(zhǔn)值,修改方法同上
- ulong Temperature=0,Temperature2=0;
- unsigned char date;
- unsigned char time_buf2[7];//定義接收四個(gè)字節(jié)非接觸式紅外溫度數(shù)組
- unsigned char Temp1[6];
- unsigned char Temp2[6];
- uchar a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0,a8=0,a9=0,a10=0,a11=0,a12=0,a13=0,a14=0,a15=0,a16=0;
- void initial_LCD();
- void DispalyLcd();
- void LCD_Data(uchar LCDbyte );
- void WriteCommand(uchar a);
- void LCD_PutString(unsigned char x,unsigned char y,uchar *s);
- void UART_Init();
- unsigned char Receive(void);
- void Send(unsigned char back);
- void send_char_com(uchar ch);
- void send_string_com(uchar *str, uchar strlen);
- void delay1ms(uint z);
- void Init_Timer0(void);
- void main(void)
- {
- initial_LCD(); //初始化LCD12864
- LCD_PutString(0,1,"MXL90614非接觸式");
- LCD_PutString(2,2,"紅外測(cè)溫");
- LCD_PutString(0,3,"目標(biāo)溫度:");
- LCD_PutString(0,4,"環(huán)境溫度:");
- UART_Init();//初始化串口通信
- while(1);
- }
- void UART_Init()
- {
- TMOD|=0x20; //TMOD: timer 1, mode 2, 8-bit reload
- TH1=0xfd; //Baud:9600 fosc="11.0592"MHz
- TL1=0xfd;
- SCON|=0x50; //SCON: serail mode 1, 8-bit UART, enable ucvr
- TI = 0;
- RI = 0;
- TR1=1;// timer 1 run //啟動(dòng)定時(shí)器1
- ES=1; //Enable Serial Interrupt 打開中斷
- EA=1; //打開所有中斷
- }
- //串行中斷服務(wù)程序,讀取非接觸式紅外測(cè)溫溫度4個(gè)字節(jié)
- void UART_SER (void) interrupt 4
- {
- unsigned char Temp; //定義臨時(shí)變量
- unsigned int a,b,c,d,e,f,g,h;
- unsigned char i;
- if(RI) //判斷是接收中斷產(chǎn)生
- {
- RI=0; //標(biāo)志位清零
- Temp=SBUF; //讀入緩沖區(qū)的值
- time_buf2[i]=Temp;
- i++;
- if(i==8) //連續(xù)接收4個(gè)字符信息
- {
- i=0;
- a1=(unsigned int)(time_buf2[0]/16);a2=(unsigned int)(time_buf2[0]%16);//串口接收第1個(gè)16進(jìn)制溫度字節(jié),并且把個(gè)位和十位分離,只取有效數(shù)據(jù)個(gè)位。
- a3=(unsigned int)(time_buf2[1]/16);a4=(unsigned int)(time_buf2[1]%16);//串口接收第2個(gè)16進(jìn)制溫度字節(jié),并且把個(gè)位和十位分離,只取有效數(shù)據(jù)個(gè)位。
- a5=(unsigned int)(time_buf2[2]/16);a6=(unsigned int)(time_buf2[2]%16);//串口接收第3個(gè)16進(jìn)制溫度字節(jié),并且把個(gè)位和十位分離,只取有效數(shù)據(jù)個(gè)位。
- a7=(unsigned int)(time_buf2[3]/16);a8=(unsigned int)(time_buf2[3]%16);//串口接收第4個(gè)16進(jìn)制溫度字節(jié),并且把個(gè)位和十位分離,只取有效數(shù)據(jù)個(gè)位。
-
- a9=(unsigned int)(time_buf2[4]/16);a10=(unsigned int)(time_buf2[4]%16);//串口接收第5個(gè)16進(jìn)制溫度字節(jié),并且把個(gè)位和十位分離,只取有效數(shù)據(jù)個(gè)位。
- a11=(unsigned int)(time_buf2[5]/16);a12=(unsigned int)(time_buf2[5]%16);//串口接收第6個(gè)16進(jìn)制溫度字節(jié),并且把個(gè)位和十位分離,只取有效數(shù)據(jù)個(gè)位。
- a13=(unsigned int)(time_buf2[6]/16);a14=(unsigned int)(time_buf2[6]%16);//串口接收第7個(gè)16進(jìn)制溫度字節(jié),并且把個(gè)位和十位分離,只取有效數(shù)據(jù)個(gè)位。
- a15=(unsigned int)(time_buf2[7]/16);a16=(unsigned int)(time_buf2[7]%16);//串口接收第8個(gè)16進(jìn)制溫度字節(jié),并且把個(gè)位和十位分離,只取有效數(shù)據(jù)個(gè)位。
-
- Temperature=a2*1000+a4*100+a6*10+a8+OffSetValue; //將分離開的溫度數(shù)據(jù)組合成一個(gè)數(shù)據(jù),OffSetValue是校準(zhǔn)值
- //如果測(cè)到的溫度比實(shí)際溫度高,則OffSetValue要減少,反正則增加
-
-
- Temperature2=a10*1000+a12*100+a14*10+a16+OffSetValue2; //將分離開的溫度數(shù)據(jù)組合成一個(gè)數(shù)據(jù),OffSetValue2是校準(zhǔn)值
- //如果測(cè)到的溫度比實(shí)際溫度高,則OffSetValue2要減少,反正則增加
-
-
- a=Temperature/1000;
- b=(Temperature%1000)/100;
- c=(Temperature%100)/10;
- d= Temperature%10;
- Temp1[0]=a+0x30;
- Temp1[1]=b+0x30;
- Temp1[2]=c+0x30;
- Temp1[3]='.';
- Temp1[4]=d+0x30;
- LCD_PutString(5,3,Temp1); //液晶顯示目標(biāo)溫度
-
-
- e=Temperature2/1000;
- f=(Temperature2%1000)/100;
- g=(Temperature2%100)/10;
- h= Temperature2%10;
- Temp2[0]=e+0x30;
- Temp2[1]=f+0x30;
- Temp2[2]=g+0x30;
- Temp2[3]='.';
- Temp2[4]=h+0x30;
- LCD_PutString(5,4,Temp2); //液晶顯示環(huán)境溫度
- }
- }
- if(TI) //如果是發(fā)送標(biāo)志位,清零
- TI=0;
- }
- void Send(unsigned char back)
- {
- SBUF=back;
- while(TI==0)
- ;
- TI=0;
- }
- unsigned char Receive(void)
- {
- unsigned long i = 10000;
-
- while( RI == 0 )
- {
- i--;
- if( i == 0 ) return -1;//
- }
-
- RI = 0;
- return SBUF;
- }
- //向串口發(fā)送一個(gè)字符
- void send_char_com(uchar ch)
- {
- PAUSE_INT
- SBUF=ch;
- while(TI==0);
- TI=0;
- START_INT
- }
- //
- //向串口發(fā)送一個(gè)字符串,strlen為該字符串長(zhǎng)度
- void send_string_com(uchar *str, uchar strlen)
- {
- uchar k=0;
- do
- {
- send_char_com(*(str+k));
- k=k+1;
- } while(k<strlen);
- }
- void delay1ms(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
復(fù)制代碼
|