2017-12-02 15 views
0

Atmelからの新しいSAMC21 Xplained Proの使用に問題があります。私は現在、Cortex M0 +の基本を理解しようとしていますが、私は固執しました。私はAtmel StudioでASFを使用しています。私はスイッチからLEDを切り換える方法を学び、基本的なものから始めました。これは、Atmelのコードで完璧に動作しますGPIOピンコントロールSAMC21

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データ型を認識しないようなものです。たぶん私は何かが欠けているでしょう。ご回答有難うございます。

答えて

1

ledが常にオンになっている(またはオフになっている、ハードウェアがどのように接続されているかによって異なります)ため、コードが機能していないと思いますか? 2回目の変更後にスリープ状態にならないため、出力レベル1は短い時間(正確にはport_pin_set_output_levelの実行時間)だけ設定され、あなたの目はそれを見るのに十分速くありません。

+0

はい、あなたは正しいですが、これは動作しないかん: しばらく(1) \t { \t \t port_pin_set_output_level(LED_0_PIN、0); delay354; \t \t port_pin_set_output_level(LED_0_PIN、1); delay354; \t} –

関連する問題