这个LED很简单。基本上是自动生成的。
首先插入开发板,则屏幕显示如下:
然后选择新建ASF工程,选择开发板选项
点确认,则自动跳出ASF WIZARD界面
而程序也自动生成。
- #include <asf.h>
- int main (void)
- {
- board_init();
- // Insert application code here, after the board has been initialized.
- // This skeleton code simply sets the LED to the state of the button.
- while (1) {
- // Is button pressed?
- if (ioport_get_pin_level(BUTTON_0_PIN) == BUTTON_0_ACTIVE) {
- // Yes, so turn LED on.
- ioport_set_pin_level(LED_0_PIN, LED_0_ACTIVE);
- } else {
- // No, so turn LED off.
- ioport_set_pin_level(LED_0_PIN, !LED_0_ACTIVE);
- }
- }
- }
点击编译程序,则程序编译通过,按绿色三角运行程序,以下是运行时截图:
这时按下按键则,LED灯亮,放开按键则LED灯灭
|