|
windows平臺下的keil開發(fā)環(huán)境開發(fā)的以atmel51單片機(jī)開發(fā)的四層電梯模擬程序與配套的proteus8.0的模擬程序,編譯通過。模擬程序運(yùn)行無誤 。其中包含的資料為 電梯程序c語言和電梯仿真的原理圖
0.png (33.53 KB, 下載次數(shù): 103)
下載附件
2016-11-25 16:00 上傳
單片機(jī)源程序:
- #include <reg52.h>
- #define u8 unsigned char
- unsigned char seg_table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
- unsigned char run,floor;
- bit ud,stop=0;
- sbit P06=P0^6;
- sbit P07=P0^7;
- sbit ulc=P2^0;
- sbit dlc=P2^1;
- sbit start=P2^2;
- sbit alrl=P2^3;
- sbit alrb=P2^4;
- void input()
- {
- run|=((~P0)&0x3f);
- if((P06==0)&&(ud==1))
- run|=0x02;
- if((P06==0)&&(ud==0))
- run|=0x04;
- if((P07==0)&&(ud==1))
- run|=0x08;
- if((P07==0)&&(ud==0))
- run|=0x10;
- }
- void delay(int j)
- {
- int i;
- for(;j>0;j--)
- {
- input();
- for(i=200;i>0;i--)
- {
- if(stop==1)
- break;
- }
- if(stop==1)
- break;
- }
- }
- void StepMotor(bit a,u8 b)
- {
- u8 x=0x80,i;
- if(a==1)
- {
- ulc=0;
- dlc=1;
- for(i=0;i<b;i++)
- {
- if(x==0x10)
- x=0x80;
- else
- x=x/2;
- P3|=(x&0xf0);
- delay(100);
- }
- }
- else
- {
- ulc=1;
- dlc=0;
- for(i=0;i<b;i++)
- {
- if(x==0x80)
- x=0x10;
- else
- x=x*2;
- P3|=(x&0xf0);
- delay(100);
- }
- }
- }
- void alarm()
- {
- alrl=0;
- while(1)
- {
- alrb = ~alrb;
- delay(200);
- }
- }
- void main()
- {
- floor=1;
- P1=seg_table[floor];
- P0=0xff;
- ud=1;
- run=0;
- ulc=1;
- dlc=1;
-
- alrl=1;
- alrb=1;
- TCON=0x01; //打開外部中斷0,并設(shè)置為下降沿觸發(fā)
- IE=0x81; //開總中斷
- while(1)
- {
- while(start==1)
- {
- P1=seg_table[10];
- ulc=1;
- dlc=1;
- }
- input();
- switch(floor)
- {
- case 1: //1
- {
- P1=seg_table[floor];
-
- if((run&0x01)==0x01)
- {
- delay(600);
- run&=0xfe;
- }
- if((run&0x3e)!=0)
- {
- StepMotor(1,5);
- floor=2;
- ud=1;
- }
- else
- {
- ulc=1;
- dlc=1;
- }
- } break;
- case 2:
- {
- P1=seg_table[floor];
- if(ud==1) //2上
- {
- if((run&0x02)==0x02)
- {
- delay(600);
- run&=0xfd;
- }
-
- if((run&0x38)!=0)
- {
- StepMotor(1,5);
- floor=3;
- }
- else
- {
- ud=0;
- ulc=1;
- dlc=1;
- }
- }
- else //2下
- {
- if((run&0x04)==0x04)
- {
- delay(600);
- run&=0xfb;
- }
-
- if((run&0x01)!=0)
- {
- StepMotor(0,5);
- floor=1;
- }
- else
- {
- ud=1;
- ulc=1;
- dlc=1;
- }
- }
-
- } break;
- case 3:
- {
- P1=seg_table[floor];
- if(ud==1) //3上
- {
- if((run&0x08)==0x08)
- {
- delay(600);
- run&=0xf7;
- }
-
- if((run&0x20)!=0)
- {
- StepMotor(1,5);
- floor=4;
- }
- else
- {
- ud=0;
- ulc=1;
- dlc=1;
- }
- }
- else //3下
- {
- if((run&0x10)==0x10)
- {
- delay(600);
- run&=0xef;
- }
-
- if((run&0x07)!=0)
- {
- StepMotor(0,5);
- floor=2;
- }
- else
- {
- ud=1;
- ulc=1;
- dlc=1;
- }
- }
- } break;
- case 4:
- {
- P1=seg_table[floor];
- if((run&0x20)==0x20)
- {
- delay(600);
- run&=0xdf;
- }
-
- if((run&0x1f)!=0)
- {
- StepMotor(0,5);
- floor=3;
- ud=0;
- }
- else
- {
- ulc=1;
- dlc=1;
- }
- }
- }
-
- if(stop==1)
- {
- P1=seg_table[10];
- ulc=1;
- dlc=1;
- alarm();
- }
-
- }
- }
- void int0() interrupt 0
- {
- stop=1;
- }
復(fù)制代碼
0.png (61.84 KB, 下載次數(shù): 99)
下載附件
2016-11-25 16:01 上傳
所有資料打包下載:
四層電梯模擬程序與proteus仿真.rar
(106.52 KB, 下載次數(shù): 225)
2016-11-25 15:55 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|