我编的STM32通过TLC5917点亮LED灯的程序为什么点不亮LED灯
时间:10-02
整理:3721RD
点击:
//TLC5917的CLK引脚接STM32的PC7
#include "stm32f10x.h"
void GPIO_configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void NVIC_Configuration(void)
{
//定义一个结构体
NVIC_InitTypeDef NVIC_InitStructure;
//设置优先级组
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0) ;
//设置 TIM7线
NVIC_InitStructure.NVIC_IRQChannel =TIM7_IRQn;
//使能优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//配置抢断优先级
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
//配置响应优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_Init(&NVIC_InitStructure);
//设置存入寄存器
NVIC_SetVectorTable (NVIC_VectTab_FLASH ,0x0);
}
//*****定时器初始化*********
void TIM_Configuration (void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// TIM_Cmd(TIM7, DISABLE);
//预分频系数为3600-1,这样计数器时钟为72MHz/3600 = 20kHz
TIM_TimeBaseStructure.TIM_Prescaler = 3600 - 1;
//设置时钟分割 TIM_CKD_div1=0x0000,不分割
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
//设置计数器模式为向上计数模式
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up ;
//设置计数溢出大小,每计2个数就让PC7翻转一下产生10KHZ的时钟信号
TIM_TimeBaseStructure.TIM_Period = 1;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
//将配置应用到TIM7中
TIM_TimeBaseInit(TIM7,&TIM_TimeBaseStructure);
TIM_UpdateRequestConfig( TIM7, TIM_UpdateSource_Regular);
//使能计数器
TIM_Cmd(TIM7, ENABLE);
//使能中断
TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE);
//清除标志位
// TIM_ClearFlag(TIM7, TIM_FLAG_Update);
}
//*****************************
int main(void)
{
SystemInit(); //系统时钟配置函数 通过不同的定义 来选择不同的主频 这里设置是72m
GPIO_configuration ();
NVIC_Configuration ();
TIM_Configuration ();
GPIO_ResetBits(GPIOC,GPIO_Pin_9);
GPIO_SetBits(GPIOC, GPIO_Pin_6);
GPIO_ResetBits(GPIOC, GPIO_Pin_6);
//初始化IO口
while (1)
{
}
}
it.c中的中断函数 让PC7翻转一下产生10KHZ的时钟信号
void TIM7_IRQHandler(void)
{
//检测是否发生溢出更新事件
if(TIM_GetITStatus(TIM7, TIM_IT_Update)== SET)
{
if(i==1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_7 | GPIO_Pin_8);
i=0;
}
else
{
GPIO_ResetBits(GPIOC, GPIO_Pin_7 | GPIO_Pin_8);
i=1;
}
TIM_ClearITPendingBit(TIM7 , TIM_FLAG_Update);
}
}
#include "stm32f10x.h"
void GPIO_configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void NVIC_Configuration(void)
{
//定义一个结构体
NVIC_InitTypeDef NVIC_InitStructure;
//设置优先级组
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0) ;
//设置 TIM7线
NVIC_InitStructure.NVIC_IRQChannel =TIM7_IRQn;
//使能优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//配置抢断优先级
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
//配置响应优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_Init(&NVIC_InitStructure);
//设置存入寄存器
NVIC_SetVectorTable (NVIC_VectTab_FLASH ,0x0);
}
//*****定时器初始化*********
void TIM_Configuration (void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// TIM_Cmd(TIM7, DISABLE);
//预分频系数为3600-1,这样计数器时钟为72MHz/3600 = 20kHz
TIM_TimeBaseStructure.TIM_Prescaler = 3600 - 1;
//设置时钟分割 TIM_CKD_div1=0x0000,不分割
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
//设置计数器模式为向上计数模式
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up ;
//设置计数溢出大小,每计2个数就让PC7翻转一下产生10KHZ的时钟信号
TIM_TimeBaseStructure.TIM_Period = 1;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
//将配置应用到TIM7中
TIM_TimeBaseInit(TIM7,&TIM_TimeBaseStructure);
TIM_UpdateRequestConfig( TIM7, TIM_UpdateSource_Regular);
//使能计数器
TIM_Cmd(TIM7, ENABLE);
//使能中断
TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE);
//清除标志位
// TIM_ClearFlag(TIM7, TIM_FLAG_Update);
}
//*****************************
int main(void)
{
SystemInit(); //系统时钟配置函数 通过不同的定义 来选择不同的主频 这里设置是72m
GPIO_configuration ();
NVIC_Configuration ();
TIM_Configuration ();
GPIO_ResetBits(GPIOC,GPIO_Pin_9);
GPIO_SetBits(GPIOC, GPIO_Pin_6);
GPIO_ResetBits(GPIOC, GPIO_Pin_6);
//初始化IO口
while (1)
{
}
}
it.c中的中断函数 让PC7翻转一下产生10KHZ的时钟信号
void TIM7_IRQHandler(void)
{
//检测是否发生溢出更新事件
if(TIM_GetITStatus(TIM7, TIM_IT_Update)== SET)
{
if(i==1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_7 | GPIO_Pin_8);
i=0;
}
else
{
GPIO_ResetBits(GPIOC, GPIO_Pin_7 | GPIO_Pin_8);
i=1;
}
TIM_ClearITPendingBit(TIM7 , TIM_FLAG_Update);
}
}