|
#include <REGX51.H> //頭文件,定義單片機(jī)型號(hào)
#define uchar unsigned char //偽指令用uchar代替unsigned char
#define uint unsigned int //偽指令用uint代替unsigned int
uchar code a[6]={0xfa,0xf5,0xeb,0xd7,0xaf,0x5f}; //定義編譯數(shù)組
uchar code b[6]={0x5f,0xaf,0xd7,0xeb,0xf5,0xfa}; //定義編譯數(shù)組
void delay(uint x) //延時(shí)函數(shù)
{
uint y;
for(;x>0;x--)
for(y=100;y>0;y--);
}
void main(void) //函數(shù)的開始,(void)表示有返回值
{
uint i;
uchar temp;
while(1) //while循環(huán)(1)循環(huán)條件
{
temp=0xfe;
for(i=0;i<8;i++)
{
P0=temp;
delay(300);
temp=(temp<<=1)|0x01; //temp值左移1位,從而實(shí)現(xiàn)流水燈效果,0x01表示在最右面補(bǔ)1
}
temp=0x7f;
for(i=0;i<8;i++)
{
P0=temp;
delay(300);
temp=(temp>>=1)|0x80; //temp值右移1位,從而實(shí)現(xiàn)流水燈效果,0x80表示在最左面補(bǔ)1
}
for(i=0;i<6;i++)
{
P0=a[i]; //遍歷數(shù)組a,將數(shù)組a中的每個(gè)元素賦給P0
delay(400);
}
for(i=0;i<6;i++)
{
P0=b[i]; //遍歷數(shù)組b,將數(shù)組b中的每個(gè)元素賦給P0
delay(400);
}
}
}
|
|