预览加载中,请您耐心等待几秒...
1/6
2/6
3/6
4/6
5/6
6/6

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

基于51单片机的六层电梯c语言矩阵键盘控制系统基于51单片机的六层电梯c语言矩阵键盘控制系统基于51单片机的六层电梯c语言矩阵键盘控制系统#include〈reg51.h〉#defineMAXFLOOR6unsignedcharcodeLEDCODES[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d};sbitLEDUP=P3^6;sbitLEDDOWN=P3^7;bitDIRECTION=1,STOP=0;unsignedcharCURFLOOR=1;unsignedcharDESTFLOOR=1;unsignedcharRUN=1;unsignedinttimer1=0,timer2=0;unsignedcharCALLFLOORUP[7]={0,0,0,0,0,0,0};unsignedcharCALLFLOORDOWN[7]={0,0,0,0,0,0,0};unsignedcharCALLFLOOR[7]={0,0,0,0,0,0,0};unsignedcharkeyscan(void);unsignedcharkey;voidreadarray(void);voidSELECTNEXT();voidstep(bitDIRECTION);voidDELAY(unsignedintZ);voidDELAY2(unsignedintS);voidJUDGESIT();voidmain(void){P0=LEDCODES[1];TH0=0x3C;TL0=0xB0;TMOD=0x01;ET0=1;EA=1;EX0=1;IT0=1;while(1){if(!RUN&&!STOP){SELECTNEXT();step(DIRECTION);}elseif(STOP){timer2=0;TR0=1;while(timer2<100&&STOP);TR0=0;timer2=0;STOP=0;}return;}}voidSELECTNEXT(){charn;if(CURFLOOR==MAXFLOOR){DIRECTION=0;}elseif(CURFLOOR==1){DIRECTION=1;}if(DIRECTION==0){if(CALLFLOORDOWN[CURFLOOR]){CALLFLOORDOWN[CURFLOOR]=0;STOP=1;return;}for(n=CURFLOOR-1;n〉=1;n——)if(CALLFLOORDOWN[n]){DESTFLOOR=n;return;}for(n=0;n<CURFLOOR;n++)if(CALLFLOORUP[n]){DESTFLOOR=n;return;}DIRECTION=1;for(n=CURFLOOR+1;n<=MAXFLOOR;n++)if(CALLFLOORUP[n]){DESTFLOOR=n;return;}for(n=MAXFLOOR;n>CURFLOOR;n——)if(CALLFLOORDOWN[n]){DESTFLOOR=n;return;}}else{if(CALLFLOORUP[CURFLOOR]){CALLFLOORUP[CURFLOOR]=0;STOP=1;return;}for(n=CURFLOOR+1;n<=MAXFLOOR;n++)if(CALLFLOORUP[n]){DESTFLOOR=n;return;}for(n=MAXFLOOR;n〉CURFLOOR;n——)if(CALLFLOORDOWN[n]){DESTFLOOR=n;return;}DIRECTION=0;for(n=CURFLOOR-1;n〉=1;n——)if(CALLFLOORDOWN[n]){DESTFLOOR=n;return;}for(n=1;n〈=CURFLOOR;n++)if(CALLFLOORDOWN[n]){DESTFLOOR=n;return;}}}voidstep(bitDIRECTION){if(DESTFLOOR==CURFLOOR)return;elseif(!RUN){RUN=1;DELAY(50);if(DIRECTION==1){LEDUP=0;LEDDOWN=1;}else{LEDUP=1;LEDDOWN=0;}timer1=0;TR0=1;}}voidDELAY(unsignedintZ){unsignedintX,Y;for(X=Z;X〉0;X-—)for(Y=125;Y>0;Y—-);}voidtimer0_int()interrupt1{TH0=0x3C;TL0=0xB0;timer1++;timer2++;if(RUN){if(timer1==20){timer1=0;if(DIRECTION){CURFLO