bit k1=P3^0;//按鈕
sbit k2=P3^1;
sbit k3=P3^2;
//=================================================
#define led_num1 15//編碼個(gè)數(shù)
uchar code table1[15]={//花樣1編碼
0x00,0x00,0xff,
0x00,0x00,0xff,
0x00,0x00,0xff,
0x00,0x00,0xff,
0x00,0x00,0xff
};
//=================================================
#define led_num2 8//編碼個(gè)數(shù)
uchar code table2[8]={//花樣2編碼
0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00
};
//=================================================
#define led_num3 10//編碼個(gè)數(shù)
uchar code table3[10]={//花樣3編碼
0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6
};
uchar time=0,mode=0;//系統(tǒng)變量
uchar flag=0;
void main() //主函數(shù)
{
TMOD|=0X01;
TH0=(65536-50000)/256;//50ms
TL0=(65536-50000)%256;
ET0=1;//打開(kāi)定時(shí)器0中斷允許
EA=1;//打開(kāi)總中斷
TR0=1;//打開(kāi)定時(shí)器
while(1)
{
if(!k1) //花樣1
{
mode=1;
}
if(!k2) //花樣2
{
mode=2;
}
if(!k3) //花樣3
{
mode=3;
}
}
}
//定時(shí)器中斷
void Timer0() interrupt 1
{
if(time<10)//0.5s
time++;
else
{
time=0;
if(mode==1)//花樣1
{
P1=table1[flag];
if(flag<led_num1)
flag++;
else
{
flag=0;
P1=0xff;
mode=0;//停止
}
}
if(mode==2)//花樣2
{
P1=table2[flag];
if(flag<led_num2)
flag++;
else
{
flag=0;
P1=0;
mode=0;//停止
}
資料借鑒于此紛傳
閱讀全文