0

我在尝试使用来自 Atmel 的新 SAMC21 Xplained Pro 时遇到问题。我目前正在尝试了解 Cortex M0+ 的基础知识,但我卡住了。我在 Atmel Studio 中使用 ASF。我从基础开始,学习如何用开关切换 LED。这是 Atmel 的代码,完美无瑕:

void configure_port_pins(void)
{
     struct port_config config_port_pin;
     port_get_config_defaults(&config_port_pin);
     config_port_pin.direction = PORT_PIN_DIR_INPUT;
     config_port_pin.input_pull = PORT_PIN_PULL_UP;
     port_pin_set_config(BUTTON_0_PIN, &config_port_pin);
     config_port_pin.direction = PORT_PIN_DIR_OUTPUT;
     port_pin_set_config(LED_0_PIN, &config_port_pin);
}
int main (void)
{
    system_init();
    configure_port_pins();
    while (true) {
       bool pin_state = port_pin_get_input_level(BUTTON_0_PIN);
       port_pin_set_output_level(LED_0_PIN, !pin_state);
    }

然后我想尝试一些更简单的东西,比如:

int main (void)
{
    system_init();
    configure_port_pins();
    port_pin_set_output_level(LED_0_PIN,0);

    while (1)
    {
        port_pin_set_output_level(LED_0_PIN,0);
        delay_ms(500);
        port_pin_set_output_level(LED_0_PIN,1);
    }
}

但它不起作用。就像它不识别 bool 数据类型一样。也许我错过了一些东西。感谢您的回答。

4

1 回答 1

1

您认为代码无法正常工作是因为 led 一直处于打开状态(或关闭状态,这取决于硬件的连接方式)?这是因为您在第二次更改后没有睡觉,所以输出级别 1 仅设置为短暂的时刻(准确地说,是port_pin_set_output_level执行时间),您的眼睛不够快,无法看到它。

于 2017-12-02T01:57:09.433 回答