欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 6492|回復: 0
打印 上一主題 下一主題
收起左側

求救!! stm32f103c8t6 TIM4 定時器問題

[復制鏈接]
跳轉到指定樓層
樓主
ID:348627 發表于 2018-11-9 20:39 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
每一秒 是數碼管顯示加一   可是實際操作大約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);

}



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

使用道具 舉報

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

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表