avr单片机定时器控制串口_AVR | 使用ATmega16微控制器顺时针和逆时针旋转直流电动机...

avr单片机定时器控制串口

It is also a very simple program, the Simple DC motor can be rotated clockwise when the input is given to the positive terminal and vice versa for Anti-clockwise rotation.

这也是一个非常简单的程序, 当将输入提供给正极端子时,可将Simple DC电动机顺时针旋转,反之亦然

程序顺时针和逆时针旋转直流电动机 (Program to Rotate DC motor clockwise and anti clockwise )

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


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

Explanation

说明

When you will connect the motor ATmega16 with the DC motor the terminals required would be PA0 and PA7.

当您将电动机ATmega16与直流电动机连接时,所需的端子将是PA0和PA7。

PA7	PA6	PA5	PA4	PA4	PA3	PA2	PA1	PA0
1	0	0	0	0	0	0	0	1

The above representation can be represented in Hexadecimal as 0x81, the first four term i.e. 1000 represents 8 in binary and the last four term 0001 will represent 1 in binary. Therefore the input pins are defined as DDRA = 0x81.

上面的表示可以十六进制表示为0x81 ,前四个项(即1000表示二进制形式的8),后四个项0001将以二进制表示1。 因此,输入引脚定义为DDRA = 0x81 。

Inside the while loop firstly we have given input to the PA0 i.e. (PORTA = 0x01) the motor will rotate in the clockwise direction.

首先在while循环内部,我们给PA0提供了输入,即( PORTA = 0x01 ),电动机将沿顺时针方向旋转。

Then for 500 milliseconds we have stopped our motor (PORTA = 0x00) & then again we have given our input to PA7 terminal which would move the Motor in anti-clockwise direction.

然后在500毫秒内我们停止了电动机( PORTA = 0x00 ),然后再次将输入提供给PA7端子,该输入将使电动机沿逆时针方向移动。

Again it is stopped and further the same cycle repeats.

再次停止,并重复相同的循环。

Simulation

模拟

Rotating DC motor clockwise and anti clockwise

Explanation

说明

  • Devices required:

    所需设备:

    1. ATMEGA16
    2. Simple DC motor
  • Arrange the setup as shown in the figure.

    如图所示安排设置。

  • Double click on the motor and click on edit properties and then change the voltage our motor to 3v or any small value, decreasing the voltage of our Motor will increase its speed of rotation.

    双击电动机,然后单击编辑属性,然后将电动机的电压更改为3v或任何较小的值,降低电动机的电压将提高其旋转速度。

  • Put the HEX file in ATmega16 by double clicking it and selecting the path.

    双击将HEX文件放入ATmega16,然后选择路径。

  • Click on the play Button and your Simulation will run as we wanted.

    单击播放按钮,您的模拟将按照我们的要求运行。

翻译自: https://www.includehelp.com/embedded-system/rotating-dc-motor-clockwise-and-anti-clockwise-using-atmega16-microcontroller-avr.aspx

avr单片机定时器控制串口

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值