Design of single chip intelligent room

Publisher:Ziyu2022Latest update time:2015-06-15 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Overview:
1. The keyboard can be used to control the electrical appliances in each room.
2. You can also use wireless remote control to control the electrical appliances in each room.
3. It can also be connected to a computer and use computer programs to control the electrical appliances in each room.
4. With a large digital tube real-time clock, made of DS1302.
As long as it has the hours and minutes, it can replace the big clock.
  Hourly time signal (beep once), 2 alarms can be set,
5. You can use the 4*4 keyboard to directly adjust the time and set the alarm.
6. Use two microcontrollers to communicate with each other.
7. A single chip microcomputer is responsible for keyboard, clock, digital tube display, buzzer
(Named Unit 2)
8. Another MCU is responsible for detecting sensor input and connecting to NRF24L01 wireless module. Output controls the electrical appliances in each room (named No. 1)
9. Now think of the input sensors, two photoresistor sensors and one magnet reed switch sensor.
10. Output devices include lights in each room, fans, and an alarm horn.
 
Functions will continue to be added......
What you can learn:
I think the most important thing is the ability to integrate various modules.
1. Application of DS1302
2. Keyboard scanning program, keyboard input program, . . .
 
 
Project Progress:
April 3, 2012
I have been working on it for a week and have completed time display, 4*4 keyboard direct time adjustment, alarm setting, and hourly time announcement.
 
 April 9, 2012
Some variables and function names are excerpted below.
bit tiaoshibz; //Time adjustment mark
uchar zhishuPointer; //Time adjustment bit pointer
uchar xianshipointer; //Display the rotating pointer
uchar miaojilu; //Seconds record, used for flashing the second digit
uchar miaojishu; //Time when the second digit flashes
bit miaobz; //Mark when the second digit flashes end
uchar data xiancun[4]; //Display cache xiancun[0] is the tens digit of the hour xiancun[3] is the ones digit of the minute
bit naozhongbz1,naozhongbz2; //Alarm start flag
bit naozhongnaolingbz; //Alarm start flag
uchar naozhong1[4]; //Alarm timer naozhong[0] is the tens digit of the hour naozhong[3] is the ones digit of the minute
uchar naozhong2[4];
uchar zhengdianbaoshi; //Time signal on the hour
/********Keyboard use***********/
uchar code SKEY[16]={10,11,12,13,3,6,9,14,2,5,8,0,1,4,7,15};
uchar code act[4]={0xfe,0xfd,0xfb,0xf7};
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

/**********DS1302 function declaration**************/
void DS1302InputByte(unsigned char d);
unsigned char DS1302OutputByte(void);
void Write1302(unsigned char ucAddr, unsigned char ucDa);
unsigned char Read1302(unsigned char ucAddr);
void DS1302_SetProtect(bit flag);
void DS1302_SetTime(unsigned char Address, unsigned char Value);
void DS1302_GetTime(struct Clock *Time);
void TimeToStr(struct Clock *Time,bit bz);
/*void DateToStr(struct Clock *Time);*/
void Initial_DS1302(void);
//void BurstWrite1302(unsigned char *pWClock); //Write clock data to DS1302 (multi-byte mode)
//void BurstRead1302(unsigned char *pRClock); //Read DS1302 clock data (multi-byte clock mode)
//void DS1302_TimeStop(bit flag); //Stop the clock
/***********Function declaration*******************/
char scan_key(void);
void ControlInput(uchar a);
uchar jianceshuzhi(uchar pointer,char n);//Check if the input value is legalvoid
zhishu(void);//Keyboard direct inputvoid
naozhong(uchar bz1,uchar bz2);//Alarm clock contains hourly time (beep once)
void baojing(uint);//Alarm soundvoid
shanshuo(uchar a);
/*********Serial port function declaration**************/
void fasong (uchar a); //Send one bytevoid
huiying(void); //Respond to the computer (send input and output status to the computer)   
void yingda(void);
void yueding(bit a);
void Stringfasong(uchar *p);
 
