This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

increment and decrement of 7 segment(0-99 count) using 2 buttons

Question: Interface two seven-segment LED displays to Port C of STM32F4 MCU that mustincrement and show the rolling of two digits from 00 onwards, to a max of 99, when aswitch SW1 (PB0) is pressed. And must decrement when the user is pressing SW2(PB1).

the issues we are facing is there is increment and decrement happening but then increment is not happening after it is decrementing till 0

the other issues which are being faced are mentioned below 

1) the system is operating even when both the both the switches are off to the topmost mentioned conditional IF loop let it be increment or decrement

//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

The conditions which are to be satisfied for us are 

1) both on nothing should be done
2) both off nothing should be done
3) xor operation it should do increment/decrement(one OFF one ON combination)
4) after 99 in increment it should halt and not go to 0
5) after 0 in decrement it should stop

the proteus desgin we are testing on is mentioned below 

proteus simulation link