#include "reg51.h"
#define uint unsigned int
#define uchar unsigned char
sbit k1 = P3^2;
uint a,b,c;
const table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, //正向流水灯
0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff, //反向流水灯
0xaa,0x55,0xaa,0x55,0xaa,0x55,0xff, //隔灯闪烁
0xf0,0x0f,0xf0,0x0f,0xff, //高四盏闪烁,低四盏闪烁
0x33,0xcc,0x33,0xcc,0x33,0xcc,0xff}; //隔两盏闪烁
const table1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,}; //反向流水灯
void delay(uint z) //delay 1ms
{
uint x,y;
for(x=z;x>0;x--)
for(y=124;y>0;y--);
}
void Int0Init()
{
//设置INT0
IT0=1;//跳变沿出发方式(下降沿)
EX0=1;//打开INT0的中断允许。
// IT1=1;
// EX1=1;
EA=1;//打开总中断
}
void Int0() interrupt 0 //外部中断0的中断函数
{
// uint a;
delay(200); //延时消抖
if(k1==0)
{
a=~a;
P0=a;
}
}
void main()
{
Int0Init();
a=0;
// uint x;
while(1)
{
{
if(a==0)
{
for(b=0;b<8;b++)
{
P2=table[b];
// P0=table[x];
delay(100);
}
}
if(a!=0)
{
{
for(c=0;c<8;c++)
{
P2=table1[c];
// P0=table[x];
delay(100);
}
}
}
}
}
}
你得改下才行。
#define uint unsigned int
#define uchar unsigned char
sbit k1 = P3^2;
uint a,b,c;
const table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, //正向流水灯
0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff, //反向流水灯
0xaa,0x55,0xaa,0x55,0xaa,0x55,0xff, //隔灯闪烁
0xf0,0x0f,0xf0,0x0f,0xff, //高四盏闪烁,低四盏闪烁
0x33,0xcc,0x33,0xcc,0x33,0xcc,0xff}; //隔两盏闪烁
const table1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,}; //反向流水灯
void delay(uint z) //delay 1ms
{
uint x,y;
for(x=z;x>0;x--)
for(y=124;y>0;y--);
}
void Int0Init()
{
//设置INT0
IT0=1;//跳变沿出发方式(下降沿)
EX0=1;//打开INT0的中断允许。
// IT1=1;
// EX1=1;
EA=1;//打开总中断
}
void Int0() interrupt 0 //外部中断0的中断函数
{
// uint a;
delay(200); //延时消抖
if(k1==0)
{
a=~a;
P0=a;
}
}
void main()
{
Int0Init();
a=0;
// uint x;
while(1)
{
{
if(a==0)
{
for(b=0;b<8;b++)
{
P2=table[b];
// P0=table[x];
delay(100);
}
}
if(a!=0)
{
{
for(c=0;c<8;c++)
{
P2=table1[c];
// P0=table[x];
delay(100);
}
}
}
}
}
}
你得改下才行。