//program starts from here
#include<stm32f401xe.h>
unsigned char Digit[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x6f};
void MSdelay(unsigned int );
void MSdelay(unsigned int times)
{
unsigned int i=0,j=0;
for(j=0;j<times;j++)
{
for(i=0;i<1400;i++);
}
}
int main(void)
{
unsigned int count1=0;//intialising count variable
RCC->AHB1ENR|=6;//initialising clock for port B and port C
GPIOB->MODER&=~(0XF);//clearing and setting port B as input
GPIOC->MODER&=~(0X0FFFFFFF);//resetting port C MODER register
GPIOC->MODER|=(0X05555555);//Setting all PC0-PC13 as outputs of port C
GPIOB->PUPDR&=~(0XF);//clearing pull-up/pull-down configuration of switch B
GPIOB->PUPDR|=(0X05);//setting them as pull up
while(1)
{
if(GPIOB->IDR&=0x3)
{
GPIOC->ODR=(Digit[0]<<7)|(Digit[0]);
}
if(GPIOB->IDR&=0X2)//If PB0 is ON
{
GPIOC->ODR=(Digit[count1/10]<<7)|Digit[count1%10];
count1++;
if(count1>=100)
{
count1=99;
GPIOC->ODR=(Digit[count1/10]<<7)|Digit[count1%10];
}
MSdelay(170);
}
else if(GPIOB->IDR&=0x1)//IF PB1 is ON
{
count1--;
GPIOC->ODR=(Digit[count1/10]<<7)|Digit[count1%10];
if(count1<1)
{
GPIOC->ODR=(Digit[0]<<7)|(Digit[0]);
}
MSdelay(170);
//INCREMENT(count1);
}
}
}
// program ends here