本帖最后由 ddllxxrr 于 2015-1-10 13:58 编辑
今天接着用SAMD21开发板跑程序哈!
这次,不接上次程序,另起炉灶。
首先新建ASF工程,在工程里选择SAMD21,(关于为什么选开发板的好处参见前几个贴子):
然后打开,ASF wizard 把DAC模块加进来。
再打开右边的ASF EXPLORER
接着打开里边的Quictk Strat
按照里边的步骤组织好程序。然后编译。
编译通过。
那么在哪个脚输出呢。这也好办,数据手册,关于DAC的就是一个脚:
好了,运行结果,我手机没带等带了再传一下:
先上程序先:
- /**
- * \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).
- */
- #include <asf.h>
- void configure_dac(void);
- void configure_dac_channel(void);
- struct dac_module dac_instance;
- void configure_dac(void)
- {
- struct dac_config config_dac;
- dac_get_config_defaults(&config_dac);
- dac_init(&dac_instance, DAC, &config_dac);
- dac_enable(&dac_instance);
- }
- void configure_dac_channel(void)
- {
- struct dac_chan_config config_dac_chan;
- dac_chan_get_config_defaults(&config_dac_chan);
- dac_chan_set_config(&dac_instance, DAC_CHANNEL_0, &config_dac_chan);
- dac_chan_enable(&dac_instance, DAC_CHANNEL_0);
- }
- int main (void)
- {
- system_init();
- configure_dac();
- configure_dac_channel();
- uint16_t i = 0;
- while (1) {
- dac_chan_write(&dac_instance, DAC_CHANNEL_0, i);
- if (++i == 0x3FF) {
- i = 0;
- }
- }
-
-
-
-
- }
好了,先写到这里!!!
|