Proteus simulation and program of elevator that can go up and down stairs based on 51 single chip microcomputer

Publisher:一直333Latest update time:2019-11-25 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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             flag=0;

        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)

……………………


Reference address:Proteus simulation and program of elevator that can go up and down stairs based on 51 single chip microcomputer

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)

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号