單片機(jī)控制花樣LED燈閃爍
#include AT89X51.H>
void main(void)
{const unsigned char design[32]={0xFF,0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF,
0xFF,0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x0,
0xE7,0xDB,0xBD,0x7E,0xFF}; //定義花樣數(shù)據(jù)
unsigned int a; //定義循環(huán)用的變量
unsigned char b; //因內(nèi)存有限,在C51編程中要注意變量類(lèi)型的使用
do{ //do while型循環(huán)
for (b=0; b32; b++)
{for(a=0; a30000; a++); //延時(shí)一段時(shí)間
P2 = design; //讀已經(jīng)定義的花樣數(shù)據(jù)并寫(xiě)花樣數(shù)據(jù)到P2口
}
} while(1);
}
void main() //主函數(shù)
{ unsigned char OutData=0xfe; //定義輸出數(shù)據(jù)與初值
for(;;) //無(wú)限循環(huán)
{
P2=OutData; //將OutData輸出到P2口,使P2口中的一個(gè)LED燈亮
OutData=_crol_(OutData,1); //使 OutData循環(huán)左移,使亮的LED燈左移一位
mDelay(100); //調(diào)用延時(shí)函數(shù),延時(shí)100 毫秒
}}
led燈相關(guān)文章:led燈原理
評(píng)論