我正在尝试创建一个程序,使用移位在PORTA的开发板的每个位上闪烁LED。当我模拟程序时,输出为0x01,0x02,ox04,0x10,而不是位0-7之间的移位。然后重新开始。有什么理由我不能完全转换那个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);
}
}
}
可能你的意思是:
for (int count = 0; count < 8; count++)
{
PORTA = 1<<count;
_delay_ms(1000);
}