Delay是ARM公司自带的,本来以为很快就能搞定但实践一下还不是那么地容易。
我首先加载Delay模块。
并打开快速指导:
我马上形成程序,我的意图是灯点一下后隔半分钟换一下状态。然后二秒后再换一下
刚开始我把
#define | | | Delay in at least specified number of milliseconds. More... | | | #define | | | Delay in at least specified number of seconds. More... | | | #define | | | Delay in at least specified number of microseconds. More... |
加到了程序的上边,但后来查看了下,居然不用加,因为在sam0中已经有delay.h的定义
其余的时钟也不用改,因为它是内核内带,下进灯闪了,以下是程序:
- #include <asf.h>
- //bool pin_state = port_pin_get_input_level(BUTTON_0_PIN);
- 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();
- delay_init();
- configure_port_pins();
-
- while (true) {
- delay_ms(500);
- port_pin_toggle_output_level(LED_0_PIN);
- delay_s(2);
- port_pin_toggle_output_level(LED_0_PIN);
- delay_ms(500);
- port_pin_toggle_output_level(LED_0_PIN);
-
- }
- }
|