搜索
bottom↓
回复: 4

用CodeWizardAVR编译attiny13A和attiny85,INT0死活不能用

[复制链接]

出0入0汤圆

发表于 2014-5-13 07:57:59 | 显示全部楼层 |阅读模式
如题,代码只是一个测试INT0的最小程序,请解决过的朋友帮忙给看一下,这是源码

  1. /*****************************************************
  2. This program was produced by the
  3. CodeWizardAVR V2.05.1b Evaluation
  4. Automatic Program Generator
  5. ?Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
  6. http://www.hpinfotech.com

  7. Project :
  8. Version :
  9. Date    : 2014-5-8
  10. Author  : Freeware, for evaluation and non-commercial use only
  11. Company :
  12. Comments:


  13. Chip type               : ATtiny85
  14. AVR Core Clock frequency: 8.000000 MHz
  15. Memory model            : Small
  16. External RAM size       : 0
  17. Data Stack size         : 128
  18. *****************************************************/

  19. #include <tiny85.h>
  20. #include<delay.h>
  21. // Pin change interrupt service routine
  22. //interrupt [PC_INT0] void pin_change_isr(void)
  23. interrupt [EXT_INT0] void ext_int0_isr(void)
  24. {
  25. // Place your code here
  26. PORTB&=0xfe;
  27. }

  28. // Declare your global variables here

  29. void main(void)
  30. {
  31. // Declare your local variables here

  32. // Crystal Oscillator division factor: 1
  33. #pragma optsize-
  34. CLKPR=0x80;
  35. CLKPR=0x00;
  36. #ifdef _OPTIMIZE_SIZE_
  37. #pragma optsize+
  38. #endif

  39. // Input/Output Ports initialization
  40. // Port B initialization
  41. // Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
  42. // State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
  43. //PORTB=0x3F;
  44. //DDRB=0x3F;
  45. DDRB = 0x3F;             //将所有I/O口均初始化为输出状态
  46.    PORTB = 0x3F;
  47.    DDRB&=0XFD;       //PCINT1设为输入
  48.    PORTB=0X3F;

  49. // Timer/Counter 0 initialization
  50. // Clock source: System Clock
  51. // Clock value: Timer 0 Stopped
  52. // Mode: Normal top=0xFF
  53. // OC0A output: Disconnected
  54. // OC0B output: Disconnected
  55. TCCR0A=0x00;
  56. TCCR0B=0x00;
  57. TCNT0=0x00;
  58. OCR0A=0x00;
  59. OCR0B=0x00;

  60. // Timer/Counter 1 initialization
  61. // Clock source: System Clock
  62. // Clock value: Timer1 Stopped
  63. // Mode: Normal top=0xFF
  64. // OC1A output: Disconnected
  65. // OC1B output: Disconnected
  66. // Timer1 Overflow Interrupt: Off
  67. // Compare A Match Interrupt: Off
  68. // Compare B Match Interrupt: Off
  69. PLLCSR=0x00;

  70. TCCR1=0x00;
  71. GTCCR=0x00;
  72. TCNT1=0x00;
  73. OCR1A=0x00;
  74. OCR1B=0x00;
  75. OCR1C=0x00;

  76. // External Interrupt(s) initialization
  77. // INT0: Off
  78. // Interrupt on any change on pins PCINT0-5: On
  79. //GIMSK=0x20;
  80. //MCUCR=0x00;
  81. //PCMSK=0x02;
  82. //GIFR=0x20;
  83. GIMSK=0x40;
  84. MCUCR=0x00;
  85. GIFR=0x40;

  86. // Timer(s)/Counter(s) Interrupt(s) initialization
  87. TIMSK=0x00;

  88. // Universal Serial Interface initialization
  89. // Mode: Disabled
  90. // Clock source: Register & Counter=no clk.
  91. // USI Counter Overflow Interrupt: Off
  92. USICR=0x00;

  93. // Analog Comparator initialization
  94. // Analog Comparator: Off
  95. ACSR=0x80;
  96. ADCSRB=0x00;
  97. DIDR0=0x00;

  98. // ADC initialization
  99. // ADC disabled
  100. ADCSRA=0x00;

  101. // Global enable interrupts
  102. #asm("sei")

  103. while (1)
  104.       {
  105.       // Place your code here
  106.        #asm("sei")            // 开放全局中断       while(1);
  107.       }
  108. }
复制代码

阿莫论坛20周年了!感谢大家的支持与爱护!!

月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!

出0入0汤圆

 楼主| 发表于 2014-5-16 06:01:22 | 显示全部楼层
