[Atmel] 用AtmelStudio6.2跑mega16例程(35)T0控制LED

[复制链接]
 楼主| ddllxxrr 发表于 2014-10-17 22:01 | 显示全部楼层 |阅读模式
这个程序是利用T0的溢出中断。来定时控制LED的闪亮.

Prouets仿真的截图:



Studio6.2截图:


具体程序:
  1. /*
  2. * GccApplication21.c
  3. *
  4. * Created: 2014-10-17 21:43:54
  5. *  Author: Administrator
  6. */

  7. #define F_CPU 4000000UL
  8. #include <avr/io.h>
  9. #include <avr/interrupt.h>
  10. #include <stdint.h>

  11. #define LED_BLINKL()(PORTC ^= 0x01)
  12. uint16_t T_Count = 0;


  13. int main(void)
  14. {
  15.     DDRC = 0x01;
  16.         TCCR0 = 0x05;
  17.         TCNT0 = 256 - F_CPU/1024.0*0.05;
  18.         TIMSK = 0x01;
  19.         sei();
  20.        
  21.        
  22.         while(1)
  23.     {
  24.         //TODO:: Please write your application code
  25.     }
  26. }

  27. ISR(TIMER0_OVF_vect)
  28. {
  29.         TCNT0 = 256 - F_CPU/1024.0 *0.05;
  30.         if(++T_Count != 5) return;
  31.         T_Count = 0;
  32.         LED_BLINKL();
  33. }

本帖子中包含更多资源

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

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

本版积分规则

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

2403

主题

6994

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

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