51单片机流水灯程序纠错

来源:百度知道 编辑:UC知道 时间:2024/05/31 14:02:36
目的是通过int0改变流水灯的花样,编译总是提示main中的int b=0和后面的int 变量定义有错,还有那个中断函数也有错,麻烦高手帮忙看看。
#include <reg51.h>

void show (int b) ;
void show_0 ();
void show_1 ();
void show_2 ();
void ftime(int ms);
void change(int b) ;
int b,i,i1,i2;

void main()
{
{
EA=1;
EX0=1;
}

int b=0;

while (1)
{
show(b);
}
}
/**显示分支*/
void show ( int b )
{
switch(b)
{
case 0: show_0 ; break ;
case 1: show_1 ; break ;
case 2: show_2 ; break ;
}
}
/* 显示方式*/
void show_0()
{
P0=0xff;ftime(500);P0=0x00;ftime(500);
}
void show_1()
{
P0=0x01;
int i;
for(i=0;i<8;i++)
{
P0*=2;
ftime(500);
}
}
void show_2()
{
P0=0x70;
int i1;
for(i1=0;i1<8;i1++)
{
P0/=2;
ftime(500);
}
}
/*延时*/

你的中断程序这行: void change(int b) interrupt 0
函数 change(int b) 不应该带参数,可能这里错了,因为外部中断函数不是主程序调用的,参数怎么传呢。

你参考一下我用中断实现的流水等程序:(C51编写的)

#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit DIOLA=P2^5;
uchar count=20;
bit flag=0;

void main()
{

uchar move;
uchar i;
DIOLA=1;
P1=0x0;//全亮
TMOD=0x01;//T0工作于方式1
EA=1;
ET0=1;
TH0=0x3c;
TL0=0xb0;//定时25ms/12MH,9e58.
TR0=1;
while(1)
{
move=0xfe;// 选择L1亮
for(i=8;i>0;)
{
if(flag==1)
{
move=_cror_(move,1);
P1=move;
flag=0;
i--;
}

}
}
}

void T0_INT() interrupt 1
{
TH0=0x3c;
TL0=0xb0;//定时25ms
if(--count==0)
{