Hello.I am trying to program stm32f401cb microprocessor to display numbers in the seven segment due to the button actions.Without pressing the button,the program starts with writing 0 in 7segment,after that in every time of pressing to the button,it will display 1,2,3,4,5,6,7,8,9 and after 9,program will stop.I have written a code like this
#include "stm32f4xx.h"
void rcc_config(void) {
RCC_ClocksTypeDef rcc_clocks_init;
rcc_clocks_init.SYSCLK_Frequency=8400000;
RCC_GetClocksFreq(&rcc_clocks_init);
}
void gpioa_config(void) {
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
GPIO_InitTypeDef gpioa_init;
gpioa_init.GPIO_Pin=GPIO_Pin_0;
gpioa_init.GPIO_Mode= GPIO_Mode_IN;
gpioa_init.GPIO_OType=GPIO_OType_PP;
gpioa_init.GPIO_PuPd=GPIO_PuPd_DOWN;
gpioa_init.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOA,&gpioa_init);
}
void gpiob_config(void) {
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);
GPIO_InitTypeDef gpiob_init;
gpiob_init.GPIO_Pin=GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
gpiob_init.GPIO_Mode=GPIO_Mode_OUT;
gpiob_init.GPIO_OType=GPIO_OType_PP;
gpiob_init.GPIO_PuPd=GPIO_PuPd_NOPULL;
gpiob_init.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOB,&gpiob_init);
}
void number_0(void) {
GPIO_SetBits(GPIOB,GPIO_Pin_0); //a
GPIO_SetBits(GPIOB,GPIO_Pin_1); //b
GPIO_SetBits(GPIOB,GPIO_Pin_2); //c
GPIO_SetBits(GPIOB,GPIO_Pin_3); //d
GPIO_SetBits(GPIOB,GPIO_Pin_4); //e
GPIO_SetBits(GPIOB,GPIO_Pin_5); //f
GPIO_ResetBits(GPIOB,GPIO_Pin_6); //g
}
The problem is normally the program starts with displaying zero(0) but when i press the button for the first time,it displays 9 and after that,it always displays 9(nine) in the 7segment everytime i press the button
counter control function is used to display according to the counter,normally it should display 0 when j=0,1 when j=1,2 when j=2 etc... but it always displays 9 after the first time i press the button.
What may be the reason of that you think??

