搜索
bottom↓
回复: 0

tiny85休眠前如何关闭看门狗

[复制链接]

出0入0汤圆

发表于 2014-5-4 02:43:35 | 显示全部楼层 |阅读模式
之前用M16正常的程序,移植到TINY85上就出现睡眠前不能关闭看门狗,导致一睡眠就看门狗复位,搞了几个小时了,实在没办法才来发贴求助,另外,这个看门狗的溢出时间设置没有效果,也不知道是什么原因,融丝里的WDTON 已经编程

  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-3
  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. // Declare your global variables here
  22. #define uchar  unsigned char
  23. #define uint  unsigned int

  24. void main(void)
  25. {
  26. // Declare your local variables here   在这里您声明局部变量

  27. // Crystal Oscillator division factor: 1
  28. #pragma optsize-
  29. CLKPR=0x80;
  30. CLKPR=0x00;
  31. #ifdef _OPTIMIZE_SIZE_
  32. #pragma optsize+
  33. #endif

  34. // Input/Output Ports initialization
  35. // Port B initialization
  36. // Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
  37. // State5=1 State4=1 State3=1 State2=0 State1=0 State0=0
  38. PORTB=0xFF;
  39. DDRB=0xFF;

  40. // Timer/Counter 0 initialization
  41. // Clock source: System Clock
  42. // Clock value: Timer 0 Stopped
  43. // Mode: Normal top=0xFF
  44. // OC0A output: Disconnected
  45. // OC0B output: Disconnected
  46. TCCR0A=0x00;
  47. TCCR0B=0x00;
  48. TCNT0=0x00;
  49. OCR0A=0x00;
  50. OCR0B=0x00;

  51. // Timer/Counter 1 initialization
  52. // Clock source: System Clock
  53. // Clock value: Timer1 Stopped
  54. // Mode: Normal top=0xFF
  55. // OC1A output: Disconnected
  56. // OC1B output: Disconnected
  57. // Timer1 Overflow Interrupt: Off
  58. // Compare A Match Interrupt: Off
  59. // Compare B Match Interrupt: Off
  60. PLLCSR=0x00;

  61. TCCR1=0x00;
  62. GTCCR=0x00;
  63. TCNT1=0x00;
  64. OCR1A=0x00;
  65. OCR1B=0x00;
  66. OCR1C=0x00;

  67. // External Interrupt(s) initialization
  68. // INT0: Off
  69. // Interrupt on any change on pins PCINT0-5: Off
  70. GIMSK=0x00;
  71. MCUCR=0x00;

  72. // Timer(s)/Counter(s) Interrupt(s) initialization
  73. TIMSK=0x00;

  74. // Universal Serial Interface initialization
  75. // Mode: Disabled
  76. // Clock source: Register & Counter=no clk.
  77. // USI Counter Overflow Interrupt: Off
  78. USICR=0x00;

  79. // Analog Comparator initialization
  80. // Analog Comparator: Off
  81. ACSR=0x80;
  82. ADCSRB=0x00;
  83. DIDR0=0x00;

  84. // ADC initialization
  85. // ADC disabled
  86. ADCSRA=0x00;

  87. // Watchdog Timer initialization
  88. // Watchdog Timer Prescaler: OSC/2k
  89. // Watchdog Timer interrupt: Off
  90. #pragma optsize-
  91. #asm("WDR")   //喂狗
  92. WDTCR |= (1<<WDCE) | (1<<WDE);
  93. /* 设置新预分频器值 = 64K周期 (~0.5 s) */
  94. WDTCR = (1<<WDE) | (1<<WDP2) | (0<<WDP0)| (1<<WDP1)| (0<<WDP3)| (0<<WDIE);  
  95. #ifdef _OPTIMIZE_SIZE_
  96. #pragma optsize+
  97. #endif



  98. while (1)
  99.       {
  100.       // Place your code here
  101.       PORTB&=(0<<3)|(0<<4)|(0<<5);
  102.       delay_ms(1000);
  103.           PORTB|=(1<<3)|(1<<4)|(0<<5);
  104.           delay_ms(2000);         
  105.       MCUCR |= (1<<SM1) | (0<<SM0);  // 掉电模式
  106.       MCUCR |= (1<<SE);   //睡眠使能
  107.       PORTB&=(0<<3)|(0<<4)|(0<<5);
  108.           delay_ms(2000);
  109.      #asm("WDR")   //喂狗
  110. /* Clear WDRF in MCUSR */
  111. MCUSR &= ~(1<<WDRF);
  112. /* Write logical one to WDCE and WDE */
  113. WDTCR |= (1<<WDCE) | (1<<WDE);
  114. /* Turn off WDT */
  115. WDTCR &= ~(1<<WDE);   
  116.       #asm("sleep")      //休眠
  117.       PORTB|=(1<<3)|(1<<4)|(0<<5);
  118.           delay_ms(1000);
  119.       PORTB&=(0<<3)|(0<<4)|(0<<5);
  120.           delay_ms(5000);
  121.        }   
  122. }
复制代码
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-19 14:37

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

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