專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

AVR單片機(jī)從左到右LED流水燈C語言程序

作者:佚名   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2013年04月14日   【字體:

AVR單片機(jī)第一個(gè)實(shí)驗(yàn),從左到右的LED流水燈C語言程序,編程環(huán)境是WinAVR,8MHZ晶振。

 

#include <avr/io.h>//相關(guān)庫

#include <util/delay.h>

typedef unsigned int uint;

typedef unsigned char uchar;

uchar const tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

void main(void)//主函數(shù)

{

   PORTB=0xff;//PB口輸出為高電平

   DDRB=0xff;//高PB口為輸出

   uchar a;//定義變量

   while(1)//無限循環(huán)

   {

       for(a=0;a<8;a++)

       {

           PORTB=tab[a];//流水燈十六進(jìn)制數(shù)組

           _delay_ms(500);//調(diào)用庫中的延時(shí)函數(shù)

       }

   }

}

關(guān)閉窗口

相關(guān)文章