[英]GPIO Pin Control SAMC21
我在嘗試使用來自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數據類型一樣。 也許我想念一些東西。 感謝您的回答。
您認為代碼不起作用是因為led一直亮着(或熄滅,這取決於硬件的連接方式)? 這是因為您在第二次更改后就沒有睡覺,所以僅將輸出級別1設置為一小會兒(准確地說,是port_pin_set_output_level
執行的時間),並且您的眼睛不夠快才能看到它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.