跑馬燈:
#include<intrins.h>
void delay(unsigned int c);
void main()
{
unsigned char temp=0x01;
unsigned num;
while(1)
{
P0=0x00;
for(num = 0;num<8;num++)
{
P0=temp;
delay(50);
temp=_crol_(temp,1);
}
}
}
void delay(unsigned int c)
{
unsigned char a, b;
for (;c>0;c--)
{
for (b=38;b>0;b--)
{
for (a=130;a>0;a--)
;
}
}
}
左右跑馬燈(for循環(huán)后面不要加分號(hào))
void main()
{
unsigned int i;
temp=0xfe;
for(i=0;i<7;i++)
{
P0=temp;
delay(50);
temp=_crol_(temp,1);//或者temp=temp<<1;
temp=temp|0x01;
}
for(i=0;i<7;i++)
{
P0=temp;
delay(50);
temp=_crol_(temp,1);//或者temp=temp>>1;
temp=temp|0x80;
}
}
數(shù)碼管依次顯示0-9
void main()
{
P0=0x3f;delay(50);
P0=0x06;delay(50);
P0=0x5b;delay(50);
P0=0x4f;delay(50);
P0=0x66;delay(50);
P0=0x6d;delay(50);
P0=0x7d;delay(50);
P0=0x07;delay(50);
P0=0x7f;delay(50);
P0=0x6f;delay(50);
}