在线时间216 小时
UID404271
ST金币0
蝴蝶豆9
注册时间2015-5-6
论坛元老
- 最后登录
- 2020-11-25
|
发表于 2015-5-13 09:57:20
|
显示全部楼层
a0a.1 0b0c
开定时器照样可以唤醒,实现功能:T2每进中断让PD口输出翻转,10次后进入halt,PB1外部中断唤醒,唤醒时让PC口翻转。看到的现象就是LED以1s间隔闪烁,闪10次后停机,用PB1按键唤醒后PC口输出取反,PD口LED接着闪烁。
void initcpu();
void Init_GPIO(void);
void delay(unsigned char ms);
void Tim2INIT(void);
unsigned int i;
u8 TIM1S;
int main()
{
Init_GPIO();
initcpu();
Tim2INIT();
enableInterrupts();
while(1)
{
if(TIM1S>10)
{
TIM1S=0;
GPIOD->ODR=0x08;//进入Halt前关掉LED
GPIOB->CR2=0x02; //PB1使能外部中断
halt(); //进入halt模式
}
}
}
void Init_GPIO(void)
{
GPIOB->DDR=0x00;
GPIOB->CR1=0x02; //PB1上拉输入
GPIOB->CR2=0x00; //PB禁止外部中断
EXTI->CR1 = 0x08; //PB1下降沿触发
GPIOC->DDR=0x08;
GPIOC->CR1=0x08;
GPIOC->CR2=0x00;
GPIOC->ODR=0x00;
GPIOD->DDR=0x08;
GPIOD->CR1=0x08;
GPIOD->CR2=0x00;
GPIOD->ODR=0x00; //LED低亮
}
void initcpu()
{
//CLK->CKDIVR&= (uint8_t)(~0x18);/*时钟复位*/
CLK->CKDIVR= (uint8_t)0x01; /*设置时钟为内部16M高速时钟*/
disableInterrupts(); //close all interrupt
}
void delay(unsigned char i)
{
unsigned int j;
j=65535;
while(i--)
{
while(j--);
}
}
void Tim2INIT(void)
{
CLK->PCKENR1|=0x20;
TIM2->ARRH=0xf4;
TIM2->ARRL=0x24;
TIM2->CNTRH=0x00;
TIM2->CNTRL=0x00;
TIM2->PSCR=0x08;//256分频
TIM2->CR1=0x80;
TIM2->EGR=0x00;
TIM2->IER|=0x01;
TIM2->CR1|=0x01;
}
INTERRUPT_HANDLER(TIM2_UPD_OVF_TRG_BRK_IRQHandler,13)
{
TIM2->SR1 &= 0xfe;
TIM1S++;
GPIOD->ODR=~GPIOD->ODR;
return;
}
INTERRUPT_HANDLER(EXTI1_IRQHandler,4) //PB1外部中断
{
GPIOB->CR2=0x00; //PB禁止外部中断
GPIOC->ODR=~GPIOC->ODR;
return;
} |
|