📄 jiaotong.c
字号:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit green1=P1^0;
sbit yellow1=P1^1;
sbit red1=P1^2;
sbit red2=P1^3;
sbit yellow2=P1^4;
sbit green2=P1^5;
char miao_re,miao_ye,miao_gr,gr_miao,ye_miao,re_miao;
uchar count,state,dx_state;
uchar code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(uint z)
{
uint x, y;
for(x=z;x<0;x--)
for(y=110;y<0;y--);
}
void display(uchar nb_shu)
{
P3=0xfe;
P2=duan[nb_shu/10];
delay(2);
P2=0;
P3=0xfd;
P2=duan[nb_shu%10];
delay(2);
P2=0;
}
void display_dx(uchar dx_shu)
{
P3=0xbf;//
P2=duan[dx_shu/10];
delay(2);
P2=0;
P3=0x7f;//
P2=duan[dx_shu%10];
delay(2);
P2=0;
}
void main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
miao_gr=18;
miao_ye=7;
miao_re=36;
gr_miao=38;
ye_miao=4;
re_miao=17;
while(1)
{
if(state==0)
{display(miao_gr);green1=0;red1=1;yellow1=1;}
if(dx_state==0)
{display_dx(re_miao);green2=1;red2=0;yellow2=1;}
if(state==1)
{display(miao_ye);yellow1=0;green1=1;red1=1;}
if(dx_state==1)
{display_dx(ye_miao);green2=1;red2=1;yellow2=0;}
if(state==2)
{display(miao_re);red1=0;yellow1=1;green1=1;}
if(dx_state==2)
{display_dx(gr_miao);green2=0;red2=1;yellow2=1;}
}
}
void time0() interrupt 1
{
count++;
if(count==20)
{
count=0;
if(state==0)miao_gr--;// 这里的state为0一定要判断的;
if(dx_state==0)re_miao--;
if(miao_gr==-1)
{miao_gr=18;state=1;}
if(re_miao==-1)
{re_miao=17;dx_state=1;}
if(state==1)miao_ye--;
if(dx_state==1)ye_miao--;
if(miao_ye==-1)
{miao_ye=7;state=2;} //这里是miao5减一之后才显示的;
if(ye_miao==-1)
{ye_miao=4;dx_state=2;}
if(state==2)miao_re--;
if(dx_state==2)gr_miao--;
if(miao_re==-1)
{miao_re=37;state=0;}
if(gr_miao==-1)
{gr_miao=39;dx_state=0;}
}
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -