[Atmel] 用AtmelStudio6.2跑mega16例程(6)

[复制链接]
 楼主| ddllxxrr 发表于 2014-9-1 19:07 | 显示全部楼层 |阅读模式
以下是软件仿真的结果:


以下是程序:
  1. /*
  2. * GccApplication10.c
  3. *
  4. * Created: 2014-9-1 12:07:23
  5. *  Author: Administrator
  6. */


  7. #include <avr/io.h>
  8. #include <avr/interrupt.h>
  9. #define uchar unsigned char
  10. #define uint unsigned int
  11. //定义按钮及LED与端口的连接
  12. //#define  button1     PIND.2
  13. //#define  button2     PIND.3
  14. //#define  speaker     PORTD.0
  15. #define  redLED1     0//PORTC.0
  16. #define  blueLED1    1//PORTC.1
  17. #define  greenLED1   2//PORTC.2
  18. #define  yellowLED1  3//PORTC.3
  19. #define  redLED2     4//PORTC.4
  20. #define  blueLED2    5//PORTC.5
  21. #define  greenLED2   6//PORTC.6
  22. #define  yellowLED2  7//PORTC.7
  23. uint i,a=0;
  24. uchar tab2[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F, //正向流水灯
  25.         0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF, //反向流水灯
  26.         0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F, //正向流水灯
  27. 0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF}; //反向流水灯
  28. //interrupt [TIM0_OVF] void timer0_ovf_isr(void)
  29. ISR(TIMER0_OVF_vect)
  30. {
  31.         a++;
  32.         TCNT0=0x00;
  33. }

  34. int main(void)
  35. {
  36.         //uchar k;
  37.         DDRC=0xFF;
  38.         PORTC=0xFF;
  39.         TCCR0=0x05;     //WGM01=0 WGM00=0选择普通模式;COM01=0 COM00使PB3为通用I/O(OC0不与引脚相连)CS02=1 CS01=0 CS01=1选择1024分频
  40.         TCNT0=0x00;
  41.         OCR0=0x00;
  42.         TIMSK=0x01;
  43.         //#asm("sei")
  44.         sei();
  45.         while(1)
  46.         {
  47.                 for(i=0;i<23;)
  48.                 {
  49.                         if(a==30)
  50.                         {
  51.                                 PORTC=tab2[i];
  52.                                 a=0;
  53.                                 i++;
  54.                         }
  55.                         else
  56.                         {;}
  57.                 }
  58.         }
  59. }


本帖子中包含更多资源

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

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

本版积分规则

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

2403

主题

6994

帖子

68

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