51 单片机
时间:10-02
整理:3721RD
点击:
#include"reg52.h"
sbit A_YELLOW=P1^0;
sbit A_GREEN=P1^1;
sbit A_RED=P1^2;
sbit B_YELLOW=P1^3;
sbit B_GREEN=P1^4;
sbit B_RED=P1^5;
void delay()
{
int i,j;
for(i=0;i<50;i++)
{
for(j=0;j<10;j++)
;
}
}
char tab_duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int red_time=25;
int green_time=20;
int yellow_time=5;
int a,b;
int mode=0;
void display1(int a,int b)
{
P2=0xff;
P0=tab_duan[a/10];
P2=0x7f;
delay();
P2=0xff;
P0=tab_duan[a%10];
P2=0xbf;
delay();
P2=0xff;
P0=tab_duan[b/10];
P2=0xfd;
delay();
P2=0xff;
P0=tab_duan[b%10];
P2=0xfe;
delay();
}
void main()
{ int k,i;
P1=0xff;
mode=0;
a=red_time;
b=green_time;
k=green_time;
A_RED=0;
B_GREEN=0;
while(1)
{
for(i=0;i<30;i++)
{
display1(a,b);
}
if(k==0)
{
switch (mode)
{
case 0:
mode=1;
b=yellow_time;
k=b;
B_GREEN=1;
B_YELLOW=0;
break;
case 1:
mode=2;
a=green_time;
b=red_time;
B_RED=0;
B_YELLOW=1;
A_GREEN=0;
A_RED=1;
k=a;
break;
case 2:
mode=3;
a=yellow_time;
k=a;
A_GREEN=1;
A_YELLOW=0;
break;
case 3:
mode=0;
a=red_time;
b=green_time;
k=b;
A_YELLOW=1;
B_RED=1;
A_RED=0;
B_GREEN=0;
break;
}
}
a--;
b--;
k--;
}
}
sbit A_YELLOW=P1^0;
sbit A_GREEN=P1^1;
sbit A_RED=P1^2;
sbit B_YELLOW=P1^3;
sbit B_GREEN=P1^4;
sbit B_RED=P1^5;
void delay()
{
int i,j;
for(i=0;i<50;i++)
{
for(j=0;j<10;j++)
;
}
}
char tab_duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int red_time=25;
int green_time=20;
int yellow_time=5;
int a,b;
int mode=0;
void display1(int a,int b)
{
P2=0xff;
P0=tab_duan[a/10];
P2=0x7f;
delay();
P2=0xff;
P0=tab_duan[a%10];
P2=0xbf;
delay();
P2=0xff;
P0=tab_duan[b/10];
P2=0xfd;
delay();
P2=0xff;
P0=tab_duan[b%10];
P2=0xfe;
delay();
}
void main()
{ int k,i;
P1=0xff;
mode=0;
a=red_time;
b=green_time;
k=green_time;
A_RED=0;
B_GREEN=0;
while(1)
{
for(i=0;i<30;i++)
{
display1(a,b);
}
if(k==0)
{
switch (mode)
{
case 0:
mode=1;
b=yellow_time;
k=b;
B_GREEN=1;
B_YELLOW=0;
break;
case 1:
mode=2;
a=green_time;
b=red_time;
B_RED=0;
B_YELLOW=1;
A_GREEN=0;
A_RED=1;
k=a;
break;
case 2:
mode=3;
a=yellow_time;
k=a;
A_GREEN=1;
A_YELLOW=0;
break;
case 3:
mode=0;
a=red_time;
b=green_time;
k=b;
A_YELLOW=1;
B_RED=1;
A_RED=0;
B_GREEN=0;
break;
}
}
a--;
b--;
k--;
}
}
what do you want to say?
我要积分
好歹给个说明,坛里都这样,那还怎么看
哈哈
哈哈
这是什么
实在没搞懂
呵呵。
难道这就是程序员版的天书,,,,,,
这是什么的程序?