简体   繁体   English

GPIO引脚控制SAMC21

[英]GPIO Pin Control SAMC21

i'm having trouble trying to use my new SAMC21 Xplained Pro from Atmel. 我在尝试使用来自Atmel的新SAMC21 Xplained Pro时遇到了麻烦。 I'm currently trying to understand the basics of Cortex M0+, but i stuck. 我目前正在尝试了解Cortex M0 +的基础知识,但是我坚持了下来。 I'm using ASF in Atmel Studio. 我在Atmel Studio中使用ASF。 I started from basic, learning how to toggle the LED with the switch. 我从基础开始,学习如何使用开关切换LED。 This is Atmel's code, works flawless: 这是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);
    }

Then I wanted to try something simpler, like: 然后,我想尝试一些更简单的方法,例如:

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);
    }
}

But it doesn't work. 但这是行不通的。 It's like it doesn't recognize bool data type. 就像它无法识别bool数据类型一样。 Maybe I'm missing something. 也许我想念一些东西。 Thanks for your answer. 感谢您的回答。

You think that code is not working because led is constantly on (or off, that depends on how hardware is connected)? 您认为代码不起作用是因为led一直亮着(或熄灭,这取决于硬件的连接方式)? It's because you don't sleep after second change, so output level 1 is set only for a brief moment (to be precise, time of port_pin_set_output_level execution), and your eye is not fast enough to see it. 这是因为您在第二次更改后就没有睡觉,所以仅将输出级别1设置为一小会儿(准确地说,是port_pin_set_output_level执行的时间),并且您的眼睛不够快才能看到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM