Single chip microcomputer intelligent curtain proteus simulation diagram and code

Publisher:RadiantBlossomLatest update time:2019-11-20 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The microcontroller source program is as follows:

/********51 single chip microcomputer intelligent curtain design********/

/****************JJ Electronics Direct Store****************/

/***************original design***************/


#include //header file

#define uchar unsigned char

#define uint unsigned int


#define CS P3_0 //ADC0804 CS port

#define RD P3_1 //ADC0804 RD port

#define WR P3_2 //ADC0804 WR port

#define g_kz P2_5 //digit control of digital tube

#define s_kz P2_4 //Nude tube ten-digit control

#define b_kz P2_3 //digital tube hundreds digit control

#define q_kz P2_2 //code tube thousands control

#define SMG_XS P0 //Digital tube display port

#define AD_data P1 //ADC0804 output port

#define Up P2_1 //Upper limit switch port

#define Down P2_0 //Lower limit switch port

#define Key1 P3_3 //Manual/auto switch button

#define Key2 P3_4 //Timing/light control function switch button

#define Key3 P3_5 //Set the key

#define Key4 P3_6 //Add button (manual mode: open curtains timing mode: open curtains at a fixed time)

#define Key5 P3_7 //Decrease button (manual mode: close curtains timing mode: close curtains at a fixed time)


#define IA P2_7 //DC motor control port

#define IB P2_6 //DC motor control port


int adval; //ADC output variable

int j; //define loop variable ij

uchar flag=0; //Display flag (0: normal display 1: upper limit illumination setting (time adjustment) 2: lower limit illumination setting (minute adjustment)                                 

bit flag_gd=0; //Light control/timing flag (0: current light intensity 1: timing time)        

bit ms=0; //Mode (0: manual mode 1: automatic mode)

bit move=0; //Timed time flag (0: time not yet reached 1: time reached)

bit OFF_ON=0; //Motor forward and reverse rotation flag, indicating whether the curtain is open or closed (0: curtain closed 1: curtain open)

bit Time_OFF_ON=0; //Open or close the curtains at the scheduled time (0: close the curtains at scheduled time 1: open the curtains at scheduled time)


char hour=12,min=0;sec=0; //Define the time "hour, minute, second" variables. The default value is 12.00.00 when powered on.

char num=0; //time base

uint H_GM=240; //Define the upper limit light sensitivity setting variable, the default value is 200 when powered on

uint L_GM=100; //Define the lower limit light sensitivity setting variable, the default value is 100 when powered on

uchar t=1; //digital tube dynamic scanning delay parameter

                

uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};        

//Digital tube display array 0 1 2 3 4 5 6 7 8 9


void delay(uint time) //delay function

{

        uint x,y; //define temporary variables xy

        for(x=time;x>0;x--)

        for(y=110;y>0;y--); //No operation

}


void Time_init() //Timer initialization

{

        EA=1;

        TMOD=0x11;


        /*Timer 0 initialization (generates PWM to control motor speed)*/        

        TH0=0xf8; //timing 2ms

        TL0=0xcc;

        ET0=1; //Enable T0 interrupt

        TR0=0; //Do not start timer 0 first

        /*Timer 1 initialization (generating 50ms timing)*/

        TH1=0x4c; //50ms

        TL1=0x00;

        ET1=1;

        TR1=0; //Do not start timer 1 first        

}


void Key_cl()

{

        static bit keybuf1=1; //Key1 value is temporarily stored, and the key scan value is temporarily saved

        static bit backup1=1; //Key1 value backup, save the previous scan value

        static bit keybuf2=1; //Key2 value is temporarily stored, and the key scan value is temporarily saved        

        static bit backup2=1; //Key2 value backup, save the previous scan value

        static bit keybuf3=1; //Key3 value is temporarily stored, and the key scan value is temporarily saved

        static bit backup3=1; //Key3 value backup, save the previous scan value

        static bit keybuf4=1; //Key4 value is temporarily stored, and the key scan value is temporarily saved

        static bit backup4=1; //Key4 value backup, save the previous scan value

        static bit keybuf5=1; //Key5 value is temporarily stored, and the key scan value is temporarily saved

        static bit backup5=1; //Key5 value backup, save the previous scan value

        keybuf1=Key1; //temporarily store the current scan value of Key1

        if(keybuf1!=backup1) //The current value of Key1 is not equal to the previous value, indicating that Key1 has an action

        {

                delay(1); //delay debounce

                if(keybuf1==Key1) //Judge whether the scan value of Key1 has changed, i.e. the key is jittering

                {

                        if(backup1==1) //Key1 is pressed and effective

                        {

                                move=0; //Reset the time flag to 0 (time not up)

                                TR0=0; //turn off timer 0

                                ms=~ms; // Mode inversion

                                q_kz=1;b_kz=1;s_kz=1;g_kz=1;//Turn off the digital tube display

                                IA=0;IB=0; //curtain stop        

                        }

                        backup1=keybuf1; //Update the current value of backup Key1 for the next comparison

                }

        }

        if(ms==0) ​​//manual mode

        {

                if(Key4==0) //When the curtain opening button is pressed

                {

                        delay(10); //delay debounce

                        if(Key4==0) // Check if the key is pressed

                        {

                                move=0; //Reset the time flag to 0 (time not up)

                                OFF_ON=1; //curtains open

                                TR0=1; //Start timer 0

                                SMG_XS=table[1]; //The digital tube displays "1"

                                q_kz=1;b_kz=1;s_kz=1;g_kz=0; //unit display

                                while(Key4==0); //Wait for the key to be released

                                TR0=0; //turn off timer 0

                                IA=0;IB=0; //curtain stop

                                q_kz=1;b_kz=1;s_kz=1;g_kz=1; //Turn off the digital tube        

                        }

                }

                if(Key5==0) //When the curtain closing button is pressed

                {

                        delay(10); //delay debounce        

                        if(Key5==0) // Check if the key is pressed

                        {

                                move=0; //Reset the time flag to 0 (time not up)

                                OFF_ON=0; //Curtains closed

                                TR0=1; //Start timer 0

                                SMG_XS=table[0]; //The digital tube displays "0"

                                q_kz=1;b_kz=1;s_kz=1;g_kz=0; //unit display

                                while(Key5==0); //Wait for the key to be released

                                TR0=0; //turn off timer 0

                                IA=0;IB=0; //curtain stop        

                                q_kz=1;b_kz=1;s_kz=1;g_kz=1; //Turn off the digital tube

                        }

                }                

        }

        else //In automatic mode

        {

                keybuf2=Key2; //temporarily store the current scan value of Key2

                if(keybuf2!=backup2) //The current value of Key2 is not equal to the previous value, indicating that the Key2 key has an action

                {

                        delay(1); //delay debounce

                        if(keybuf2==Key2) //Judge whether the scan value of Key2 has changed, i.e. the key is jittering

                        {

                                if(backup2==1) //Key2 is pressed and effective

                                {        

                                        move=0; //Reset the time flag to 0 (time not up)

                                        flag_gd=~flag_gd; //Light control/timing flag inversion (0: current light intensity 1: timing time)                                                                

                                }

                                backup2=keybuf2; //Update the current value of backup Key2 for the next comparison

                        }

                }

                keybuf3=Key3; //temporarily save the current scan value of Key3                        

                if(keybuf3!=backup3) //The current value of Key3 is not equal to the previous value, indicating that Key3 has an action

                {

                        delay(1); //delay debounce

                        if(keybuf3==Key3) //Judge whether the scan value of Key3 has changed, i.e. the key is jittering        

                        {

                                if(backup3==1) //Key3 is pressed and effective

                                {

                                        move=0; //Reset the time flag to 0 (time not up)

                                        TR0=0; //turn off timer 0

                                        flag++;

                                        if(flag==3) {flag=0;} //Keep flag between 0 and 2

                                }

                                backup3=keybuf3; //Update the current value of backup Key3 for the next comparison

                        }

                }

                if(flag==1) //Allow upper limit illumination setting (time adjustment)                        

                {

                        keybuf4=Key4; //temporarily store the current scan value of Key4

                        if(keybuf4!=backup4) //The current value of Key4 is not equal to the previous value, indicating that Key4 has an action

                        {

                                delay(1); //delay debounce

                                if(keybuf4==Key4) //Judge whether the scan value of Key4 has changed, i.e. the key is jittering        

                                {

                                        if(backup4==1) //Key4 is pressed and effective

                                        {

                                                if(flag_gd==0) //Light intensity setting allowed        

                                                {

[1] [2] [3] [4]
Keywords:MCU Reference address:Single chip microcomputer intelligent curtain proteus simulation diagram and code

Previous article:51 single chip microcomputer realizes three-phase six-step stepper motor control
Next article:What does a nop in a 51 MCU mean?

Recommended ReadingLatest update time:2024-11-23 11:48

MathWorks Simulink Products Now Support Infineon’s Newest AURIX™ TC4x Family of Automotive Microcontrollers
MathWorks Simulink Products Now Support Infineon’s Newest AURIX™ TC4x Family of Automotive Microcontrollers Beijing, China, December 13, 2022 - MathWorks and Infineon Technologies AG today announced the launch of a hardware support package for MathWorks Simulink® products, providing su
[Automotive Electronics]
MathWorks Simulink Products Now Support Infineon’s Newest AURIX™ TC4x Family of Automotive Microcontrollers
Using LED to realize the running light--Single-chip microcomputer simulation experiment
Assignment title: Implement a marquee in assembly language Assignment requirements: Use light-emitting diodes to achieve a marquee effect. Eight light-emitting diodes run from top to bottom twice and flash twice.                   Then run from bottom to top twice and dodge twice. Program flow chart: Appl
[Microcontroller]
Infineon Technologies expands its AIROC Wi-Fi 6/6E portfolio with the powerful CYW5591x family of wireless microcontrollers
Infineon Technologies AG, a global semiconductor leader in power systems and the Internet of Things, recently launched the new AIROC™ CYW5591x wireless microcontroller (MCU) product series . The new series integrates powerful long-range Wi-Fi 6/6E with low-power Bluetooth 5.4 and secure multi-function MCUs,
[Embedded]
Infineon Technologies expands its AIROC Wi-Fi 6/6E portfolio with the powerful CYW5591x family of wireless microcontrollers
51 single chip microcomputer traffic light program design
Using 51 single-chip microcomputer as the MCU of the system, the control of two groups of traffic lights is basically completed. Each intersection has three indicator lights: left turn, straight and pedestrian. Each straight light has three colors: red, yellow and green. Bicycles and cars share left turn and straight
[Microcontroller]
51 Microcontroller Basics: Timer Interrupt (1)
TH and TL timing conversion: To put it bluntly, the timer counts down. When the time is up, an interrupt is triggered, so the countdown time must be set. TH0 and TL0 are the upper eight bits and the eighth bit Assume that the timing is 1ms once, then 2 raised to the 16th power is equal to 65536, and the timing i
[Microcontroller]
51 Microcontroller Basics: Timer Interrupt (1)
PID programming of C51 microcontroller
//Main program============================================== ======== #include “Main.h” #include “PID_f1.h” /* 。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。.. */ /* 。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。..。.. */ void main(void) { float x,y,z; while(1) { x = PID_Control(y,z); } } //P
[Microcontroller]
Design of single chip microcomputer control program
    In this system, the single-chip microcomputer AT89C51 is responsible for keyboard processing, serial display of various working states, and coordination with ∏GA measurement and control and frequency preset. Specifically, it includes the single-chip microcomputer main program, preset frequency plus 1 subroutine, pr
[Microcontroller]
Design of single chip microcomputer control program
Realization of playing music with single chip microcomputer based on Proteus
Many current systems that use single-chip microcomputers to perform music are implemented using development boards combined with simulators. This method is not very complicated and is easy to implement, but it is not very convenient to debug and the cost is also high. This paper proposes a method of playing music wi
[Microcontroller]
Realization of playing music with single chip microcomputer based on Proteus
Latest Microcontroller Articles
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号