//=========================================================================
// SysTick_Config(void)
//=========================================================================
void STM32_SysTick_Config(void)
{
/* Configure HCLK clock as SysTick clock source */
STM32_SysTick_Regs->Ctrl.all=((u32)0x00000004); // SysTick_CLKSource_HCLK
STM32_SysTick_Regs->Ctrl.bit.CLKSOURCE=1; // 内核时钟(FCLK)
/* SysTick interrupt each 100 Hz with HCLK equal to 72MHz */
STM32_SysTick_Regs->Reload.all=720000; //720,000
/* Enable the SysTick Interrupt */
STM32_SysTick_Regs->Ctrl.bit.TICKINT=1; //1=SysTick 倒数到0 时产生SysTick 异常请求
/* Enable the SysTick Counter */
STM32_SysTick_Regs->Ctrl.bit.ENABLE=1; //SysTick 定时器的使能位
}
//=========================================================================
// LcdShow_Init(void)
//=========================================================================
void STM32_LcdShow_Init(void)
{
u32 tmpccmrx = 0, tmpccer = 0;
/* Time base configuration */
STM32_Tim2_Regs->arr.all=8000; // 自动重装载的值
STM32_Tim2_Regs->psc.all=17; // 预分频器的值 计数器的时钟频率CK_CNT等于fCK_PSC/(PSC[15:0]+1)。
STM32_Tim2_Regs->cr1.bit.DIR=0; // 计数器向上计数
STM32_Tim2_Regs->cr1.bit.CKD=0; // 时钟分频因子 00:tDTS = tCK_INT
STM32_Tim2_Regs->cr1.bit.ARPE=0; // TIM1_ARR寄存器没有缓冲
/* only counter overflow/underflow generate U interrupt */
//如果允许产生更新中断或DMA请求,则只有计数器溢出/下溢产生一个更新中断或DMA请求
STM32_Tim2_Regs->cr1.bit.URS=1;
/* Output Compare Timing Mode configuration: Channel1 */
tmpccer=STM32_Tim2_Regs->ccer.all;
tmpccmrx=STM32_Tim2_Regs->ccmr1.all;
/* Reset the Output Compare Bits */
//00:CC1通道被配置为输出 &=0XFF00
tmpccmrx &= 0xFF00;
/* Set the Output Polarity level */
//CC1P:输入/捕获1输出极性 =0:OC1高电平有效 &=FFFD;
tmpccer &=0xFFFD;
/* Disable the Channel 1: Reset the CCE Bit */
//CC1E:输入/捕获1输出使能 0: 关闭 &((u16)0xFFFE)
STM32_Tim2_Regs->ccer.all &=((u16)0xFFFE);
/* Select the Output Compare Mode */
//CC1S[1:0]:捕获/比较1 选择。00:CC1通道被配置为输出 000:冻结
//OC1PE:输出比较1预装载使能 0:关闭TIMx_CCR1寄存器的预装载功能 ?
tmpccmrx |= 0x00;
/* Set the Capture Compare Register value */
//捕获/比较1的值 =4000
STM32_Tim2_Regs->ccr1.all =4000;
/* Set the Capture Compare Enable Bit */
//CCIE 输入/捕获1输出极性 1: 开启- OC1信号输出到对应的输出引脚。 ((u16)0x0001)
tmpccer |= ((u16)0x0001);
/* Set the Capture Compare Polarity */
//CCIP 输入/捕获1输出极性0:OC1高电平有效 |=((u16)0x0000)
tmpccer |= ((u16)0x0000);
STM32_Tim2_Regs->ccmr1.all = (u16)tmpccmrx;
STM32_Tim2_Regs->ccer.all= (u16)tmpccer;
STM32_Tim2_Regs->ccmr1.all&=((u16)0x7F77); //bit3, bit7, bit15=0
/* TIM IT enable */
STM32_Tim2_Regs->dier.bit.UIE=1; //允许更新中断
STM32_Tim2_Regs->dier.bit.CC1IE=1; //允许捕获/比较1中断
/* TIM2 enable counter */
STM32_Tim2_Regs->cr1.bit.CEN=1; // 允许计数器1:开启计数器
}
//=========================================================================
// Led_Config(void)
//=========================================================================
void STM32_Led_Config(void)
{
/* Enable GPIOC clock */
STM32_Rcc_Regs->apb2enr.bit.IOPCEN=1;//IOPCEN:IO口C时钟使能
/* Configure PC.06, PC.07, PC.08 and PC.09 as output push-pull */
// 注意了这个万利的注释是 PC.08 PC.09 而实在是PC.04 PC.05!
STM32_Gpioc_Regs->crl.bit.CNF4=Output_push_pull; // PC.04 推挽输出
STM32_Gpioc_Regs->crl.bit.MODE4=Output_Mode_50mhz; // PC.04 输出模式,最大速度50MHz
STM32_Gpioc_Regs->crl.bit.CNF5=Output_push_pull; // PC.05 推挽输出
STM32_Gpioc_Regs->crl.bit.MODE5=Output_Mode_50mhz; // PC.05 输出模式,最大速度50MHz
STM32_Gpioc_Regs->crl.bit.CNF6=Output_push_pull; // PC.06 推挽输出
STM32_Gpioc_Regs->crl.bit.MODE6=Output_Mode_50mhz; // PC.06 输出模式,最大速度50MHz
STM32_Gpioc_Regs->crl.bit.CNF7=Output_push_pull; // PC.07 推挽输出
STM32_Gpioc_Regs->crl.bit.MODE7=Output_Mode_50mhz; // PC.07 输出模式,最大速度50MHz
}
//=========================================================================
// Button_Config(void)
//=========================================================================
void STM32_Button_Config(void)
{
/* Enable GPIOD clock */
STM32_Rcc_Regs->apb2enr.bit.IOPDEN=1;//IOPDEN:IO口D时钟使能
/* Configure PD.03, PD.04 as output push-pull */
// 注意了 这里是推挽输出 而实在是浮空输入!
STM32_Gpiod_Regs->crl.bit.CNF3=Input_floating; // PD.03 浮空输入
STM32_Gpiod_Regs->crl.bit.MODE3=Input_Mode; // PD.03 输入模式
STM32_Gpiod_Regs->crl.bit.CNF4=Input_floating; // PD.04 浮空输入
STM32_Gpiod_Regs->crl.bit.MODE4=Input_Mode; // PD.04 输入模式
}
//=========================================================================
//
//=========================================================================
//GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3);
STM32_Afio_Regs->exticr0.bit.EXTI3=3; //0011:EXTI3=PD[3]脚
/* Configure EXTI Line9 to generate an interrupt on falling edge */
// 1:线x上的中断请求不被屏蔽 MR3=1中断请求不被屏蔽 ( EXTI 3 )
STM32_Exti_Regs->imr.bit.MR3=1;
/* Clear Rising Falling edge configuration */
// 0:禁止输入线x上的上升沿触发(中断和事件) tr3 ( EXTI 3 )
STM32_Exti_Regs->rtsr.bit.TR3=0;
// 0:禁止输入线x上的下降沿触发(中断和事件) tr3 ( EXTI 3 )
STM32_Exti_Regs->ftsr.bit.TR3=0;
/* Select the trigger for the selected external interrupts */
// 下降沿触发选择寄存器(EXTI_FTSR) 1:允许输入线x上的下降沿触发(中断和事件)
STM32_Exti_Regs->ftsr.bit.TR3=1;
//GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource4);
STM32_Afio_Regs->exticr1.bit.EXTI4=3; //0011:EXTI4=PD[4]脚
/* Configure EXTI Line9 to generate an interrupt on falling edge */
// 1:线x上的中断请求不被屏蔽 MR4=1中断请求不被屏蔽 ( EXTI 4 )
STM32_Exti_Regs->imr.bit.MR4=1;
/* Clear Rising Falling edge configuration */
// 0:禁止输入线x上的上升沿触发(中断和事件) tr4 ( EXTI 4 )
STM32_Exti_Regs->rtsr.bit.TR4=0;
// 0:禁止输入线x上的下降沿触发(中断和事件) tr4 ( EXTI 4 )
STM32_Exti_Regs->ftsr.bit.TR4=0;
/* Select the trigger for the selected external interrupts */
// 下降沿触发选择寄存器(EXTI_FTSR) 1:允许输入线x上的下降沿触发(中断和事件)
STM32_Exti_Regs->ftsr.bit.TR4=1;
//原函数内容如下:
/*
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3);
// Configure EXTI Line9 to generate an interrupt on falling edge
EXTI_InitStructure.EXTI_Line = EXTI_Line3;//((u32)0x00008)
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//0
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//0x0C
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource4);
// Configure EXTI Line9 to generate an interrupt on falling edge
EXTI_InitStructure.EXTI_Line = EXTI_Line4;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
*/
文章评论(0条评论)
登录后参与讨论