#include //Include header file, generally no need to change,
//Header file contains the definition of special function registers
sbit SCL=P2^0;
sbit SDA=P2^1;
sbit led=P2^2;
sbit led1=P1^5;
sbit tz=P2^3; //Stop button
sbit lc1=P2^4; //One floor button
sbit lc2=P2^5; //Second floor button
sbit lc3=P2^6; //3rd floor button
sbit lc4=P2^7; //Fourth floor button
sbit mb=P0^0; //Door insurance sensor processing
sbit dw1=P0^1; //Processing of one floor in place
sbit dw2x=P0^2; //Processing of one floor in place
sbit dw2s=P0^3; //Processing of one floor in place
sbit dw3x=P0^4; // One floor in place
sbit dw3s=P0^5; //Processing of one floor in place
sbit dw4=P0^6; //Processing of one floor in place
sbit jd1=P3^5; // Stop the main power supply normally closed relay
sbit jd2=P3^6; //Rising relay
sbit jd3=P3^7; //Down relay
bit fg,fg1,fg2; //bit processing
bit sb,jb; // rising flag bit falling flag bit
bit dw2,dw3; //Second and third floors in place
bit lch12; // Flag between floors 1 and 2
bit lch23; // Flag between floors 2 and 3
bit lch34; // Flag between floors 3 and 4
unsigned char num,num1,num2;
unsigned char jylc; // Memory layer number variable
void Delay(unsigned int t); //Function declaration
void Init_Timer0(void);
/*------------------------------------------------
Main function
------------------------------------------------*/
void main (void)
{
char i,a;
char lch,lch1; //Floor number variable,lch1 is used when the digital tube scans only once
SDA=0;
lch=2; fg=1;
Delay(60);
if(dw1==0)
{ lch=1;fg=1;lc1=1; }
if(dw2x==0||dw2s==0)
{ lch=2;fg=1;lc2=1;}
if(dw3x==0||dw3s==0)
{ lch=3;fg=1;lc3=1;}
if(dw4==0)
{ lch=4;fg=1;lc4=1; }
Init_Timer0(); //Timer initialization
while (1) //main loop
{
if(lc1==1&&lc2==1&&lc3==1&&lc4==1)
a=1;
if(lc1==0&&a==1&&dw1!=0) //Floor selection
{ a=0;jylc=1;lc1=0; }
if(lc2==0&&a==1&&dw2!=0)
{ a=0;jylc=2;lc2=0; }
if(lc3==0&&a==1&&dw3!=0)
{ a=0;jylc=3;lc3=0; }
if(lc4==0&&a==1&&dw4!=0)
{ a=0;jylc=4;lc4=0; }
if(tz==0||mb==1) //Stop button pressed
{
lc1=1;lc2=1;lc3=1;lc4=1; //Floor button reset
jylc=0; //Memory floor reset
if(lch12==0&&lch23==0&&lch34==0&&(sb==1||jb==1))
{
fg1=1;
if(lch==1&&sb==1)
lch12=1;
if(lch==2&&sb==1)
lch23=1;
if(lch==2&&jb==1)
lch12=1;
if(lch==3&&sb==1)
lch34=1;
if(lch==3&&jb==1)
lch23=1;
if(lch==4&&jb==1)
lch34=1;
}
jd2=1;jd3=1; //Relay stops energizing and the elevator stops
}
[page]
if(dw1==0&&jb==1)
{ lch=1;fg=1;lc1=1; }
if((dw2x==0&&jb==1)||(sb==1&&dw2s==0))
{ lch=2;fg=1;lc2=1;dw2=0; }
else
dw2=1;
if((dw3x==0&&jb==1)||(sb==1&&dw3s==0))
{ lch=3;fg=1;lc3=1;dw3=0; }
else
dw3=1;
if(dw4==0&&sb==1)
{ lch=4;fg=1;lc4=1; }
if(dw1==0||dw2==0||dw3==0||dw4==0)
{ fg1=0;lch12=0;lch23=0;lch34=0; }
if(jylc!=0)
{
if(jylc>lch && fg1==0)
{ jd2=0;jd3=1; sb=1;jb=0; led=0; } //Elevator goes up
if(jylc
Reference address:Elevator control program based on single chip microcomputer
{ jd3=0;jd2=1; sb=0;jb=1; led=1;} //Elevator descends
if(jylc==lch && fg1==0)
{ jd2=1;jd3=1; sb=0;jb=0;lc1=1;lc2=1;lc3=1;lc4=1; } //Elevator stops
if(lch12==1)
{
if(jylc==1)
{ jd3=0;jd2=1; sb=0;jb=1; led=1; } //Elevator descends
if(jylc>=2)
{ jd2=0;jd3=1; sb=1;jb=0; led=0; } //Elevator goes up
}
if(lch23==1)
{
if(jylc<=2)
{ jd3=0;jd2=1; sb=0;jb=1; led=1; } //Elevator descends
if(jylc>=3)
{ jd2=0;jd3=1; sb=1;jb=0; led=0; } //Elevator goes up
}
if(lch34==1)
{
if(jylc<=3)
{ jd3=0;jd2=1; sb=0;jb=1; led=1; } //Elevator descends
if(jylc>=4)
{ jd2=0;jd3=1; sb=1;jb=0; led=0; } //Elevator goes up
}
}
if(lch!=lch1||fg2==1)
{
fg2=0;
switch(lch)
{
case 1:
{
for(i=0;i<8;i++)
{
SCL=0;
Delay(1);
if(i==0||i==7)
SDA=1;
else
SDA=0;
SCL=1;
Delay(1);
}
} break;
case 2:
{
for(i=0;i<8;i++)
{
SCL=0;
Delay(1);
if(i==2||i==7)
SDA=0;
else
SDA=1;
SCL=1;
Delay(1);
}
} break;
case 3:
{
for(i=0;i<8;i++)
{
SCL=0;
Delay(1);
if(i==2||i==4)
SDA=0;
else
SDA=1;
SCL=1;
Delay(1);
}
} break;
case 4:
{
for(i=0;i<8;i++)
{
SCL=0;
Delay(1);
if(i==1||i==5||i==4)
SDA=0;
else
SDA=1;
SCL=1;
Delay(1);
}
} break;
}
lch1=lch;
}
}
}
/*------------------------------------------------
Delay function, with input parameter unsigned int t, no return value
unsigned int is used to define an unsigned integer variable, whose value range is
0~65535
------------------------------------------------*/
void Delay(unsigned int t)
{
while(--t);
}
/*------------------------------------------------
Timer initialization subroutine
------------------------------------------------*/
void Init_Timer0(void)
{
TMOD |= 0x01; //Use mode 1, 16-bit timer, use the "|" symbol to avoid being affected when using multiple timers
//TH0=0x00; //Give initial value
//TL0=0x00;
EA=1; //General interrupt is turned on
ET0=1; //Timer interrupt is turned on
TR0=1; //Timer switch is turned on
}
/*------------------------------------------------
Timer interrupt subroutine
------------------------------------------------*/
void Timer0_isr(void) interrupt 1
{
TH0=(65536-5000)/256; //Reassign 5ms
TL0=(65536-5000)%256;
num++;
if(num<20)
{
led1=0;
if(jd2==1&&jd3==1&&mb==0)
led=0;
}
else
{
led1=1;
if(jd2==1&&jd3==1&&mb==0)
led=1;
}
if(mb==1)
{
if(num%10==0)
led=~led;
if(num==200)
led=1;
}
if(num==200)
{
num=0;
num2++;
if(num2==60)
{ num2=0;fg2=1; }
if(tz==0) // Long press the stop button to turn off the main power
num1++;
else
num1=0;
if(num1>2)
jd1=0;
}
}
Previous article:51 single chip microcomputer colorful LED light gradient dimming color adjustment program
Next article:51 single chip microcomputer electronic clock program
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!
- 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
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- 【Project source code】Image display system based on FPGA on-chip ROM
- Problems with the primary absorption clamp circuit in the flyback circuit
- How to use MSO5 series oscilloscope to capture abnormal signals?
- Analysis of interrupt processing of S3C2410 && WinCE6.0
- What is the impedance of a power module?
- I didn’t expect that Musk’s SpaceX manned spacecraft programming used C++ and Python
- ESP32-S2-Saola-1 运行 circuitpython(2)
- Sinlinx A33 realizes LED driver
- Do MCU ADC input pins require series resistors? Why?
- 4.3 inch LCD screen driver