hc6800板子作交通灯<求修改>
时间:10-02
整理:3721RD
点击:
要红灯亮15s,黄灯6s,绿灯10s。且每个最后五秒亮的灯都闪烁并有蜂鸣器声音。
#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit red=P1^0;
sbit yellow=P1^1;
sbit green=P1^2;
sbit math1=P2^2;
sbit math2=P2^3;
sbit math3=P2^4;
sbit beep=P2^5;
uchar code table[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
uchar aa,num,num1,a;
uint LedOut[2];
void delay(uint i)
{
char j;
for(i; i > 0; i--)
for(j = 200; j > 0; j--);
}
void main()
{
uchar i;
TMOD=0x01,TH0=0x3c,TL0=0xb0, EA=1;
ET0=1;
TR0=1;
num=0;
red=0;yellow=1;green=1;
while(1)
{
num1=num;
LedOut[0]=table[num1/10];
LedOut[1]=table[num1%10];
for( i=0; i<2; i++)
{
P0 = LedOut[i];
switch(i)
{
case 0:math1=0; math2=0; math3=0; break;
case 1:math1=1; math2=0; math3=0; break;
}
delay(10);
}
}
}
void timer0(void) interrupt 1
{
TH0=0x3c,TL0=0xb0;
aa++;
if(aa == 10)
{
aa = 0;
num++;
if(num >=10&&num<=15){ red = ~red;beep=0;}
else if(a==2&&num>=16)
{
beep=1;
red = 1;
yellow = 0;
green = 1;
a=0;
while (num>17&&num<21) yellow=~yellow;
}
if(num >=21&&num<=31)
{
red = 1;
yellow = 1;
green = 0;
num = 0;
a++;
}
}
}
#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit red=P1^0;
sbit yellow=P1^1;
sbit green=P1^2;
sbit math1=P2^2;
sbit math2=P2^3;
sbit math3=P2^4;
sbit beep=P2^5;
uchar code table[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
uchar aa,num,num1,a;
uint LedOut[2];
void delay(uint i)
{
char j;
for(i; i > 0; i--)
for(j = 200; j > 0; j--);
}
void main()
{
uchar i;
TMOD=0x01,TH0=0x3c,TL0=0xb0, EA=1;
ET0=1;
TR0=1;
num=0;
red=0;yellow=1;green=1;
while(1)
{
num1=num;
LedOut[0]=table[num1/10];
LedOut[1]=table[num1%10];
for( i=0; i<2; i++)
{
P0 = LedOut[i];
switch(i)
{
case 0:math1=0; math2=0; math3=0; break;
case 1:math1=1; math2=0; math3=0; break;
}
delay(10);
}
}
}
void timer0(void) interrupt 1
{
TH0=0x3c,TL0=0xb0;
aa++;
if(aa == 10)
{
aa = 0;
num++;
if(num >=10&&num<=15){ red = ~red;beep=0;}
else if(a==2&&num>=16)
{
beep=1;
red = 1;
yellow = 0;
green = 1;
a=0;
while (num>17&&num<21) yellow=~yellow;
}
if(num >=21&&num<=31)
{
red = 1;
yellow = 1;
green = 0;
num = 0;
a++;
}
}
}