#include "main.h"
int main()
{
uchar Floor =1;
char temp; //当前的楼层数
bit Dir = 0; //电梯的运行方向,上1下0
char Terminal =1; //本阶段电梯的运行终点
while(1)
{
temp = Read_Key();
if (temp > 0)
Terminal = temp;
if(Terminal >Floor)
{
Dir = 1;
UP = 0;
DOWN = 1;
MOTOR0 = 0;
MOTOR1 = 1;
}
if(Terminal
{
Dir = 0;
UP = 1;
DOWN = 0;
MOTOR0 = 1;
MOTOR1 = 0;
}
if(Terminal ==Floor)
{
DOWN = 1;
UP = 1;
MOTOR0 = 1;
MOTOR1 = 1;
BUZZER = 0;
if((Terminal!=1) &&(temp < 0))
{
Terminal= 1;
Dir= 0;
}
}
Display(Floor);
#if 1
if(Flag_NextFloor)
{
Flag_NextFloor= 0; //清零标志位
if(Dir&& (Floor < Terminal))
Floor++;
elseif((!Dir) && (Floor > Terminal))
Floor--;
}
#endif
}
}
void Display(uchar Dat) //数码管显示楼层
{
P0 = ~Table[Dat]; //楼层从1开始
// P3 = 1;
P3 = (1<
}
void Timer_Init()
{
EA = 1; //开中断
TMOD = 0x01; //定时器模式设定
TH0 = (65536 - 50000) /256; //定时器装载初值
TL0 = (65536 - 50000) %256; //初值50mS
ET0 = 1; //开定时器0中断
TR0 = 1; //启动定时器0
}
char Read_Key(void) //读取需要操作的楼层
{
char i = -1;
if(!KEY7)
i =5;
else if((!KEY6)||(!KEY5))
i = 4;
else if((!KEY4)||(!KEY3))
i = 3;
else if((!KEY2)||(!KEY1))
i = 2;
else if(!KEY0)
i = 1;
return i;
}
void Timer0() interrupt 1
{
static uchar num;
TH0 = (65536 - 50000) /256; //定时器装载初值
TL0 = (65536 - 50000) % 256; //初值50mS
num++;
if(num > TIME_50MS)
{
num = 0;
Flag_NextFloor =1; //计数时间到,进入下一层
}