[Atmel] 在mbed环境下跑一下SAMD21:定时器3

[复制链接]
1619|0
 楼主| ddllxxrr 发表于 2016-3-25 08:15 | 显示全部楼层 |阅读模式
今天这个程序,是估算一下最大的定时时间长度。

用了两个变量s m,s计秒s计分。

程序如下:
  1. #include "mbed.h"
  2. Timer t;

  3. float s=0;
  4. float m=0;
  5. DigitalOut diag(PB30);
  6. Serial pc(USBTX,USBRX);
  7. int main()
  8. {
  9.     pc.printf("\r\nTimer Duration Test\n\r");
  10.     pc.printf("-------------------------\n\n\r");
  11.     t.reset();
  12.     t.start();
  13.     while(1)
  14.     {
  15.         if(t.read()>=(s+1))
  16.         {
  17.             diag = 1;
  18.             wait(0.5);
  19.             diag =0;
  20.             s++;
  21.             pc.printf("%1.0f seconds\r\n",(s-60*(m-1)));
  22.             
  23.             }
  24.         if(t.read()>=60*m)
  25.         {
  26.             printf("%1.0f minutes \n\r",m);
  27.             m++;
  28.             }
  29.         if(t.read()<s)
  30.         {
  31.             pc.printf("\r\n Timer has overflowed!\n\r");
  32.             for(;;){}
  33.             }   
  34.         }
  35.    
  36.     }



运行截图如下:


由于定时器时间很长,本人没有耐心再等下去,也许等一天也完不了,所以只截取了部分运行时的截图。

本帖子中包含更多资源

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

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2404

主题

7001

帖子

68

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