The day before yesterday, I finally succeeded in the experiment of communicating between two microcontrollers using the SPI interface.
I am currently researching NRF24L01. If this experiment is successful and added to the smart room program, you can use wireless remote control to control home appliances.
May 1, 2012
The NRF24L01 transceiver experiment has been successful.
May 6, 2012
When I was studying NRF2401 a few days ago, I accidentally connected the wrong wires and burned one.
I bought two more pieces on Taobao yesterday and they are still on the way.
I have been studying VB programming these days, which is based on the human-computer interface I programmed last year. It is named "Human-Computer Interface".
 Here are the screenshots:
 
The functions that can be realized are:
The 8 command buttons can control the state of P0. Click once to reverse the state.
The green squares indicate the status of each bit of P0.
The 8 green dots indicate the status of each bit of port P2.
The instructions are all real-time. As long as the port status changes, the microcontroller will send the status to the computer for indication. [page]
 
 A few days ago, a time adjustment window was added. The time adjustment window program has the function of detecting whether the input data is legal. If the data is illegal, the input will be rejected.
After many debugging, the computer has realized the time adjustment of DS1302. 
The time adjustment process is that the computer sends the time data to machine No. 1, and machine No. 1 sends it to machine No. 2 and the computer.
 
I'm stuck on the wireless module, and my computer has had issues these days. I'm going to put it aside for a while. June 3, 2012
 
There have been new progress in the past few days. The wireless module and hardware experiments have been successful. Yesterday, I bought a long-range nRF24l01p on Taobao. It is on the way now. I will try my best to integrate the wireless module program into the smart room. July 16, 2012
 
