⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 led._c

📁 mega8的控制LED走马灯程序
💻 _C
字号:
#include <iom8v.h>
#include <macros.h>

/* This seems to produce the right amount of delay for the LED to be seen */
void Delay()
	{
	unsigned int a, b;

	for (a = 1; a<50; a++)
		{
		for (b = 1; b<2000; b++);
		}
	}

void LED_PORTBOn(int i)
	{
	PORTB = ~BIT(i);	/* low output to turn BLED on */
	Delay();
	}
void LED_PORTDOn(int j)
	{
	PORTD = ~BIT(j);/* low output to turn DLED on */
	Delay();
	}
void LED_PORTBOff(int i)
{
    PORTB = ~BIT(i);	/* hight output to turn BLED off */
	}
	void LED_PORTDOff(int j)
{
	PORTD = ~BIT(j);/* hight output to turn DLED off */
	}
void main()
	{
	int i,j;
	DDRB = 0xFF;	/* output */
	PORTB = 0xFF;	/* all off */
	DDRD=0xFF;/*D output*/
	PORTD=0xFF;/*all off*/

	while (1)
		{
		for (i = 0; i < 3; i++)
			LED_PORTBOn(i);
			LED_PORTBOff(i);
		for (j = 5; j < 8; j++)
			LED_PORTDOn(j);
		for(j = 7;j >4; j--)
		    LED_PORTDOn(j);
			LED_PORTDOff(j);
		for (i = 2; i >=0; i--)
			LED_PORTBOn(i);
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -