#i nclude<reg52.h>
unsigned char TAB[] = {0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f}
void Delay(unsigned char a)//延时函数
{
unsigned char i//定义无符字符型变量,范围为0~255
while( --a != 0)//建议使用--a不要使用a-- 大家看看编译后的汇编代码便知
{
for(i = 0i <125i++)} //i 从0加到125,在12M晶体下CPU大概就耗时1毫秒
}
void main(void)
{
unsigned char i = 0
while(i<7)
{
P1 = TAB[i]
Delay(80)
i++
}
P1=Oxff
}
#include<reg52.h>#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit key1=P3^4//¶ÀÁ¢¼üÅÌ
sbit key2=P3^5//¶ÀÁ¢¼üÅÌ
uchar t,temp
void delay(uchar z)
{
uchar x,y
for(x=zx>0x--)
for(y=110y>0y--)
}
void init()
{
TMOD=0x01
TH0=(65536-50000)/256
TL0=(65536-50000)%256
EA=1
ET0=1
TR0=1
temp=0xfe
t=0
P3=0xff
}
void main()
{
init()
while(1)
{
if(t==20)
{
t=0
P1=temp
temp=_crol_(temp,1)
}
if(key1==0)
{
TR0=0
P1=0xff
while(!key1)
}
if(key2==0)
{
TR0=0
P1=0
while(!key2)
}
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256
TL0=(65536-50000)%256
t++
}