led.c

来自「AVR单片机ATMEGA48控制LED灯的C程序」· C语言 代码 · 共 37 行

C
37
字号
#include <iom48v.h>
#include <macros.h>

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

	for (a = 1; a; a++)
		for (b = 1; b; b++)
			;
	}

void LED_On(int i)
	{
	PORTB = ~BIT(i);	/* low output to turn LED on */
	Delay();
	}

void main()
	{
	int i;
	DDRB = 0x97;	/* output */
	PORTB = 0xFF;	/* all off */

	while (1)
		{
		/* forward march */
		for (i = 0; i < 2; i++)
			LED_On(i);
			i++;
		/* backward march */
		}
	}

⌨️ 快捷键说明

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