每一秒 是数码管显示加一 可是实际操作大约10s才加一 。想了很长时间 没搞懂 希望大佬帮帮忙谢谢谢 !!跪谢! 下面是代码
extern unsigned int Count;
int main(void)
{
NVIC_Config();
SMG_Config();
TIM4_Config();
GPIO_ResetBits(GPIOC,GPIO_Pin_13);
while(1)
{
if(Count>=60)
Count=0;
SMG_Display(Count);
}
}
void TIM4_IRQHandler(void)
{
TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
GPIO_SetBits(GPIOC,GPIO_Pin_13);
Count++;
}
#include "stm32f10x.h"
#include "tim4.h"
u8 table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,
0x5e,0x79,0x71};
#define Set_Dula GPIO_SetBits(GPIOB,GPIO_Pin_0)
#define Set_Wela GPIO_SetBits(GPIOB,GPIO_Pin_1)
#define CLR_Dula GPIO_ResetBits(GPIOB,GPIO_Pin_0)
#define CLR_Wela GPIO_ResetBits(GPIOB,GPIO_Pin_1)
unsigned int Count=0,shi=0,ge=0;
void Delay_ms(__IO u32 nCount)
{
for(; nCount != 0; nCount--);
}
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM4_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);
TIM_DeInit(TIM4);
TIM_InternalClockConfig(TIM4);
TIM_TimeBaseStructure.TIM_Prescaler = 35999;
TIM_TimeBaseStructure.TIM_Period = 1999;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode =TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStructure);
TIM_Cmd(TIM4,ENABLE);
//TIM_PrescalerConfig(TIM4,2000,TIM_PSCReloadMode_Immediate);
TIM_ClearFlag(TIM4,TIM_FLAG_Update);
TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);//计数溢出时候发生中断
}
void SMG_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void SMG_Display(unsigned int Count)
{
shi=Count/10;
ge=Count%10;
GPIO_Write(GPIOA,0XFe);
Set_Wela;
CLR_Wela;
GPIO_Write(GPIOA,table[shi]);
Set_Dula;
CLR_Dula;
Delay_ms(0X7FB);
GPIO_Write(GPIOA,0XFD);
Set_Wela;
CLR_Wela;
GPIO_Write(GPIOA,table[ge]);
Set_Dula;
CLR_Dula;
Delay_ms(0X7FB);
}
|