avr studio使用_如何使用AVR使LED闪烁?

avr studio使用

This is one of the basic programs, or we can say that a type of "HELLO WORLD" program of an Embedded System. The programming in Embedded System quit simple, it is almost similar to the Basic C programming that we use. The programming of Embedded System (AVR) is done using the application ATMEL STUDIO 6.2.

这是基本程序之一,或者可以说是嵌入式系统的一种“ HELLO WORLD”程序。 嵌入式系统中的编程非常简单,它几乎与我们使用的Basic C编程相似。 嵌入式系统(AVR)的编程是使用应用程序ATMEL STUDIO 6.2完成的

程序使用AVR使LED闪烁 (Program to blink an LED using AVR)

#include <avr/io.h>
#define F_CPU 1000000
#include <util/delay.h>

int main(void)
{
	DDRA = 0x01;
	
	while(1)
	{
		PORTA = 0x01;
		_delay_ms(1000);
		PORTA = 0x00;
		_delay_ms(1000);
	}
	
	return 0;
}

Screenshot of the program from editor

该程序的屏幕截图来自编辑器

Program to blink an LED using AVR

Explanation:

说明:

  1. Here <avr/io.h> is the header file for the AVR, it includes all the functions, classes that are required for our program.

    这里的<avr / io.h>是AVR的头文件,它包含我们程序所需的所有功能和类。

  2. F_CPU indicates the CPU speed of our ATMEGA16(AVR).

    F_CPU表示我们ATMEGA16(AVR)的CPU速度。

  3. The header file #include <util/delay.h> provides the delay that is required in the program. It is basically used to delay the operation performed.

    头文件#include <util / delay.h>提供程序中所需的延迟。 它基本上用于延迟执行的操作。

  4. Below the int main(void) we write the pins that are given to our ATMEGA16 board by the LED and is denoted by DDRA = 0x01, where 0x represents the hexadecimal and 01 is the is the position of the LED attached to it.

    在int main(void)下方,我们编写由LED分配给ATMEGA16板的引脚,并由DDRA = 0x01表示,其中0x代表十六进制,而01是与其相连的LED的位置。

  5. Inside the while(1) we write the coding which we want to repeat continuously.

    在while(1)内部,我们编写了要连续重复的编码。

  6. Inside the while loop PORTA = 0x01 represents the condition when our LED blinks i.e. the LED will be on when we will receive 1 in our PA0 port and will be OFF if we receive 0.

    在while循环内, PORTA = 0x01表示LED闪烁的状态,即当我们在PA0端口中接收到1时LED点亮,而在接收到0时LED熄灭。

  7. _delay_ms(1000) shows the delay is micro seconds which we have used 1000.

    _delay_ms(1000)显示延迟为微秒,我们已使用1000。

Simulation:

模拟:

Blink an LED using AVR - Simulation

Simulation Explanation:

仿真说明:

  1. Open the PROTEUS Professional and from the file Menu open a NEW design

    打开PROTEUS Professional,然后从文件菜单中打开新设计

  2. Then go to the left side in the selection Mode, click on P and select the following devices:

    然后在选择模式下转到左侧,单击P并选择以下设备:

    • ATMEGA16
    • RESISTANCE
    • LED of any colour
  3. From the terminal mode on the left side, select the Ground terminal and place it as shown in the figure.

    从左侧的端子模式中,选择接地端子,然后如图所示放置它。

  4. Arrange all the components as shown in the aboveimage.

    如上图所示排列所有组件。

  5. Here we have not connected any power terminal, because during the simulation it is not required.

    在这里我们没有连接任何电源端子,因为在仿真过程中不需要。

  6. Now double click the resistance and change its value from 10k to 330 also double click the ATMEGA16 and a popup will appear there select the file of the that has been created in your respective directory through ATMEGA STUDIO 6.2.

    现在,双击电阻并将其值从10k更改为330,再双击ATMEGA16,将出现一个弹出窗口,选择已通过ATMEGA STUDIO 6.2在各自目录中创建的的文件。

  7. Open the debug file and select the HEX File and open it.

    打开调试文件,然后选择HEX文件并打开它。

  8. Now go to the left bottom corner and click on play.

    现在转到左下角,然后单击播放。

  9. Through these Steps the program and Stimulation will be executed and your LED will burn with the respective delay.

    通过这些步骤,将执行程序和刺激,并且LED将以相应的延迟点亮。

翻译自: https://www.includehelp.com/embedded-system/blink-an-led-using-the-avr.aspx

avr studio使用

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值