想通过GPIOB的3、4、6、7口控制51数码管的位选,GPIO的8-15口控制51数码管段选,
求看看程序有什么问题,
#include "timer.h"
#include "led.h"
#include "delay.h"
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseStructure.TIM_Period = arr;
TIM_TimeBaseStructure.TIM_Prescaler =psc;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM3,TIM_IT_Update ,ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM3, ENABLE); //ê1ÄüTIMxíaéè
}
u16 j=0,k=0,m=0;
u16 duanxuan[10]={0XFFFC,0XFF60,0XFFDE,0XFFF2,0XFF66,0XFFB6,0XFFBE,0XFFE0,0XFFFE,0XFFF6};//段选
u8 smwx[4];
void daterpro()
{
smwx[0]=duanxuan[j%10];
smwx[1]=duanxuan[k%10];
smwx[2]=duanxuan[k/10];
smwx[3]=duanxuan[m%10];
}
void smg()
{
u8 i;
for(i=0;i<4;i++)
{
switch(i)
{
case(0):GPIOB->ODR&=0XE4FF;GPIOB->ODR|=0XE5FF;break;//位选码
case(1):GPIOB->ODR&=0XE4FF;GPIOB->ODR|=0XE6FF;break;
case(2):GPIOB->ODR&=0XE4FF;GPIOB->ODR|=0XEAFF;break;
case(3):GPIOB->ODR&=0XE4FF;GPIOB->ODR|=0XF4FF;break;
}
GPIOB->ODR&=0XF4FF;
GPIOB->ODR|=smwx[i];
delay_ms(10);
GPIOB->ODR&=0XE4FF;
}
}
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
j++;
if(j>9)
{
j=0;
k++;
if(k>100)
{
k=0;
m++;
if(m>9)
{
m=0;
}
}
}
TIM_ClearITPendingBit(TIM3, TIM_IT_Update );
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>