|
學(xué)校單片機(jī)的課排到下學(xué)期了,沒什么基礎(chǔ) 想請(qǐng)教一下通過DH11采集完環(huán)境濕度后。在這之上加入一個(gè)上位機(jī)來根據(jù)傳過來的數(shù)據(jù)閾值控制風(fēng)扇打開關(guān)閉,具體的思路是怎么樣的呢?
接觸單片機(jī)的時(shí)間短,不太清楚這個(gè)概念,有些無從下手...如果只是讓上位機(jī)進(jìn)行簡(jiǎn)單的控制,用proteus仿真該怎么實(shí)現(xiàn)?
單片機(jī)源程序如下:
- #include"DHT11.h"
- void Delay30us()
- {
- uchar i;
- _nop_();
- i = 12;
- while (--i);
- }
- void Delay40us()
- {
- uchar i;
- _nop_();
- i = 17;
- while (--i);
- }
- void Delay20ms()
- {
- uchar i, j;
- i = 39;
- j = 230;
- do
- {
- while (--j);
- } while (--i);
- }
- void Init()
- {
- dht=1;
- dht=0;
- Delay20ms();
- dht=1;
- Delay30us();
- }
- uchar Read()
- {
- uchar dat=0,detect=0;
- uchar i;
- for(i=0;i<8;i++)
- {
- while(!dht);
- Delay40us();
- if(dht==1)
- {
- detect=1;
- }
- else
- {
- detect=0;
- }
- dat<<=1;
- dat|=detect;
- while(dht);
- }
- return dat;
- }
復(fù)制代碼
|
|