使用WinAVR的微控制器AVR中的基本I

使用WinAVR的微控制器AVR中的基本I

本文介绍了使用WinAVR的微控制器AVR中的基本I/O的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想驱动BLDC电机,我使用ATMEGA32作为控制器的CPU,从BLDC电机读取霍尔效应传感器时遇到问题

I want to drive a BLDC motor, i use ATMEGA32 as CPU of controller , i have a problem in reading hall effect sensor from BLDC motor

这是我的代码:

DDRB=(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5);
DDRD=(0<<0)|(0<<1)|(0<<2)|(0<<3);
PORTD=(1<<0)|(1<<1)|(1<<2)|(1<<3);

PORTB作为输出,PORTD作为输入这是主程序:

PORTB as OUTPUT and PORTD as INPUTthis is main program :

       if (~(PORTD &(1<<0)) && PORTD &(1<<1) && ~(PORTD &(1<<2))) /// 0   1   0
        {
            PORTB=(1<<0)|(0<<1)|(0<<2)|(1<<3)|(0<<4)|(0<<5);
        }
        else if (~(PORTD &(1<<0)) && PORTD &(1<<1) && PORTD &(1<<2)) /// 0   1   1
        {
            PORTB=(0<<0)|(0<<1)|(0<<2)|(1<<3)|(0<<4)|(1<<5);
        }
        ...........

我的回答是该程序无法从霍尔效应传感器读取逻辑零(0),因此BLDC无法正常运行,如何在AVR ATMEGA32中读取多个输入?我使用Codeblock和winavr....

my answer is this program cannot read logic zero (0) from hall effect sensor so BLDC cannot run well, how to read multiple input in AVR ATMEGA32 ?i use Codeblock and winavr....

非常感谢您

推荐答案

我不太了解您要做什么,但是如果您想从atmega 32的Port D中读取内容,则无需处理"PORTD"寄存器,还有另一个称为"PIND"的寄存器,这是您从中读取数字信号的寄存器.也没有>> DDRD =(0<< 0)|(0<< 1)|(0<< 2)|(0<< 3);如果您想清除一位(将位设置为逻辑零),则只使用按位而不是移位的位(例如DDRD = ~(1<<bitnumber)

I don't really understand what you want to do, but if you want to read from Port D in the atmega 32, you do not deal with the 'PORTD' register, there is another Register called 'PIND', this is the one you read digital signals from.Also there nothing as ">DDRD=(0<<0)|(0<<1)|(0<<2)|(0<<3);" If you want to clear a bit (set the bit to logic zero), you just use the bitwise not with the shifted one (e.g. DDRD = ~(1<<bitnumber)

这篇关于使用WinAVR的微控制器AVR中的基本I/O的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 16:33