#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit key0=P0^0;
sbit key1=P0^1;
sbit key2=P0^2;
sbit key3=P0^3;
sbit b1=P0^4;
sbit k1=P2^4;
sbit k2=P2^3;
sbit k3=P2^2;
sbit k4=P2^1;
sbit k5=P2^0;
void delay_ms (uint z)
{
uint x,y;
for (x=z;x>0;x--)
for (y=110;y>0;y--);
}
void timer()
{
TMOD|=0x01;
TH0=0xd8;
TL0=0xf0;
IE=0X82;
ET0=1;
TR0=1;
}
uchar ControlFlag=0;
void EXTI1_IRQHandler(void)
{
uchar data i;
delay_ms(30);//消抖
if(key0 == 1)
{
#ifdef _DEVICEFLAG_
for(i=0;i<2;i++)
{
delay_ms(1000);
}
if(key0 == 0) //按键2
{
ControlFlag = 2;
}
else if(key0 == 1)
{
ControlFlag = 1;
}
#else
if(key0 == 1)
{
ControlFlag = 1;
}
#endif
}
TL0=0; //清除LINE1上的中断标志位
}
//外部中断2服务程序 复位开关2
void EXTI2_IRQHandler(void)
{ uchar data i;
delay_ms(30);
if(key1 == 1)
{
for(i=0;i<2;i++)
{
delay_ms(1000);
}
if(key1 == 0)
{
ControlFlag = 6;
}
else if (key1 == 1)
{
ControlFlag = 5;
}
}
TL0=0; //清除LINE2上的中断标志位
}
//外部中断3服务程序 复位开关1
void EXTI3_IRQHandler(void)
{ uchar data i;
delay_ms(30);
if(key2 == 1)
{
for(i=0;i<2;i++)
{
delay_ms(1000);
}
if(key2 == 0)
{
ControlFlag = 4;
}
else if(key2 == 1)
{
ControlFlag = 3;
}
}
TL0=0; //清除LINE3上的中断标志位
}
main()
{
k1=0;
k2=0;
k3=0;
k4=0;
k5=0;
while(1)
{
#ifdef _DEVICEFLAG_
if((b1==1)||(key3 == 1))
{
k5 = 1;
}
else if ((b1 == 0)&&(key3 == 0))
{
k5 = 0;
}
/*************************************************************
*************************************************************/
#ifdef _DEVICEFLAG_
case 1: //机器总开关长按
if(key3 == 0) //服务器+5V为0时
{
if(b1 == 0) //K1断开时
{
k1 = 1;
k4 = 1;
delay_ms(1000);
k4 = 0;
}
else if (b1== 1) //K1闭合时
{
k1 = 0;
}
}
else if(key3 ==1) //服务器+5V为1时
{
if(b1 == 0) //K1断开时
{
k4 =1;
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
k4 = 0;
}
else if(b1 ==1) //K1闭合时
{
k4 = 1;
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
k1= 0;
delay_ms(1000);
k4 = 0;
}
}
ControlFlag = 0;
break;
case 2: //机器总开关短按
if(key3 == 0) //服务器+5V为0时
{
if(b1 ==0) //K1为断开时
{
k1 = 1;
k4 = 1;
delay_ms(1000);
k4 = 0;
}
else if (b1 == 1) //K1为闭合时
{
k4 = 1;
delay_ms(1000);
k4 = 0;
}
}
else if(key3 ==1) //服务器+5V为1时
{
if(b1 == 0) //K1断开时
{
k1 = 1;
}
else if(b1 ==1) //K1闭合时
{
;
}
}
ControlFlag = 0;
break;
case 3: //复位开关1长按
if(b1 == 1) //K1闭合时
{
k2 = 1;
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
k2 = 0;
}
ControlFlag = 0;
break;
case 4: //复位开关1短按
if(b1 == 1) //K1闭合时
{
k1 = 0;
delay_ms(1000);
k1 = 1;
}
ControlFlag = 0;
break;
case 5: //复位开关2长按
if(key3== 1)
{
k3= 1;
delay_ms(1000);
k3 = 0;
}
ControlFlag = 0;
break;
case 6: //复位开关2短按
if(key3 == 1)
{
k3 = 1;
delay_ms(1000);
k3 = 0;
}
ControlFlag = 0;
break;
}
}
这是错误:
compiling 112.c...
112.C(32): warning C280: 'i': unreferenced local variable
112.c(234): warning C316: unterminated conditionals
112.C(234): error C141: syntax error near ''
112.c - 1 Error(s), 2 Warning(s).
究竟哪点错了啊 |