新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > AVR單片機從左到右LED流水燈C語言程序

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

作者: 時間:2016-11-30 來源:網(wǎng)絡 收藏
AVR單片機第一個實驗,從左到右的LED流水燈C語言程序,編程環(huán)境是WinAVR,8MHZ晶振。

本文引用地址:http://butianyuan.cn/article/201611/323645.htm

#include <avr/io.h>//相關庫

#include

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];//流水燈十六進制數(shù)組

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

}

}

}



關鍵詞: AVR單片機LED流水

評論


技術專區(qū)

關閉