本設(shè)計是使用兩個紅外對管來檢測是否有人進(jìn)入辦公室并進(jìn)行人數(shù)統(tǒng)計,人數(shù)最多統(tǒng)計到二位數(shù)99人,并實時將人數(shù)顯示到液晶屏LCD上,液晶屏同時顯示實時日期/時間/星期; 使用4個LED燈模擬辦公室的照明燈,在符合條件開啟時,人數(shù)為0時燈不亮,人數(shù)小于10人亮一個燈,10-20人亮二個燈,20-30人亮三個燈,大于30人則全亮四個燈; 系統(tǒng)分自動/手動模式,可以通過按鍵切換模式,并有LED指示當(dāng)前所在模式; 在自動模式下,可以設(shè)定定時時間段,在定時時間段內(nèi),當(dāng)辦公室有人(人數(shù)大于0)的情況下,如果光線暗弱則自動打開照明燈,照明燈點亮個數(shù)根據(jù)人數(shù)而定,不在定時時間段或者辦公室無人的情況下,關(guān)閉所有照明燈; 另外在手動模式下,可以通過手動開關(guān)控制照明燈的亮滅,人數(shù)統(tǒng)計部分仍然生效;
制作出來的實物圖如下:
07848188-cc6a-4b4f-bbfd-b9816f164fd3.jpg (580.19 KB, 下載次數(shù): 55)
下載附件
2021-3-31 22:00 上傳
ffc0f9d3-f5a5-4982-9961-95ae33e22119.jpg (308.44 KB, 下載次數(shù): 49)
下載附件
2021-4-1 00:58 上傳
d932de09-16e6-4cc6-8580-0e5eccf2c24a.jpg (575.7 KB, 下載次數(shù): 58)
下載附件
2021-4-1 00:58 上傳
0be0cd27-e0a9-4c62-8461-eb9d06a1fe67.jpg (886.08 KB, 下載次數(shù): 43)
下載附件
2021-4-1 00:58 上傳
電路原理圖如下:
原理圖.png (193.73 KB, 下載次數(shù): 58)
下載附件
2021-4-1 00:59 上傳
元件清單:
元器件 型號 數(shù)量
單片機(jī)最小系統(tǒng) stc89c52 1
液晶顯示 LCD1602 1
紅外模塊 2
時鐘芯片 DS1302 1
光敏電阻模塊 1
按鈕 5
led 6
電阻 300歐姆 2
數(shù)據(jù)線 1
程序流程圖:
51hei.png (33.56 KB, 下載次數(shù): 62)
下載附件
2021-4-1 01:06 上傳
單片機(jī)源程序如下:
/*******************說明:************************** 將實時時鐘數(shù)據(jù)通過LCD1602顯示 #include <reg52.h> #include <intrins.h> #define uchar unsigned char #define uint unsigned int uchar dis_time_buf[16]={0}; //LCD1602引腳定義 //采用8位并行方式,DB0~DB7連接至LCDDATA0~LCDDATA7 sbit RS=P2^2; sbit RW=P2^1; sbit CS=P2^0; #define LCDDATA P0 //時鐘DS1302引腳定義 sbit RST=P2^4; sbit IO=P2^5; sbit SCK=P2^6;
sbit guangmin = P1^3;//光敏傳感器
sbit led1 = P3^3; //6個指示燈 sbit led2 = P3^2; sbit led3 = P1^7; sbit led4 = P1^0; sbit led5 = P1^4; sbit led6 = P1^5;
sbit K1=P3^5; //按鍵 sbit K2=P3^7; sbit K3=P3^4; sbit K4=P3^6; sbit K5=P1^6;
sbit Ir1=P1^1; //red Ir sbit Ir2=P1^2;
//DS1302地址定義 #define ds1302_sec_add 0x80 //秒數(shù)據(jù)地址 #define ds1302_min_add 0x82 //分?jǐn)?shù)據(jù)地址 #define ds1302_hr_add 0x84 //時數(shù)據(jù)地址 #define ds1302_date_add 0x86 //日數(shù)據(jù)地址 #define ds1302_month_add 0x88 //月數(shù)據(jù)地址 #define ds1302_day_add 0x8a //星期數(shù)據(jù)地址 #define ds1302_year_add 0x8c //年數(shù)據(jù)地址 #define ds1302_control_add 0x8e //控制數(shù)據(jù)地址 #define ds1302_charger_add 0x90 #define ds1302_clkburst_add 0xbe
//flag uchar flag_led1_sta = 0; uchar flag_led2_sta = 0; uchar flag_led3_sta = 0; uchar flag_led4_sta = 0; uchar flag_led5_sta = 0;
uchar flag_person_cont = 0; uchar flag_person_cont_buf[3]=000; uint flag_per_add = 0; uint flag_per_cut = 0; uint flag_mode_choose = 1; uint flag_guang = 1; //初始時間定義 uchar time_buf[8] = {0x20,0x21,0x02,0x01,0x11,0x47,0x55,0x02};//初始時間2020年11月17號11:47:55 week:2 /*************************延時函數(shù)*********************************/ //功能:延時1毫秒 //入口參數(shù):x //出口參數(shù):無 //說明:當(dāng)晶振為12M時,j<112;當(dāng)晶振為11.0592M時,j<122 void Delay_xms(uint x) { uint i,j; for(i=0;i<x;i++) for(j=0;j<112;j++); } //功能:12us延時 //STC89C52為1T單片機(jī),即1個時鐘/機(jī)器周期,速度為AT89C52的12倍 void Delay_xus(uint t) { for(;t>0;t--) { _nop_(); } } //控制LCD寫時序 void LCD_en_write(void) { CS=1; Delay_xus(20); CS=0; Delay_xus(20); }
//寫指令函數(shù) void Write_Instruction(uchar command) { RS=0; RW=0; CS=1; LCDDATA=command; LCD_en_write();//寫入指令數(shù)據(jù) }
//寫數(shù)據(jù)函數(shù) void Write_Data(uchar Wdata) { RS=1; RW=0; CS=1; LCDDATA=Wdata; LCD_en_write();//寫入數(shù)據(jù) }
//字符顯示初始地址設(shè)置 void LCD_SET_XY(uchar X,uchar Y) { uchar address; if(Y==0) address=0x80+X;//Y=0,表示在第一行顯示,地址基數(shù)為0x80 else address=0xc0+X;//Y非0時,表時在第二行顯示,地址基數(shù)為0xC0 Write_Instruction(address);//寫指令,設(shè)置顯示初始地址 } //在第X行Y列開始顯示W(wǎng)data所對應(yīng)的單個字符 void LCD_write_char(uchar X,uchar Y,uchar Wdata) { LCD_SET_XY(X,Y);//寫地址 Write_Data(Wdata);//寫入當(dāng)前字符并顯示 } //清屏函數(shù) void LCD_clear(void) { Write_Instruction(0x01); Delay_xms(5); } void led_init() { led1=1; led2=1; led3=1; led4=1; led5=0; led6=1; } //顯示屏初始化函數(shù) void LCD_init(void) { Write_Instruction(0x38); //8bit interface,2line,5*7dots Delay_xms(5); Write_Instruction(0x38); Delay_xms(5); Write_Instruction(0x38);
Write_Instruction(0x08); //關(guān)顯示,不顯光標(biāo),光標(biāo)不閃爍 Write_Instruction(0x01); //清屏 Delay_xms(5);
Write_Instruction(0x04); //寫一字符,整屏顯示不移動 //Write_Instruction(0x05); //寫一字符,整屏右移 //Write_Instruction(0x06); //寫一字符,整屏顯示不移動 //Write_Instruction(0x07); //寫一字符,整屏左移 Delay_xms(5);
//Write_Instruction(0x0B); //關(guān)閉顯示(不顯示字符,只有背光亮) Write_Instruction(0x0C); //開顯示,光標(biāo)、閃爍都關(guān)閉 //Write_Instruction(0x0D); //開顯示,不顯示光標(biāo),但光標(biāo)閃爍 //Write_Instruction(0x0E); //開顯示,顯示光標(biāo),但光標(biāo)不閃爍 //Write_Instruction(0x0F); //開顯示,光標(biāo)、閃爍均顯示 } //DS1302初始化函數(shù) void ds1302_init(void) { RST=0; //RST腳置低 SCK=0; //SCK腳置低 } //向DS1302寫入一字節(jié)數(shù)據(jù) void ds1302_write_byte(uchar addr, uchar d) { uchar i; RST=1; //啟動DS1302總線 //寫入目標(biāo)地址:addr addr = addr & 0xFE; //最低位置零,寄存器0位為0時寫,為1時讀 for (i = 0; i < 8; i ++) { if (addr & 0x01) { IO=1; } else { IO=0; } SCK=1; //產(chǎn)生時鐘 SCK=0; addr = addr >> 1; } //寫入數(shù)據(jù):d for (i = 0; i < 8; i ++) { if (d & 0x01) { IO=1; } else { IO=0; } SCK=1; //產(chǎn)生時鐘 SCK=0; d = d >> 1; } RST=0; //停止DS1302總線 }
//從DS1302讀出一字節(jié)數(shù)據(jù) uchar ds1302_read_byte(uchar addr) {
uchar i,temp; RST=1; //啟動DS1302總線 //寫入目標(biāo)地址:addr addr = addr | 0x01; //最低位置高,寄存器0位為0時寫,為1時讀 for (i = 0; i < 8; i ++) { if (addr & 0x01) { IO=1; } else { IO=0; } SCK=1; SCK=0; addr = addr >> 1; } //輸出數(shù)據(jù):temp for (i = 0; i < 8; i ++) { temp = temp >> 1; if (IO) { temp |= 0x80; } else { temp &= 0x7F; } SCK=1; SCK=0; } RST=0; //停止DS1302總線 return temp; } //向DS302寫入時鐘數(shù)據(jù) void ds1302_write_time(void) { ds1302_write_byte(ds1302_control_add,0x00); //關(guān)閉寫保護(hù) ds1302_write_byte(ds1302_sec_add,0x80); //暫停時鐘 ds1302_write_byte(ds1302_charger_add,0xa9); //涓流充電 ds1302_write_byte(ds1302_year_add,time_buf[1]); //年 ds1302_write_byte(ds1302_month_add,time_buf[2]); //月 ds1302_write_byte(ds1302_date_add,time_buf[3]); //日 ds1302_write_byte(ds1302_hr_add,time_buf[4]); //時 ds1302_write_byte(ds1302_min_add,time_buf[5]); //分 ds1302_write_byte(ds1302_sec_add,time_buf[6]); //秒 ds1302_write_byte(ds1302_day_add,time_buf[7]); //周 ds1302_write_byte(ds1302_control_add,0x80); //打開寫保護(hù) } //從DS302讀出時鐘數(shù)據(jù) void ds1302_read_time(void) { time_buf[1]=ds1302_read_byte(ds1302_year_add); //年 time_buf[2]=ds1302_read_byte(ds1302_month_add); //月 time_buf[3]=ds1302_read_byte(ds1302_date_add); //日 time_buf[4]=ds1302_read_byte(ds1302_hr_add); //時 time_buf[5]=ds1302_read_byte(ds1302_min_add); //分 time_buf[6]=(ds1302_read_byte(ds1302_sec_add))&0x7f;//秒,屏蔽秒的第7位,避免超出59 time_buf[7]=ds1302_read_byte(ds1302_day_add); //周 } void Display(void) {
LCD_write_char(1,0,dis_time_buf[0]+'0');
LCD_write_char(2,0,dis_time_buf[1]+'0');
.......限于篇幅余下代碼請下載附件..............
全部資料51hei下載地址:
智能照明系統(tǒng).7z
(2.67 MB, 下載次數(shù): 119)
2021-4-1 01:07 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|