An elevator that can go up and down stairs based on 51 single-chip microcomputer control
The simulation schematic diagram is as follows:
The microcontroller source program is as follows:
#include #include #define uint unsigned int #define uchar unsigned char uchar code table[]={0x3f,0x06,0x5b,0x4f}; uchar num,temp,busy,flag,uf,df,ref,now,next,setf,floor; uint tn; sbit start=P1^0; sbit F1=P1^1; sbit F2=P1^2; sbit F3=P1^3; sbit UPI=P1^4; sbit DNI=P1^5; sbit UPO=P1^6; sbit DNO=P1^7; sbit UP1=P3^0; sbit UP2=P3^1; sbit DN2=P3^2; sbit DN3=P3^3; void display(uchar now); void delay(uint z); uchar keyscan(); void pause(); void ocdoor(); void main() { now=1; //initialization flag=1; num=0; P1=0xff; P2=0xfd; P3=0x0f; TMOD=0x01; //Set to timer 0 mode 1 TH0=0X3C; TL0=0XB0; EA=1; //CPU allows interrupts ET0=1; //Open timer 0 interrupt while(1) { display(now); //Display the initial floor if(P2!=0xfc)// Scan if a key is pressed { delay(20); if(P2!=0xfc) { keyscan();} } //************************************ //Analysis program on the first floor while(now==1) { display(now); if(UP2==0||F2==0||DN2==0) { TR0=1;UPI=1;flag=1;floor=2;}//delay(50);UPI=0; start timing to 2 else if(DN3==0||F3==0) { TR0=1; UPO=UPI=0; TR0=1; floor=3; flag=1; } P2=0xfc; if(P2!=0xfc) { delay(20); if(P2!=0xfc) { keyscan();} } } //******************************** //Analysis program on the second floor while(now==2) { display(now); if(UP2==0||DN2==0) TR0=1; if(DN3==0||F3==0) {TR0=1;UPO=0;flag=1;floor=3;}//delay(50);UPI=0; start timing to 2 else if(UP1==0||F1==0) { TR0=1; DNI=0; floor=1; flag=0; } if(DN3==1&&F3==1&&UP1==1&&F1==1&&DN2==1&&floor!=now) P2=0xfc; if(P2!=0xfc) { delay(20); if(P2!=0xfc) { keyscan();} } } //Analysis program on the 3rd floor while(now==3) { display(now); if(DN3==0) TR0=1; if(DN2==0||UP2==0||F2==0) { TR0=1;DNO=0;flag=0;floor=2;} else if(UP1==0||F1==0) { TR0=1; DNO=DNI=0; floor=1; flag=0; } if(DN2==1&&UP2==1&&UP1==1&&DN3==1&&floor!=now) TR0=1; P2=0xfc; if(P2!=0xfc) { delay(20); if(P2!=0xfc) { keyscan();} } } } } //Interrupt service routine void time0() interrupt 1 { tn++; TH0=0X3C;TL0=0XB0;TR0=1;TF0=0; if(tn==40) { tn=0; display(now); if(now==floor) { switch(now) { case 1:TR0=0; pause(); ocdoor(); F1=1; UP1=1; flag=1; start=1; UPI=UPO=DNI=DNO=1; break; case 2:UP2=1; TR0=0; pause(); DN2=1; TR0=0; pause(); F2=1; start=1; TR0=0; UPI=UPO=DNI=DNO=1; break; case 3:TR0=0; pause(); F3=1; DN3=1; flag=0; start=1; UPI=UPO=DNI=DNO=1; break; default:TR0=0;now=1;break; } } else { if(floor if(floor>now&&flag==0) flag=1; if(flag==0) now--; if(flag==1) now++; } } }//**************************************** //Keyboard scanning subroutine uchar keyscan() { P2=0xfe; //Scan the first line temp=P2; temp=temp&0xfc; while(temp!=0xfc) { delay(5); temp=P2; temp=temp&0xfc; while(temp!=0xfc) { temp=P2; switch(temp) { case 0xfa :num=0;start=0;break; case 0xf6 :num=1;F1=0;floor=1;break; case 0xee :num=2;F2=0;floor=2;break; case 0xde :num=3;F3=0;floor=3;break; } while(temp!=0xfc) { temp=P2; temp=temp&0xfc; } } } P2=0xfd; //Scan the second line temp=P2; temp=temp&0xfc; while(temp!=0xfc) { delay(5); temp=P2; temp=temp&0xfc; while(temp!=0xfc) { temp=2; switch(temp) { case 0xf9 :num=4;UP1=0;break; case 0xf5 :num=5;UP2=0;break; case 0xed :num=6;DN2=0;break; case 0xdd :num=7;DN3=0;break; } while(temp!=0xfc) { temp=P2; temp=temp&0xfc; } } } return num; } //****************************************** //Digital tube display function void display(uchar now) ……………………
Previous article:Design of automatic watering greenhouse control system based on single chip microcomputer
Next article:A brief discussion on controlling SG90 servo with single chip microcomputer (principle + programming)
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- 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
- dspIC30f6010a chip CAN communication and data processing
- 【McQueen Trial】McQueen product information
- Solving High-Voltage Current Sensing Design Challenges in HEV/EV
- Has anyone made irregular PCB? Please help
- Car Charger IC
- Several points to note when using SIMD to process multiple data in parallel
- Free evaluation - Topmicro intelligent display module (2) displays a picture
- The resistance of the transistor
- AD18 PCB package drawing does not display when imported
- MOS transistor driving voltage and current