biying 发表于 2014-5-4 02:43:35

tiny85休眠前如何关闭看门狗

之前用M16正常的程序,移植到TINY85上就出现睡眠前不能关闭看门狗,导致一睡眠就看门狗复位,搞了几个小时了,实在没办法才来发贴求助,另外,这个看门狗的溢出时间设置没有效果,也不知道是什么原因,融丝里的WDTON 已经编程

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

Project :
Version :
Date    : 2014-5-3
Author: Freeware, for evaluation and non-commercial use only
Company :
Comments:


Chip type               : ATtiny85
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 128
*****************************************************/

#include <tiny85.h>
#include<delay.h>

// Declare your global variables here
#define ucharunsigned char
#define uintunsigned int

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

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port B initialization
// Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State5=1 State4=1 State3=1 State2=0 State1=0 State0=0
PORTB=0xFF;
DDRB=0xFF;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x00;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFF
// OC1A output: Disconnected
// OC1B output: Disconnected
// Timer1 Overflow Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
PLLCSR=0x00;

TCCR1=0x00;
GTCCR=0x00;
TCNT1=0x00;
OCR1A=0x00;
OCR1B=0x00;
OCR1C=0x00;

// External Interrupt(s) initialization
// INT0: Off
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=0x00;
MCUCR=0x00;

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

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

// Analog Comparator initialization
// Analog Comparator: Off
ACSR=0x80;
ADCSRB=0x00;
DIDR0=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

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



while (1)
      {
      // Place your code here
      PORTB&=(0<<3)|(0<<4)|(0<<5);
      delay_ms(1000);
          PORTB|=(1<<3)|(1<<4)|(0<<5);
          delay_ms(2000);       
      MCUCR |= (1<<SM1) | (0<<SM0);// 掉电模式
      MCUCR |= (1<<SE);   //睡眠使能
      PORTB&=(0<<3)|(0<<4)|(0<<5);
          delay_ms(2000);
   #asm("WDR")   //喂狗
/* Clear WDRF in MCUSR */
MCUSR &= ~(1<<WDRF);
/* Write logical one to WDCE and WDE */
WDTCR |= (1<<WDCE) | (1<<WDE);
/* Turn off WDT */
WDTCR &= ~(1<<WDE);   
      #asm("sleep")      //休眠
      PORTB|=(1<<3)|(1<<4)|(0<<5);
          delay_ms(1000);
      PORTB&=(0<<3)|(0<<4)|(0<<5);
          delay_ms(5000);
       }   
}
页: [1]
查看完整版本: tiny85休眠前如何关闭看门狗