求助!大佬帮我解释解释这些具体程序都是什么意思,急!!!!一个c51交通灯的仿真 5
#include<reg51.h>#include<stdio.h>#defineucharunsignedcharucharseg[]={0x3f,0x06,0x5b,...
#include<reg51.h>
#include<stdio.h>
#define uchar unsigned char
uchar seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar stateFlag;//当前工作模式的标志 为1时80s 为0 时 60s
uchar flag;//统计一秒钟的标志
uchar num1=0;//数码管1显示的数
uchar num2=0;//数码管2显示的数
sbit Led1_G = P1^0;
sbit Led1_Y = P1^1;
sbit Led1_R = P1^2;
sbit Led2_G = P1^3;
sbit Led2_Y = P1^4;
sbit Led2_R = P1^5;
void delay(int a);
void showNum();
void main(){
Led1_R = 0;
Led1_G = 0;
Led1_Y = 0;
Led2_R = 0;
Led2_G = 0;
Led2_Y = 0;
stateFlag = 0;
flag = 0;
TMOD=0x10;
TH1= 55536/256;
TL1=55536%256;
num1=20;
num2=23;
Led1_R = 0;
Led1_G = 1;
Led1_Y = 0;
Led2_R = 1;
Led2_G = 0;
Led2_Y = 0;
EA=1;
ET1=1;
TR1=1;
while(1){
showNum();
}
}
void int_T1(void) interrupt 3 {
flag++;
if(flag==100){
num1--;
num2--;
flag=0;
}
if(stateFlag==0){
if(num1==0){
Led1_R = 0;
Led1_G = 0;
Led1_Y = 1;
Led2_R = 1;
Led2_G = 0;
Led2_Y = 0;
num1=3;
}
if(num2==0){
num1=33;
num2=30;
Led1_R = 1;
Led1_G = 0;
Led1_Y = 0;
Led2_R = 0;
Led2_G = 1;
Led2_Y = 0;
stateFlag=1;
}
}
else{
if(num2==0){
Led1_R = 1;
Led1_G = 0;
Led1_Y = 0;
Led2_R = 0;
Led2_G = 0;
Led2_Y = 1;
num2=3;
}
if(num1==0){
num1=20;
num2=23;
Led1_R = 0;
Led1_G = 1;
Led1_Y = 0;
Led2_R = 1;
Led2_G = 0;
Led2_Y = 0;
stateFlag=0;
}
}
TH1= 55536/256;
TL1=55536%256;
}
void delay(int a){
uchar b;
for(;a>0;a--){
for(b=0;b<255;b++);
}
}
void showNum(){
P2=0x0a;
P0=seg[num1/10];
P3=seg[num2/10];
delay(10);
P2=0x05;
P0=seg[num1%10];
P3=seg[num2%10];
delay(10);
} 展开
#include<stdio.h>
#define uchar unsigned char
uchar seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar stateFlag;//当前工作模式的标志 为1时80s 为0 时 60s
uchar flag;//统计一秒钟的标志
uchar num1=0;//数码管1显示的数
uchar num2=0;//数码管2显示的数
sbit Led1_G = P1^0;
sbit Led1_Y = P1^1;
sbit Led1_R = P1^2;
sbit Led2_G = P1^3;
sbit Led2_Y = P1^4;
sbit Led2_R = P1^5;
void delay(int a);
void showNum();
void main(){
Led1_R = 0;
Led1_G = 0;
Led1_Y = 0;
Led2_R = 0;
Led2_G = 0;
Led2_Y = 0;
stateFlag = 0;
flag = 0;
TMOD=0x10;
TH1= 55536/256;
TL1=55536%256;
num1=20;
num2=23;
Led1_R = 0;
Led1_G = 1;
Led1_Y = 0;
Led2_R = 1;
Led2_G = 0;
Led2_Y = 0;
EA=1;
ET1=1;
TR1=1;
while(1){
showNum();
}
}
void int_T1(void) interrupt 3 {
flag++;
if(flag==100){
num1--;
num2--;
flag=0;
}
if(stateFlag==0){
if(num1==0){
Led1_R = 0;
Led1_G = 0;
Led1_Y = 1;
Led2_R = 1;
Led2_G = 0;
Led2_Y = 0;
num1=3;
}
if(num2==0){
num1=33;
num2=30;
Led1_R = 1;
Led1_G = 0;
Led1_Y = 0;
Led2_R = 0;
Led2_G = 1;
Led2_Y = 0;
stateFlag=1;
}
}
else{
if(num2==0){
Led1_R = 1;
Led1_G = 0;
Led1_Y = 0;
Led2_R = 0;
Led2_G = 0;
Led2_Y = 1;
num2=3;
}
if(num1==0){
num1=20;
num2=23;
Led1_R = 0;
Led1_G = 1;
Led1_Y = 0;
Led2_R = 1;
Led2_G = 0;
Led2_Y = 0;
stateFlag=0;
}
}
TH1= 55536/256;
TL1=55536%256;
}
void delay(int a){
uchar b;
for(;a>0;a--){
for(b=0;b<255;b++);
}
}
void showNum(){
P2=0x0a;
P0=seg[num1/10];
P3=seg[num2/10];
delay(10);
P2=0x05;
P0=seg[num1%10];
P3=seg[num2%10];
delay(10);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询