|
硬件:
1、單片機(jī)開發(fā)板
2、紅外遙控器(模擬人體發(fā)出紅外光)
3、壓力傳感器
4、LCD1602液晶顯示
軟件:
1、keil4
2、stc-isp
使用方法:
上電初始狀態(tài)液晶顯示NO PERSON 當(dāng)在壓力傳感器放上一部手機(jī)時(shí)(我用的6sp)如果紅外遙控器不發(fā)出紅外光則液晶仍然顯示NO PERSON 反之則顯示CHILD(小孩)如果增加一部手機(jī)則顯示ADULT(大人)如果撤銷壓力傳感器的所有物體則顯示NO PERSON 此時(shí)如果重新放置物品在紅外遙控器發(fā)出紅外光的情況下屏幕仍然顯示NO PERSON
求大佬幫忙解讀程序。。。拜托拜托了。。。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.png (24.78 KB, 下載次數(shù): 50)
下載附件
2019-12-29 15:42 上傳
單片機(jī)源程序如下:
- #include "reg52.h"
- #include "lcd1602.h"
- #include "ds18b20.h"
- #include "i2c.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define GapValue 429.5
- sbit led = P1^2;
- sbit LED = P1^0;
- unsigned int qupi=0;
- unsigned long weight = 0;
- bit weight_flag = 0;
- bit temp_flag = 0;
- bit no_person = 0;
- uchar IrValue[6];
- uchar Time;
- uint temp;
- //void delay(uint n)
- //{
- // uint j;
- // for(j=0;j<n;j++)
- // {
- // _nop_();
- // }
- //}
- void init()
- {
- Write_Cmd(0x38); //設(shè)置16*2顯示
- Write_Cmd(0x0c); //顯示地址
- Write_Cmd(0x06);//地址指針移位命令
- Write_Cmd(0x01);////清屏
- TMOD|=0x01;//設(shè)置定時(shí)器0工作模式1
- TH0=(65536-50000)/256;//定時(shí)器裝初值
- TL0=(65536-50000)%256;
- EA=1; //開總中斷
- ET0=1; //開定時(shí)器0中斷
- TR0=1; //啟動(dòng)定時(shí)器0
- }
- void Get_temp()
- {
- uchar L,M; //存儲(chǔ)溫度的高八位和低八位
- ds_init();//初始化DS18B20
- dsWait();
- write_byte(0xcc);//發(fā)送跳躍ROM指令
- write_byte(0x44);//發(fā)送溫度轉(zhuǎn)換指令
- ds_init();//初始化DS18B20
- dsWait();
- write_byte(0xcc);//發(fā)送跳躍ROM指令
- write_byte(0xbe);//讀取DS18B20暫存器值
- L = read_byte();//讀取溫度第八位
- M = read_byte();//讀取溫度高八位
- temp = M;
- temp <<= 8;
- temp |= L;
- temp = temp * 0.0625 + 0.5;//temp是16位數(shù)據(jù)其二進(jìn)制每增加一那么它的十進(jìn)制就增加1/16=0.0625,用temp乘以0.0625就可以得到其十進(jìn)制數(shù)是多少,加0.5是為了四舍五入
- //write_weight(13,temp);
- }
- void main()
- {
- init();
- while(1)
- {
- if(temp_flag)
- {
- temp_flag = 0;
- Get_temp();
- if(temp > 35&&temp < 39)
- {
- no_person = 1;
- }
- else
- {
- no_person = 0;
- Write_Cmd(0x01); //清屏
- write_string(1,0,"NO PERSON");
-
- }
- }
-
- if(weight_flag)
- {
- weight_flag = 0;
- weight = ADC_read(0x03);
- // write_weight(1,weight);
- if(no_person)
- {
- if(weight<85||weight>250)
- {
- Write_Cmd(0x01); //清屏
- write_string(1,0,"NO PERSON");
- // write_weight(1,weight);
- no_person = 0;
- break;
- }
- if(weight>85&&weight<170)
- {
- Write_Cmd(0x01); //清屏
- write_string(1,0,"CHILD");
- // write_weight(1,weight);
- }
- if(weight>170&&weight<250)
- {
- Write_Cmd(0x01); //清屏
- write_string(1,0,"ADULT");
- // write_weight(1,weight);
- }
- }
- else
- {
- Write_Cmd(0x01); //清屏
- write_string(1,0,"NO PERSON");
- }
- }
- }
- }
- void timer0() interrupt 1
- {
- static uchar weight_count = 0,temp_count = 0;
- weight_count++;
- temp_count++;
- if(weight_count == 10)
- {
- weight_count = 0;
- weight_flag = 1;
- }
- if(temp_count == 10)
- {
- temp_count = 0;
- temp_flag = 1;
- }
- }
復(fù)制代碼- #include "reg52.h"
- #include "Hx711.h"
- #include "lcd1602.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define GapValue 429.5
- sbit led = P2^4;
- sbit IRIN=P3^2;
- unsigned int qupi=0;
- unsigned long weight = 0;
- bit weight_flag = 0;
- bit temp_flag = 0;
- bit no_person = 0;
- uchar IrValue[6];
- uchar Time;
- uint temp;
- void delay(uint n)
- {
- uint j;
- for(j=0;j<n;j++)
- {
- _nop_();
- }
- }
- void init()
- {
- Write_Cmd(0x38); //設(shè)置16*2顯示
- Write_Cmd(0x0c); //顯示地址
- Write_Cmd(0x06);//地址指針移位命令
- Write_Cmd(0x01);////清屏
- TMOD|=0x01;//設(shè)置定時(shí)器0工作模式1
- TH0=(65536-50000)/256;//定時(shí)器裝初值
- TL0=(65536-50000)%256;
- EA=1; //開總中斷
- ET0=1; //開定時(shí)器0中斷
- TR0=1; //啟動(dòng)定時(shí)器0
- IT0=1;//下降沿觸發(fā)
- EX0=1;//打開中斷0允許
- IRIN=1;//初始化端口
- }
- void Get_Weight()
- {
- weight = HX711_Read();
-
- weight = (unsigned int)((float)weight*10/GapValue)-qupi; //計(jì)算實(shí)物的實(shí)際重量
- }
- void main()
- {
- init();
- while(1)
- {
- if(temp_flag)
- {
- temp_flag = 0;
- if(IrValue[2] == 0)
- {
- no_person = 0;
- Write_Cmd(0x01); //清屏
- write_string(1,0,"NO PERSON");
- }
- else
- {
- no_person = 1;
- }
- }
-
- if(weight_flag)
- {
- weight_flag = 0;
- Get_Weight();
- // write_weight(1,weight);
- if(no_person)
- {
- if(weight<1000||weight>5000)
- {
- Write_Cmd(0x01); //清屏
- write_string(1,0,"NO PERSON");
- // write_weight(1,weight);
- no_person = 0;
- break;
- }
- if(weight>1000&&weight<2000)
- {
- Write_Cmd(0x01); //清屏
- write_string(1,0,"CHILD");
- // write_weight(1,weight);
- }
- if(weight>2000&&weight<4000)
- {
- Write_Cmd(0x01); //清屏
- write_string(1,0,"ADULT");
- // write_weight(1,weight);
- }
- }
- else
- {
- Write_Cmd(0x01); //清屏
- write_string(1,0,"NO PERSON");
- }
- }
- }
- }
- void timer0() interrupt 1
- {
- static uchar weight_count = 0,temp_count = 0;
- weight_count++;
- temp_count++;
- if(weight_count == 10)
- {
- weight_count = 0;
- weight_flag = 1;
- }
- if(temp_count == 10)
- {
- temp_count = 0;
- temp_flag = 1;
- }
- }
- void ReadIr() interrupt 0
- {
- uchar j,k;
- uint err;
- Time=0;
- delay(700); //7ms
- if(IRIN==0) //確認(rèn)是否真的接收到正確的信號(hào)
- {
-
- err=1000; //1000*10us=10ms,超過說明接收到錯(cuò)誤的信號(hào)
- /*當(dāng)兩個(gè)條件都為真是循環(huán),如果有一個(gè)條件為假的時(shí)候跳出循環(huán),免得程序出錯(cuò)的時(shí)
- 侯,程序死在這里*/
- while((IRIN==0)&&(err>0)) //等待前面9ms的低電平過去
- {
- delay(1);
- err--;
- }
- if(IRIN==1) //如果正確等到9ms低電平
- {
- err=500;
- while((IRIN==1)&&(err>0)) //等待4.5ms的起始高電平過去
- {
- delay(1);
- err--;
- }
- for(k=0;k<4;k++) //共有4組數(shù)據(jù)
- {
- for(j=0;j<8;j++) //接收一組數(shù)據(jù)
- {
- err=60;
- while((IRIN==0)&&(err>0))//等待信號(hào)前面的560us低電平過去
- {
- delay(1);
- err--;
- }
- err=500;
- while((IRIN==1)&&(err>0)) //計(jì)算高電平的時(shí)間長(zhǎng)度。
- {
- delay(10); //0.1ms
- Time++;
- err--;
- if(Time>30)
- {
- return; //認(rèn)定通信失敗強(qiáng)制退出
- }
- }
- IrValue[k]>>=1; //k表示第幾組數(shù)據(jù)
- if(Time>=8)
- //如果大于0.8ms
- //如果高電平出現(xiàn)大于565us,那么是1
- {
- IrValue[k]|=0x80;
- }
- Time=0; //用完時(shí)間要重新賦值
- }
- }
- }
- if(IrValue[2]!=~IrValue[3])
- {
- return;
- }
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
汽車座椅有無(wú)人狀態(tài)監(jiān)測(cè).zip
(268.85 KB, 下載次數(shù): 24)
2019-12-27 09:15 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|