|
原程序如下,自己写的,有错的地方,但不知道哪里错了,求高手支招
编译时出错了。。。怎么办?怎么办?
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
//南北向指示灯
sbit RED_A=P0^0;
sbit YELLOW_A=P0^1;
sbit GREEN_A=P0^2;
//东西向指示灯
sbit RED_B=P0^3;
sbit YELLOW_B=P0^4;
sbit GREEN_B=P0^5;
//数码管显示
uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
sbit K1=P3^6;bit Key_State=1;
//数码管显示延时
void DelayMS(uint ms)
{
uchar t;
while(ms--) for(t=0;t<120;t++);
}
//延时倍数,闪烁次数,操作类型变量
uchar Key_Flag_Idx=0,Time_Count_1=0,Time_Count_2=0,Second_Count=0x19,Flash_Count=0,Operation_Type=1;
//定时器0 中断函数
void T0_INT() interrupt 1
{
TL0=0xB0;
TH0=0x3C;
switch(Operation_Type)
{
case 1: //东西向绿灯与南北向红灯亮20s
RED_A=1;YELLOW_A=0;GREEN_A=0;
RED_B=0;YELLOW_B=0;GREEN_B=1;
if(++Time_Count_1!=400) return;//20s (400*50ms) 切换
Time_Count_1=0;
Operation_Type=2;
break;
case 2: //东西向绿灯闪烁3s
if(++Time_Count_1!=10) return;
Time_Count_1=0;
GREEN_B=~GREEN_B;RED_A=1;
if(++Flash_Count!=6) return; //闪烁
Flash_Count=0;
Operation_Type=3;
break;
case 3: //东西向黄灯亮2s,绿灯熄灭
GREEN_B=0;YELLOW_B=1;RED_A=1;
if(++Time_Count_1!=40) return; //2s(40*50ms)切换
Time_Count_1=0;
Operation_Type=4;
break;
case 4: //东西向黄灯与南北向红灯熄灭同时南北向绿灯与东西向红灯亮20s
RED_A=0;YELLOW_A=0;GREEN_A=1;
RED_B=1;YELLOW_B=0;GREEN_A=0;
if(++Time_Count_1!=400) return;//20s
Time_Count_1=0;
Operation_Type=5;
break;
case 5: //南北向绿灯闪烁3s
if(++Time_Count_1!=10) return;
Time_Count_1=0;
GREEN_A=~GREEN_A;RED_B=1;
if(++Flash_Count!=6) return; //闪烁
Flash_Count=0;
Operation_Type=6;
break;
case 6: //南北向黄灯亮2s,绿灯熄灭
GREEN_A=0;YELLOW_A=1;RED_B=1;
if(++Time_Count_1!=40) return; //2s(40*50ms)切换
Time_Count_1=0;
Operation_Type=1;
break;
}
}
void T1_TNT() interrupt 1
{
TH1=0x3C;
TL1=0xB0;
while(1)
{
if(++Time_Count_2!=20) return;
Time_Count_2=0;
Second_Count--;
P2=DSY_CODE[Second_Count/10];
P1=DSY_CODE[Second_Count%10];
if(Second_Count==00)
Second_Count=0x19; //减到0后自动恢复初值25s
}
}
void Key_Event_Handle()
{
if(Key_State==0)
{
Key_Flag_Idx=(Key_Flag_Idx+1)%2;
switch(Key_Flag_Idx)
{
case 0: EA=1;ET0=1;IE=0x81;IT0=1;IT1=1;TR0=1;TR1=1;break;//第一次按键启动交通信号灯,显示倒计时
case 1: EA=0;TR0=0;TR1=0;Time_Count_1=0;Time_Count_2=0;Second_Count=0x19;//第二次按键关闭交通信号灯和倒计时显示
}
}
}
//主程序
void main()
{
P1=0x00;
P2=0x00;
TMOD=0x11; //定时器T0 方式1,定时器T1 方式1
while(1)
{
if(Key_State!=K1)
{
DelayMS(10);
Key_State=K1;
Key_Event_Handle();
}
}
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|