INT0没有响应,仿真也是如此,有哪位朋友知道原因,请告知一下!

出0入0汤圆

 楼主| 发表于 2014-5-24 00:01:44 | 显示全部楼层
本帖最后由 biying 于 2014-5-24 01:16 编辑

根据马老师的指点,我重新新建了工程,修改了程序后,INT0终于有反应了。我发现个现像,当设置为任意电平触发时,快速按下再放开按键,等再次开中断时,依然会再执行中断程序一次,似乎像是有记忆能力一样,也就是说第二次开中断时,会先对比上一次中断时的电平状态。


但是ATTINY85依然不能用INT0

  1. /*****************************************************
  2. This program was produced by the
  3. CodeWizardAVR V2.05.1b Evaluation
  4. Automatic Program Generator
  5. ?Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
  6. http://www.hpinfotech.com

  7. Project :
  8. Version :
  9. Date    : 2014-5-23
  10. Author  : Freeware, for evaluation and non-commercial use only
  11. Company :
  12. Comments:    PB3和PB4接LED灯,PB1为INT0接按键


  13. Chip type               : ATtiny13A
  14. AVR Core Clock frequency: 9.600000 MHz
  15. Memory model            : Tiny
  16. External RAM size       : 0
  17. Data Stack size         : 16
  18. *****************************************************/

  19. #include <tiny13a.h>
  20. #include<delay.h>
  21. // External Interrupt 0 service routine
  22. interrupt [EXT_INT0] void ext_int0_isr(void)
  23. {
  24. // Place your code here
  25. GIMSK=0x00; //禁用INT0中断,等合适的时候再打开
  26. GIFR=0x40;
  27. PORTB ^= 1<<4;
  28. }

  29. // Declare your global variables here

  30. void main(void)
  31. {
  32. // Declare your local variables here

  33. // Crystal Oscillator division factor: 1
  34. #pragma optsize-
  35. CLKPR=0x80;
  36. CLKPR=0x00;
  37. #ifdef _OPTIMIZE_SIZE_
  38. #pragma optsize+
  39. #endif

  40. // Input/Output Ports initialization
  41. // Port B initialization
  42. // Func5=In Func4=Out Func3=Out Func2=Out Func1=In Func0=Out
  43. // State5=P State4=1 State3=1 State2=1 State1=P State0=1
  44. PORTB=0x3F;
  45. DDRB=0x1D;

  46. // Timer/Counter 0 initialization
  47. // Clock source: System Clock
  48. // Clock value: Timer 0 Stopped
  49. // Mode: Normal top=0xFF
  50. // OC0A output: Disconnected
  51. // OC0B output: Disconnected
  52. TCCR0A=0x00;
  53. TCCR0B=0x00;
  54. TCNT0=0x00;
  55. OCR0A=0x00;
  56. OCR0B=0x00;

  57. // External Interrupt(s) initialization
  58. // INT0: On
  59. // INT0 Mode: Low level
  60. // Interrupt on any change on pins PCINT0-5: Off
  61. GIMSK=0x40;
  62. MCUCR=0x01;
  63. GIFR=0x40;

  64. // Timer/Counter 0 Interrupt(s) initialization
  65. TIMSK0=0x00;

  66. // Analog Comparator initialization
  67. // Analog Comparator: Off
  68. ACSR=0x80;
  69. ADCSRB=0x00;
  70. DIDR0=0x00;

  71. // ADC initialization
  72. // ADC disabled
  73. ADCSRA=0x00;

  74. // Global enable interrupts
  75. #asm("sei")

  76. while (1)
  77.       {
  78.       // Place your code here
  79.       delay_ms(4000);
  80.       PORTB ^= 1<<3;
  81.       GIMSK=0x40;
  82.       }
  83. }
复制代码

本帖子中包含更多资源

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

x

出0入0汤圆

发表于 2014-5-27 18:06:32 | 显示全部楼层
看下ATtiny85和ATtiny13A的寄存器名字是否一样~~~~~

出0入0汤圆

 楼主| 发表于 2014-5-27 19:01:01 | 显示全部楼层
xinhoujue 发表于 2014-5-27 18:06
看下ATtiny85和ATtiny13A的寄存器名字是否一样~~~~~

谢谢提醒,原来TINY13A的INT0是PB1,而TINY85的INT0是PB2,原来看的数据手册是中文的TINY13A,误以为同一系列应该是一样的,就忽略了TINY85的引脚定义,再次感谢你的提醒!
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-25 18:59

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表