找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 6190|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

求救! stm32f103c8t6 TIM4 定時器問題

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:348627 發(fā)表于 2018-11-9 20:39 | 只看該作者 回帖獎勵 |倒序?yàn)g覽 |閱讀模式
每一秒 是數(shù)碼管顯示加一   可是實(shí)際操作大約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);//計數(shù)溢出時候發(fā)生中斷

}
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);

}



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表