[Atmel] (详细到家)用ASF跑SAMD21程序(16)DAC BASIC

[复制链接]
1408|1
 楼主| ddllxxrr 发表于 2015-1-10 13:49 | 显示全部楼层 |阅读模式
本帖最后由 ddllxxrr 于 2015-1-10 13:58 编辑

今天接着用SAMD21开发板跑程序哈!

这次,不接上次程序,另起炉灶。

首先新建ASF工程,在工程里选择SAMD21,(关于为什么选开发板的好处参见前几个贴子):



然后打开,ASF wizard 把DAC模块加进来。


再打开右边的ASF EXPLORER


接着打开里边的Quictk Strat



按照里边的步骤组织好程序。然后编译。

编译通过。

那么在哪个脚输出呢。这也好办,数据手册,关于DAC的就是一个脚:



好了,运行结果,我手机没带等带了再传一下:

先上程序先:

  1. /**
  2. * \file
  3. *
  4. * \brief Empty user application template
  5. *
  6. */

  7. /**
  8. * \mainpage User Application template doxygen documentation
  9. *
  10. * \par Empty user application template
  11. *
  12. * This is a bare minimum user application template.
  13. *
  14. * For documentation of the board, go \ref group_common_boards "here" for a link
  15. * to the board-specific documentation.
  16. *
  17. * \par Content
  18. *
  19. * -# Include the ASF header files (through asf.h)
  20. * -# Minimal main function that starts with a call to system_init()
  21. * -# Basic usage of on-board LED and button
  22. * -# "Insert application code here" comment
  23. *
  24. */

  25. /*
  26. * Include header files for all drivers that have been imported from
  27. * Atmel Software Framework (ASF).
  28. */
  29. #include <asf.h>

  30. void configure_dac(void);
  31. void configure_dac_channel(void);

  32. struct dac_module dac_instance;

  33. void configure_dac(void)
  34. {
  35.         struct dac_config config_dac;
  36.         dac_get_config_defaults(&config_dac);
  37.         dac_init(&dac_instance, DAC, &config_dac);
  38.         dac_enable(&dac_instance);
  39. }
  40. void configure_dac_channel(void)
  41. {
  42.         struct dac_chan_config config_dac_chan;
  43.         dac_chan_get_config_defaults(&config_dac_chan);
  44.         dac_chan_set_config(&dac_instance, DAC_CHANNEL_0, &config_dac_chan);
  45.         dac_chan_enable(&dac_instance, DAC_CHANNEL_0);
  46. }

  47. int main (void)
  48. {
  49.         system_init();
  50.          configure_dac();
  51.          configure_dac_channel();

  52.         uint16_t i = 0;
  53.         while (1) {
  54.                 dac_chan_write(&dac_instance, DAC_CHANNEL_0, i);
  55.                 if (++i == 0x3FF) {
  56.                         i = 0;
  57.                 }
  58.         }
  59.        
  60.        
  61.        
  62.        
  63. }







好了,先写到这里!!!





























































本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
JY-DX-JY 发表于 2015-1-11 14:05 | 显示全部楼层
顶一个。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2404

主题

7001

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部