peoteus仿真stm32定时器功能,想实现Num的值过一秒增加一次
但实际仿真的时候,一加上定时器初始化函数,lcd12864亮但是不显示内容,注释掉定时器初始化函数,正常显示,
我想问一下,这是因为什么原因呢?
注释掉定时器初始化函数时的运行结果
加上定时器初始化函数时的运行结果
主函数
#include "stm32f10x.h" // Device header
#include "LCD12864.h"
#include "Timer.h"
unsigned int Num;
int main()
{
LCD_GPIO_Configration();
LCD12864_Init();
Timer_Init();
LCD_Position(4,1);
LCD_Show_String("hello word");//
while(1)
{
LCD_Position(1,1);
LCD_Show_Num(Num,5);//
}
}
void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)
{
Num++;
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}
}
#include "stm32f10x.h" // Device header
void Timer_Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//ʱÖÓʹÄÜ
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
TIM_InternalClockConfig(TIM2);
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
//¶¨Ê±Æ÷Timer2³õʼ»¯
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1 ;
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_Period=7200-1;
TIM_TimeBaseInitStructure.TIM_Prescaler=10000-1;
// TIM_TimeBaseInitStructure.TIM_RepetitionCounter=0;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);
//ʹÄÜÖ¸¶¨µÄTIM2Öжϣ¬ÔÊÐí¸üÐÂÖжÏ
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
//ÖжÏÓÅÏȼ¶NVICÉèÖÃ
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStructure);
//ʹÄÜTIM2
TIM_Cmd(TIM2,ENABLE);
}