linux 下的avr_AVR | 闪烁2个LED或在按钮的帮助下

linux 下的avr

程序使2个LED闪烁 (Program to blink 2 LEDs Alternatively)

#include<avr/io.h>

int main(void)
{
	DDRA=0x03;
	DDRD=0x00;

	while(1)
	{
		if((PIND & 0x01) == 0x01)
			PORTA=0x01;			
		else
			PORTA=0x02;
	}
}

Explanation

说明

Here, DDRA = 0x03 indicates the input given to both our LEDs. The LEDs are connected in the terminal PA0 and PA1 i.e. the pin 0 & 1.

此处, DDRA = 0x03表示提供给两个LED的输入。 LED连接在端子PA0和PA1(即引脚0和1)上。

PINS:	7	6	5	4	3	2	1	0
INPUTS:	0	0	0	0	0	0	1	1

The input can be written in hexadecimal as 03. Therefore, we have written DDRA = 0x03.

输入可以十六进制形式写为03。因此,我们写了DDRA = 0x03 。

DDRD = 0x00 represents the input to the button which we have connected in the D port.

DDRD = 0x00表示我们在D端口中连接的按钮的输入。

Inside the IF statement we have represented the condition which says that when the button is pressed the input 1 will be given to the PORTA at the 0th PIN. i.e. LED 1 will glow.

在IF语句中我们已经表示它说,当按下该按钮,输入1将在0 管脚被提供给PORTA的条件。 即LED 1将发光。

In the else condition we have given the statement such that when our Button won’t be pressed the LED 2 would Blink continuously.

在else条件下,我们给出了这样的声明:当不按下按钮时,LED 2将连续闪烁。

Simulation

模拟

Blink 2 leds in AVR

Explanation

说明

  • Components needed:

    所需组件:

    1. 2 resistors (330 ohm)
    2. 2 LEDs
    3. ATmega16
    4. Button
    5. One resistor of 10k ohm value
    6. Power Terminal
    7. Two Ground Terminal
  • Arrange the components as shown in the above image.

    如上图所示排列组件。

  • Here we have connected the resistance of 10k here because the current from the power terminal will always prefer a low resistance path, so instead of going to the ground it will go directly to the ATmega16.

    在这里,我们在此处连接了10k的电阻,因为来自电源端子的电流将始终倾向于低电阻路径,因此,它直接流向ATmega16而不是接地。

  • While simulating the setup you will observe that when the Switch is OFF , LED 2 will glow continuously.

    在模拟设置时,您会发现当开关为OFF时,LED 2会持续发光。

  • And when you press the button you will observe that the LED 1 will glow and LED 2 will stop glowing.

    当您按下按钮时,您会发现LED 1会发光,LED 2会停止发光。

翻译自: https://www.includehelp.com/embedded-system/blinking-2-leds-alternatively-with-the-help-of-button-avr.aspx

linux 下的avr

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值