【问题标题】:Atmega32 shifting PORTA won't cycle through entire registerAtmega32 移位 PORTA 不会循环遍历整个寄存器
【发布时间】:2018-08-30 12:19:15
【问题描述】:

我正在尝试创建一个程序,以使用移位在 PORTA 的开发板的每个位上闪烁 LED。当我模拟程序时,输出不是 0-7 位之间的移位,而是 0x01、0x02、ox04、0x10。然后重新开始。有什么原因我不能完全通过那个 8 位寄存器吗?任何帮助将不胜感激。

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


int main(void)
{
    DDRA = 0xFF;

    while (1)
    {
       PORTA = 0x01;
       _delay_ms(1000);
       for (int count = 0; count < 7; count++)
            {
            PORTA = 1<<PORTA;
            _delay_ms(1000);
            }

    }
}

【问题讨论】:

    标签: bit-shift atmel


    【解决方案1】:

    你的意思可能是这样的:

    for (int count = 0; count < 8; count++)
    {
        PORTA = 1<<count;
        _delay_ms(1000);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-23
      • 2017-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多