求助,没入门小白求改下程序..
本人就读大学,老师叫做个设计,硬件和仿真都弄好了,C语言不会.(原谅我偷懒了)就找在网上找了个程序,希望能帮改下结构和写法,其他不用变了..因为可以用,只用改下写法和结构就好!.
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit RED_A=P2^0;
sbit YELLOW_A=P2^1;
sbit GREEN_A=P2^2;
sbit RED_B=P2^3;
sbit YELLOW_B=P2^4;
sbit GREEN_B=P2^5;
uchar Flash_Count=0,Operation_Type=1;
//延时
void DelayMS(uint x)
{
uchar i;
while(x--) for(i=0;i<120;i++);
}
void Traffic_Light()
{
switch(Operation_Type)
{
case 1:
RED_A=1;YELLOW_A=1;GREEN_A=0;
RED_B=0;YELLOW_B=1;GREEN_B=1;
DelayMS(2000);
Operation_Type=2;
break;
case 2:
DelayMS(400);
YELLOW_A=~YELLOW_A;GREEN_A=1;
if(++Flash_Count!=10) return; //闪烁5次
Flash_Count=0;
Operation_Type=3;
break;
case 3:
RED_A=0;YELLOW_A=1;GREEN_A=1;
RED_B=1;YELLOW_B=1;GREEN_B=0;
DelayMS(2000);
Operation_Type=4;
break;
case 4:
DelayMS(400);
YELLOW_B=~YELLOW_B;GREEN_B=1;
if(++Flash_Count!=10) return;
Flash_Count=0;
Operation_Type=1;
}
}
void main()
{
while(1) Traffic_Light();
}