Overview:
Keywords:MCU
Reference address:Design of single chip intelligent room
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 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
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
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
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);
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".
August 5, 2012
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,
#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;
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 delay(uint k)
{
uint data i,j;
for(i=0;i
{;}}
}
/**************************** *********/
/***********************************/
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******
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
{ 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;
}
//*******************************
{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(!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;
{ 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;
}
}
}
}
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.
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]
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]
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]
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]
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
Guess you like
- EEWORLD University ---- Big Data Machine Learning (Yuan Chun)
- BLE GATT service characteristic values and types
- Boss, what's your home WIFI password? ——Qorvo~Wi-Fi 6
- [RVB2601 Creative Application Development] 2 Realize long press and short press
- When BLE meets MEMS——attitude calculation
- Routine program for controlling stepper servo motor with single chip microcomputer and xc1004 four-axis SPI motion control chip
- Network port connector model help! (Except RJ45)
- 【NXP Rapid IoT Review】+ Review Summary
- This sentence was translated from Google Translate, and the final translation must be wrong. What does diode emulation mean?
- Examples of capacitor applications in power supply design (recommended for collection)