标题:
这个程序最后哪里有错啊?第一次弄不懂
[打印本页]
作者:
锐姐吃薯包籺
时间:
2019-9-27 20:30
标题:
这个程序最后哪里有错啊?第一次弄不懂
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit RED_A=P0^0;
sbit YELLOW_A=P0^1;
sbit GREEN_A=P0^2;
sbit RED_B=P0^3;
sbit YELLOW_B=P0^4;
sbit GREEN_B=P0^5;
uchar Flash_Count=0;
uchar num=0;
Operation_Type=1;
void DelayMS(uint x);
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;
Operation_Type=2;
for(num=9;num>2;--num)
{
P1=tab[num];
DelayMS(1000);
}
break;
case 2:
for(Flash_Count=1;Flash_Count<=10;Flash_Count++)
{
P1=tab[num];
DelayMS(200);
YELLOW_A=~YELLOW_A;
if(Flash_Count%5==0)num--;
}
Operation_Type=3;
break;
case 3:
RED_A=0;YELLOW_A=1;GREEN_A=1;
RED_B=1;YELLOW_B=1;GREEN_B=0;
for(num=7;num>0;num--)
{
P1=tab[num];
DelayMS(1000);
}
Operation_Type=4;
break;
case 4:
num=2;
for(Flash_Count=1;Flash_Count<=10;Flash_Count++)
{
P1=tab[num];
DelayMS(200);
YELLOW_B=~YELLOW_B;
if(Flash_Count%5==0)num--;
}
Operation_Type=1;
break;
}
}
void main()
{
while(1)
{
Traffic_lignt ();
}
}
作者:
没有你
时间:
2019-9-27 22:23
Operation_Type这个变量没有定义?
作者:
累不死的狗
时间:
2019-9-27 23:25
第一个问题是你 Traffic_lignt ();抄错了,第二个问题是void DelayMS(uint x);这个没写子函数
作者:
累不死的狗
时间:
2019-9-27 23:26
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit RED_A=P0^0;
sbit YELLOW_A=P0^1;
sbit GREEN_A=P0^2;
sbit RED_B=P0^3;
sbit YELLOW_B=P0^4;
sbit GREEN_B=P0^5;
uchar Flash_Count=0;
uchar num=0;
Operation_Type=1;
void DelayMS(uint x);
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;
Operation_Type=2;
for(num=9;num>2;--num)
{
P1=tab[num];
DelayMS(1000);
}
break;
case 2:
for(Flash_Count=1;Flash_Count<=10;Flash_Count++)
{
P1=tab[num];
DelayMS(200);
YELLOW_A=~YELLOW_A;
if(Flash_Count%5==0)num--;
}
Operation_Type=3;
break;
case 3:
RED_A=0;YELLOW_A=1;GREEN_A=1;
RED_B=1;YELLOW_B=1;GREEN_B=0;
for(num=7;num>0;num--)
{
P1=tab[num];
DelayMS(1000);
}
Operation_Type=4;
break;
case 4:
num=2;
for(Flash_Count=1;Flash_Count<=10;Flash_Count++)
{
P1=tab[num];
DelayMS(200);
YELLOW_B=~YELLOW_B;
if(Flash_Count%5==0)num--;
}
Operation_Type=1;
break;
}
}
void main()
{
while(1)
{
Traffic_light ();
}
}
void DelayMS(uint x)
{
for(x=0;x<1000;x++)
{
}
}
作者:
cuihaodianzi
时间:
2019-9-27 23:28
Operation_Type 没有定义
有效行 第 13 行 Operation_Type=1;
改为 unsigned char Operation_Type=1;
或 uchar Operation_Type=1;
作者:
csmyldl
时间:
2019-9-28 02:13
要说明什么错误现象呀
作者:
wulin
时间:
2019-9-28 05:19
错误1.主函数调用的子函数Traffic_lignt ();与实际子函数Traffic_light()不同名
错误2.延时函数只声明了函数名,没有函数体
void DelayMS(uint x)
{
uint i,j;
for(i=0;i<x;i++)
for(j=0;j<125;j++);
}
作者:
angmall
时间:
2019-9-28 07:04
给你改了,对比一下就知道哪里错了。
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit RED_A=P0^0;
sbit YELLOW_A=P0^1;
sbit GREEN_A=P0^2;
sbit RED_B=P0^3;
sbit YELLOW_B=P0^4;
sbit GREEN_B=P0^5;
uchar Flash_Count=0;
uchar num=0;
uchar Operation_Type=1;
void DelayMS(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
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;
Operation_Type=2;
for(num=9;num>2;--num)
{
P1=tab[num];
DelayMS(1000);
}
break;
case 2:
for(Flash_Count=1;Flash_Count<=10;Flash_Count++)
{
P1=tab[num];
DelayMS(200);
YELLOW_A=~YELLOW_A;
if(Flash_Count%5==0)num--;
}
Operation_Type=3;
break;
case 3:
RED_A=0;YELLOW_A=1;GREEN_A=1;
RED_B=1;YELLOW_B=1;GREEN_B=0;
for(num=7;num>0;num--)
{
P1=tab[num];
DelayMS(1000);
}
Operation_Type=4;
break;
case 4:
num=2;
for(Flash_Count=1;Flash_Count<=10;Flash_Count++)
{
P1=tab[num];
DelayMS(200);
YELLOW_B=~YELLOW_B;
if(Flash_Count%5==0)num--;
}
Operation_Type=1;
break;
}
}
void main()
{
while(1)
{
Traffic_light(); //Traffic_lignt ();
}
}
复制代码
作者:
佛云
时间:
2019-9-28 08:25
带倒计时的交通信号灯程序
不过没明白你说的错是什么
作者:
shanlxw
时间:
2019-9-28 10:49
时序不清晰
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1