本帖最后由 ddllxxrr 于 2015-2-5 14:25 编辑
SAMD21的时钟可以通过管脚输出。
首先建立ASF工程,然后添加SYSTEM-I/O Pin Multiplexer模块。
然后添加程序代码。程序清单如下:
/**
* \file
*
* \brief Empty user application template
*
*/
/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* This is a bare minimum user application template.
*
* For documentation of the board, go \ref group_common_boards "here" for a link
* to the board-specific documentation.
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# Minimal main function that starts with a call to system_init()
* -# Basic usage of on-board LED and button
* -# "Insert application code here" comment
*
*/
/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
/**
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
*/
static void setup_clock_out_pin(void);
#include <asf.h>
#define CONF_CLOCK_PIN_OUT PIN_PA28H_GCLK_IO0
#define CONF_CLOCK_PIN_MUX MUX_PA28H_GCLK_IO0
static void setup_clock_out_pin(void)
{
struct system_pinmux_config pin_mux;
system_pinmux_get_config_defaults(&pin_mux);
/* MUX out the system clock to a I/O pin of the device */
pin_mux.mux_position = CONF_CLOCK_PIN_MUX;
system_pinmux_pin_set_config(CONF_CLOCK_PIN_OUT, &pin_mux);
}
int main (void)
{
system_init();
setup_clock_out_pin();
// 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 (port_pin_get_input_level(BUTTON_0_PIN) == BUTTON_0_ACTIVE) {
// Yes, so turn LED on.
port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
} else {
// No, so turn LED off.
port_pin_set_output_level(LED_0_PIN, !LED_0_ACTIVE);
}
}
}
至于运行结果,明天我用示波看一下,看看怎么样???
|