LEDサンプル

やっぱり最初はこれよね。
LEDをPD0〜PD7に接続。
以下、ソースコード。

#include <avr/io.h>
#include <util/delay.h>

void delay_ms( int t )
{
	while( t-- ){
		_delay_ms( 1 );
	}
}

int main( void )
{
	DDRD	= 0b11111111;
	PORTD	= 0b00000000;

	char count	= 0;
	char binc	= 0;

	while( 1 ){
		PORTD = ( 1 << count );
		if( 0 == binc ){
			count++;
			if( 7 <= count ){
				binc = 1;
			}
		} else {
			count--;
			if( 0 >= count ){
				binc = 0;
			}
		}
		delay_ms( 100 );
	}

	return 0;
}

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS