最近写了个程序,想降低单片机功耗,用ADC噪声抑制模式,想用T2中断唤醒,通过LED来查看,不知道怎么唤醒不了,向高手求救。程序如下:
#include <iom88v.h>
#include <macros.h>
#define bsignal PC0
#define setbit(adress,num) (adress |= (1<<num))
#define clrbit(adress,num) (adress &= ~(1<<num))
//I/O init
void TXport_init(void)
{
DDRB = 0X00; //时钟输入PB6和PB7为输入,其他无用端口设置为输入
PORTB = 0X3F;
DDRC = 0X01; //PC0为信号输出
PORTC = 0X06; //PC0输出0
DDRD = 0X00;
PORTD = 0X30;
//DDRD = 0X04;
}
//Watchdog init
void Watchdog_init(void)
{
WDR();//this prevents a timout on enabling
WDTCSR |= (1<<WDCE)|(1<<WDE);
WDTCSR = 0X29; //WATCHDOG ENABLED
}
//oscillator:8MHz,timing time:32us
void TXtimer2_init(void)
{
TCCR2B = 0X00;
TCCR2A = 0X00;
TCNT2 = 0XFA; //TCNT0=256-(32*oscillator)/64
TCCR2B = 0X03; //CS02:CS01:CS00=011,64分频
TIMSK2 = 0X01;
}
#pragma interrupt_handler timer2_ovf_isr:iv_TIM2_OVF
void timer2_ovf_isr(void)
{
static int TXtimecnt;
TCNT2 = 0XFC;
TXtimecnt++;
if(TXtimecnt==1)
setbit(PORTC,bsignal);
else
clrbit(PORTC,bsignal);
if(TXtimecnt>=30)
TXtimecnt = 0;
}
//cpu init
void initcpu(void)
{
CLI();
TXport_init();
Watchdog_init();
TXtimer0_init();
SEI();
}
void main(void)
{
initcpu();
while(1)
{
SMCR = 0X01;
SLEEP();
PRR=0XDF;
}
} |