我试图编写AVR Xmega-A1 xplained board并且我没什么问题。
我的代码:
unsigned char state = 1; // temporary variable for leds states
while (1)
{
if ( state == 1)
{
leds = 0b00000001; // led0 is on
if(~readSwitches() & 0b00000001)
{
state = 2;
}
if(~readSwitches() & 0b00000010)
{
state = 3;
}
}
if ( state == 2)
{
leds = blink0(leds);
if (~readSwitches() & 0b00001000)
{
state = 1;
}
}
if ( state == 3)
{
leds = 0b00000000;
if(~readSwitches() & 0b00000100)
{
state = 1;
}
}
writeLeds( ~leds );
}
应该做到以下几点:
打开时:只有led0打开
sw0: led0闪烁
sw1: led0 off //如果闪烁不工作
sw2: led0 on //如果闪烁无法正常工作
sw3 :关闭闪烁
目前它几乎像应该的那样工作..只有问题是led0在电路板打开时闪烁。有任何改变它的提示吗?