Today I programmed the analog timer function on the PLC.
There are timers T0 to Tn on the PLC. Sometimes, many timers are used for delay or other purposes in single-chip programming. I have always wanted to use C language to implement such a
Function. I made it today. And it passed the experiment on the experimental board. Now I post it to share with friends who like microcontrollers.
#include   
#define uint unsigned int 
#define uchar unsigned char
//uchar code SEG87[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
//uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar jishu;
uint sec;//Seconds variable, can count about 18 hours,
//Adding a timer requires adding a variable jilu to record the current time
//And Tnbz mark 
uint jilu1,jilu2,jilu3,jilu4,jilu5;
bit t1bz,t2bz,t3bz,t4bz,t5bz;
sbit D1=P3^3;//Define key input
sbit D2=P3^4;
sbit D3=P3^5;
sbit D4=P3^2;
/******************************/
void delay(uint k)    
{       
uint data i,j;      
for(i=0;i {for(j=0;j<960;j++)     
{;}}       
}
/**************************** *********/
/***********************************/
void timer0(void) interrupt 1//used for timing
{
TH0=-(35000/256);
TL0=-(40000%256);
jishu++;
if(jishu==20)
sec++;//second variable. sec overflow has not been considered yet
 }
/***********************************/
void main(void)   
{    
  TH0=-(50000/256);
  TL0=-(50000%256);
  ET0=1;
  EA=1;
  TR0=1;
  sec=3600;
  while(1)    
{
//*****Virtual timer 1******  
 if(!t1bz)  
 { if(!D1)
   { delay(20);
     if(!D1)
     {jilu1=sec;
      t1bz=1;
     }
   }
 }
   if(sec-jilu1==2) // Here 2 is the delay time, change it to this value
//Change the delay time
    {P2=0xef;
  t1bz=0;
  }
//*******************************
   if(!t2bz)  
 { if(!D2)
   { delay(20);
     if(!D2)
     {jilu2=sec;
      t2bz=1;
     }
   }
 }
   if(sec-jilu2==4)
    {P2=0xdf;
  t2bz=0;
  }
//*****************************
   if(!t3bz)  
 { if(!D3)
   { delay(20);
     if(!D3)
     {jilu3=sec;
      t3bz=1;
     }
   }
 }
   if(sec-jilu3==6)
    {P2=0xbf;
  t3bz=0;
  }
//*****The following is the use of virtual timers 4 and 5 to make the P2^0 LED flash.
if(!t4bz)  
   { jilu5=0;
     jilu4=sec;
      t4bz=1;
 
 }
   if(sec-jilu4==1)
    {
 P2|=0x01;
  t5bz=1;
  }
//********** *********************
 if(t5bz)  
 { 
  jilu4=0;   
  jilu5=sec;
  t5bz=0;   
 }
   if(sec-jilu5==1)
    {P2&=0xfe;
  t4bz=0;
  } 
 }
}
I feel that the above procedures are rather complicated and brain-intensive. If you are interested, please be patient when reading this.
July 22, 2012
The hardware work of the smart room officially started last Sunday. In order to ensure stable and reliable work, I tried my best to avoid using thin copper wires as jumpers. The following pictures show the progress.











August 5, 2012
Smart room hardware progress: [page]











 
August 19, 2012
I did some work on the sensor input part yesterday.


I used LM339 and temporarily connected three sensors, two photoresistors, one temperature resistor, and the remaining 1/4 was used as a backup.

Keywords:MCU Reference address:Design of single chip intelligent room

Previous article:Digital tube timer program
Next article:32 Algorithms Introduction

Recommended ReadingLatest update time:2024-11-17 03:43

BCD code conversion and calculation in the implementation of Mege16 AVR microcontroller
.include "m16def.inc" .org $0000 rjmp RESET ;***The following is the program to convert 16-bit binary code (fbinH:fbinL) into BCD code (tBCD2:tBCD1:tBCD0)*** .equ AtBCD0 =13 ;address of tBCD0 .equ AtBCD2 =15 ;address of tBCD1 .def tBCD0 =r13  ;BCD value digits 1 and 0 .def tBCD1 =r14  ;BCD value digits 3 and
[Microcontroller]
MCS51 single-chip microcomputer bit operation instructions and programming examples
In the hardware structure of the MCS-51 microcontroller, there is a bit processor (also known as a Boolean processor) that has a set of instructions for bit variable processing . When performing bit processing, CY (the carry bit we mentioned earlier) is called a "bit accumulator". It has its own bit RAM, which is the
[Microcontroller]
4. MCU reads ID card (hardware debugging and code reading)
1. Power amplifier circuit and 125Khz carrier measurement Point A is the measurement point of the oscilloscope, and the signal carrier is the 125KHz waveform generated by the microcontroller. Actual waveform 2. LC resonant circuit and sine wave measurement Point B is the oscilloscope measurement point 3. Envelo
[Microcontroller]
4. MCU reads ID card (hardware debugging and code reading)
Realization of RS-485 multi-machine communication based on single chip microcomputer
1 Introduction The RS-485 serial bus interface standard transmits signals in a differential balanced manner, has a strong ability to resist common mode interference, and allows a transmitter on a pair of twisted pairs to drive multiple load devices. This bus standard is generally used for data transmission in in
[Microcontroller]
Microcontroller Learning Notes 5---Timer and Interrupt Configuration
In this section, we will explain the program in the previous section and learn what is used. ① To create a new program, you must first include the header file. For example, many people use STC89C52, because it is a standard 51 core, so you only need to write #include "reg51.h". However, the STC15W series is not a st
[Microcontroller]
Microcontroller Learning Notes 5---Timer and Interrupt Configuration
Design of PIC18F series single chip microcomputer to control the infrared remote controller hardware of multimedia terminal
1 Design Concept and Principle 1.1 Design Concept With the rapid development of technology in the field of digital home, there will be more and more value-added services on multimedia terminals. Browsing web pages, searching, and sending text messages all require input via remote control. However, as an important peri
[Microcontroller]
Design of PIC18F series single chip microcomputer to control the infrared remote controller hardware of multimedia terminal
51 single chip microcomputer generates 1Hz-5kHz adjustable duty cycle square wave
Notice 1. The change of high and low levels is not suitable in the while loop of the main function, because there must be a delay in the dynamic display of the digital tube and other logical processing. If the time is too long, the high and low level values ​​cannot be changed in time. 2. The execution time of the
[Microcontroller]
A low-cost, high-precision shunt detection solution based on Microchip MCU, CAN interface and signal conditioning platform
BMS (Battery Management System) is a bridge connecting the battery, the core component of new energy vehicles, and the whole vehicle. Benefiting from the development of new energy vehicles, BMS, as a core component, has also developed rapidly. BMS is divided into master-slave BMS and all-in-one BMS according to the di
[Automotive Electronics]
A low-cost, high-precision shunt detection solution based on Microchip MCU, CAN interface and signal conditioning platform
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号