0

I am making a simple counter up/down using STM32F103C4, 2 buttons and a 7seg display, and the code is written in Keil uVision, from which the hex file is loaded into Proteus. The Counter Up part works perfectly, but the Counter Down part is just not registering any input. I have tried switching the pins and have come to the conclusion that the B0 pin is working but for some reason the B1 pin is not. I have searched all over, and asked many but I can't find a solution. Does this have to do with the special port B reset value?

Below is my code and a ss of the proteus scheme.

#include "stm32f10x.h"  // Device header

int dispBroj[]={0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92,  0x82, 0xF8, 0x80, 0x90};
int j = 0;

void reset()
{
    for(int i = 0; i < 7; i++)
    {
     GPIOA->ODR &=~ (1<<i);
    }
}

void cifre(int broj) 
{

    GPIOA->ODR |= dispBroj[broj];

}

int main(void)
{

RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;

GPIOA->CRL |=GPIO_CRL_MODE;
GPIOA->CRL &=~GPIO_CRL_CNF;

GPIOB->CRL|=((1<<7)|(1<<3));
GPIOB->CRL &=~((1<<2)|(1<<1)|(1<<0)|(1<<4)|(1<<5)|(1<<6));
GPIOB->CRH|=((1<<7)|(1<<3));
GPIOB->CRH &=~((1<<2)|(1<<1)|(1<<0)|(1<<4)|(1<<5)|(1<<6));


while(1){

    cifre(j%10);

    if(GPIOB->IDR & GPIO_IDR_IDR0){

        reset();
        j++;
        cifre(j%10);
        while(GPIOB->IDR & GPIO_IDR_IDR0){
            if(!GPIOB->IDR & GPIO_IDR_IDR0)
                break;
        }
    }

    if(GPIOB->IDR & GPIO_IDR_IDR1){

        reset();
        j--;
        cifre(j%10);
        while(GPIOB->IDR & GPIO_IDR_IDR1){
            if(!GPIOB->IDR & GPIO_IDR_IDR1)
                break;
        }
    }
}
}

enter image description here

My suspicion is that I declared the GPIO wrong.

James Z
  • 12,209
  • 10
  • 24
  • 44
Merisa
  • 1
  • 1

1 Answers1

-1

Try using the definition for GPIO init provided:

  GPIO_InitTypeDef  GPIO_InitStructure;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1| GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //you have an external pulldown.
  GPIO_Init(GPIOB, &GPIO_InitStructure);