我的想法是通过控制stm32的IO口的高或低,来操控51单片机的138芯片,从而控制数码管显示秒表计数,但是写到位选那儿,不知道怎么写了,
不知道如何用ministm32对51的数码管进行扫描
#include "timer.h"
#include "led.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);//ê1Äü¸üDÂÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //ÏèÕ¼óÅÏ輶0¼¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //′óóÅÏ輶3¼¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
TIM_Cmd(TIM3, ENABLE);
}
u16 i=0,j=0,m=0,n=0;
u8 duanxuan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
u8 smxs[4];
void display()
{
u8 i;
for(i=0;i<4;i++)
{
switch(i)
{
case(0):GPIO_ResetBits(GPIOB,GPIO_Pin_3);GPIO_ResetBits(GPIOB,GPIO_Pin_4);GPIO_ResetBits(GPIOB,GPIO_Pin_6); break;
case(1):GPIO_SetBits(GPIOB,GPIO_Pin_3);GPIO_ResetBits(GPIOB,GPIO_Pin_4);GPIO_ResetBits(GPIOB,GPIO_Pin_6); break;
case(2):GPIO_ResetBits(GPIOB,GPIO_Pin_3);GPIO_SetBits(GPIOB,GPIO_Pin_4);GPIO_ResetBits(GPIOB,GPIO_Pin_6); break;
case(3):GPIO_SetBits(GPIOB,GPIO_Pin_3);GPIO_SetBits(GPIOB,GPIO_Pin_4);GPIO_ResetBits(GPIOB,GPIO_Pin_6); break;
}
//程序接下来该怎么写,
}
}
void duanxhs()
{
smxs[0]=duanxuan[i%10];
smxs[1]=duanxuan[j%10];
smxs[2]=duanxuan[j/10];
smxs[3]=duanxuan[m%10];
}
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
i++;
if(i>9)
{
i=0;
j++;
if(j>100)
{
j=0;
m++;
if(m>9)
{
m=0;
}
}
}
TIM_ClearITPendingBit(TIM3, TIM_IT_Update );
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
是的,想法是通过8个32的io口连接到51数码管段选的引脚,进行段选,再拿4个32的io进行位选
一周热门 更多>