软件开发STC15F2K60S2单片机指北针的设计
- 项 目:温、湿度测量程序软件开发STC15F2K60S
- 软件开发单片机:芯片破解STC15F2K60S
- 传感器:DHT11
- 日 期:04.09
- ************************************************/
- #include <stc12c5a60s2.h>
- #include "delay.h"
- #define uint unsigned int
- #define uchar unsigned char
- sbit io = P2^0; //定义数据端口
- uchar data_byte; //定义全局变量
- uchar RH,RL,TH,TL; //定义全局变量
- unsigned char code DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; // 显示段码值0~9
- uchar TempData[5]; //存储显示值的全局变量
- /******************** DHT11测试模块**********************/
- void start() //开始信号
- {
- io=1;
- delayus(10);
- io=0;
- delayms(30); //10~60之间
- io=1;
- delayus(100); //关键时间:35-250之间
- }
- /**********************接收一个字节**********************/
- uchar receive_byte()
- {
- uchar i,temp,count;
- for(i=0;i<8;i++)
- {
- count=2;
- while((!io)&&count++)
- temp=0;
- delayus(150); //关键时间:10~23之间
- if(io==1)temp=1;
- count=2;
- while((io)&&count++);
- if(count==1)break;
- data_byte<<=1;
- data_byte|=temp;
- }
- return data_byte;
- }
- /************************接收数据************************/
- void receive()
- {
- uchar T_H,T_L,R_H,R_L,check,num_check;
- uchar count;
- start(); //开始信号
- io=1;
- if(!io) //读取DHT11响应信号
- {
- count=2;
- while((!io)&&count++); //DHT11高电平80us是否结束
- count=2;
- while((io)&&count++);
- R_H=receive_byte();
- R_L=receive_byte();
- T_H=receive_byte();
- T_L=receive_byte();
- check=receive_byte();
-
- io=0;
- delayms(1); //拉低延时
- io=1;
- num_check=R_H+R_L+T_H+T_L;
-
- if(num_check=check)
- {
- RH=R_H;
- RL=R_L;
- TH=T_H;
- TL=T_L;
- check=num_check;
- }
- }
- }

芯片解密