标题:
单片机自习室监控系统程序(包括原理图)
[打印本页]
作者:
屿浪大魔王
时间:
2019-8-18 07:31
标题:
单片机自习室监控系统程序(包括原理图)
自习室监控系统用红外传感器来检查,通过12864液晶显示屏来显示
电路原理图如下:
0.png
(39.84 KB, 下载次数: 45)
下载附件
2019-8-18 15:35 上传
Comment Designator LibRef
电解电容 C1 10uF
瓷片电容 C2, C3 30pF
USB5V DC 1 Header 2
红外开关 P1, P2 MHDR1X3
发光二极管 POWER1 LED0
电阻 R1 10k
电阻 R2 10K
电阻 R3 2k
电位器 RV1 R
触点开关 S1 SW-PB
电源开关 SW1 SW-SPDT
蓝牙模块 LANYA HC-05
单片机 U1 STC89C52
液晶屏 U2 LCD12864
温湿度传感器 U3 DTT11
晶振 Y1 12MHz
万能板 9x15cm
单片机源程序如下:
#include <reg52.h>
#define uchar unsigned char //无符号字符型 宏定义 变量范围0~255
#define uint unsigned int //无符号整型 宏定义 变量范围0~65535
#include "LCD12864.h"
#include<intrins.h>
#include "dht11.h"
sbit jin_1 = P2^0; //进来传感器1
sbit chu_1 = P2^1; //出去传感器1
uint zong_rs; //总人数
uint tongd1_jl; //通道1进来的人数
uint tongd1_cq; //通道1出去的人数
uchar t1_value; //通道1用做判断是进来还是出去的变量
uchar t1_zk; //通道1人走开
uchar t1_j_xd; //通道1进消抖
uchar t1_c_xd; //通道1出消抖
uchar t1_qans_qx; //通道1延时取消
uint t1_qans_value; //通道1延时取消
uchar Rx_buf[4],Rxnum=0;
uchar table_dht11[5]={1,2,3,4,5};
void InitUART(void) //这是串口的基本配置,配置他的波特率是9600.这些参数都是标准的。
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xFD;
TL1 = TH1;
PCON = 0x00;
EA = 1;
ES = 1;
TR1 = 1;
}
/*
* UART 发送一字节
*/
void UART_send_byte(char dat)
{
SBUF = dat;
while (TI == 0);
TI = 0;
}
/*
* UART 发送字符串
*/
void UART_send_string(unsigned char *buf)
{
while (*buf != '\0')
{
UART_send_byte(*buf++);
}
}
void Delay_ms(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<123;j++);
}
void dst11()
{
RH();//读出温湿度
table_dht11[2] = U8T_data_H;
table_dht11[0] = U8RH_data_H;
}
void tongd1_display()
{
/*******************通道1处理********************/
if(t1_value == 0)
{
if(jin_1 == 0)
{
t1_j_xd ++;
if(t1_j_xd >= 3)
{
t1_j_xd = 0;
t1_value = 1;
t1_zk = 0;
t1_qans_qx = 1;
t1_qans_value = 0;
}
}
else
t1_j_xd = 0;
if(chu_1 == 0)
{
t1_c_xd ++;
if(t1_c_xd >= 3)
{
t1_c_xd = 0;
t1_value = 2;
t1_zk = 0;
t1_qans_qx = 1;
t1_qans_value = 0;
}
}
else
t1_c_xd = 0;
}
else
{
if(t1_qans_qx == 1)
{
t1_qans_value ++; //5ms
if(t1_qans_value > 400) //2s
t1_value = 0;
}
if(t1_value == 1)
{
if((chu_1 == 0) && (t1_zk == 0))
{
tongd1_jl ++; //通道1进来的人数加1
zong_rs = tongd1_jl - tongd1_cq;
t1_zk = 1;
t1_qans_value = 0;
t1_qans_qx = 0;
}
if(t1_zk == 1) //人走开
{
if(chu_1 == 1)
{
t1_value = 0;
t1_zk = 0;
}
}
}
if(t1_value == 2)
{
if((jin_1 == 0) && (t1_zk == 0))
{
if(tongd1_jl > tongd1_cq )
tongd1_cq ++; //通道1出去的人数加1
zong_rs = tongd1_jl - tongd1_cq; //计算总人数
t1_zk = 1;
t1_qans_value = 0;
t1_qans_qx = 0;
}
if(t1_zk == 1) //人走开
{
if(jin_1 == 1)
{
t1_value = 0;
t1_zk = 0;
}
}
}
}
}
void main(void)
{
uchar Tx_Buf[15];
InitUART(); //初始化串口
LCD12864_Reset(); //初始化液晶
LCD12864_HAIZI_SET(); //设置为普通模式
LCD12864_NoWaitIdle_COM_Write(0x80); //指针设置
LCD12864_write_word("座位:50 人员: ");
LCD12864_NoWaitIdle_COM_Write(0x90); //指针设置
LCD12864_write_word("余座: ");
LCD12864_NoWaitIdle_COM_Write(0x88); //指针设置
LCD12864_write_word("温度: ℃ ");
LCD12864_NoWaitIdle_COM_Write(0x98); //指针设置
LCD12864_write_word("湿度: % ");
dst11(); //先读出温湿度的值
while(1)
{
tongd1_display();
dst11(); //先读出温湿度的值
LCD12864_NoWaitIdle_COM_Write(0x8b); //指针设置
LCD12864_Data_Write(0x30+table_dht11[2]%100/10);
LCD12864_Data_Write(0x30+table_dht11[2]%10);
Delay_ms(1);
LCD12864_NoWaitIdle_COM_Write(0x9b);
LCD12864_Data_Write(0x30+table_dht11[0]%100/10);
LCD12864_Data_Write(0x30+table_dht11[0]%10);
Delay_ms(1);
LCD12864_NoWaitIdle_COM_Write(0x87);
LCD12864_Data_Write(0x30+zong_rs/10);
LCD12864_Data_Write(0x30+zong_rs%10);
Delay_ms(1);
LCD12864_NoWaitIdle_COM_Write(0x93);
LCD12864_Data_Write(0x30+(50-zong_rs)/10);
LCD12864_Data_Write(0x30+(50-zong_rs)%10);
Tx_Buf[0]='T'; //帧头
Tx_Buf[1]=5+0x30; //将湿度数据送往发送数组,送给蓝牙模块让手机APP显示
Tx_Buf[2]=0+0x30;
Tx_Buf[3]=zong_rs/10+0x30;
Tx_Buf[4]=zong_rs%10+0x30;
Tx_Buf[5]=(50-zong_rs)/10+0x30;
Tx_Buf[6]=(50-zong_rs)%10+0x30;
Tx_Buf[7]=table_dht11[2]/10+0x30;
Tx_Buf[8]=table_dht11[2]%10+0x30;
Tx_Buf[9]=table_dht11[0]/10+0x30;
Tx_Buf[10]=table_dht11[0]%10+0x30;
Tx_Buf[11]=0;//结束符
UART_send_string(Tx_Buf); //串口发送温湿度数据出去
}
}
/*****************串口接收中断函数,接收蓝牙模块的数据*********************/
void UARTInterrupt(void) interrupt 4
{
ES=0; //关闭中断
if(RI) //接收到数据
{
Rx_buf[Rxnum]=SBUF; //接收数据进数组
if(Rx_buf[Rxnum]==0x08)
Rxnum=0;
else
Rxnum++;
// if(Rx_buf[0]==0x01)//LED1灯
// {
// if(Rx_buf[1]==0x01)//开灯
// LED1=0;//开灯
// else
// LED1=1; //关灯
// }
// if(Rx_buf[0]==0x02)//LED2灯
// {
// if(Rx_buf[1]==0x01)//开灯
// LED2=0;//开灯
// else
// LED2=1; //关灯
// }
}
RI=0;
ES=1; //关闭中断
}
复制代码
所有资料51hei提供下载:
自习室蓝牙监控系统.7z
(224.9 KB, 下载次数: 42)
2019-8-18 15:35 上传
点击文件名下载附件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1