Switch Input and LED output

Switch connected at Port B1 and output connected at Port C13







#include "stm32f1xx.h"

void waitForAmoment(int Moment)
{
 volatile int i,j;
 for (i = 0; i < Moment; ++i)
 {
  j++;
 }
}

int main(void)
{
//Setup Reset and Clock Control Register
  RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;  //Enable clock to Port C
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;  //Enable clock to Port B

//Setup GPIO Registers of Port C
GPIOC->CRH |= GPIO_CRH_MODE13; //Port C13 in Output Mode, 50 MHz
GPIOC->CRH &= ~(GPIO_CRH_CNF13); //Port C13 in General Purpose output, Push Pull

//Setup GPIO Registers of Port B
GPIOB->CRL &= ~(GPIO_CRL_MODE1); //Port B1 in Input Mode
GPIOB->CRL |= GPIO_CRL_CNF1_0; //Port B1 in Floating State
GPIOB->CRL &= ~(GPIO_CRL_CNF1_1);

    while(1)
    {

    if(GPIOB->IDR & GPIO_IDR_IDR1)
    {
    GPIOC->BSRR |= GPIO_BSRR_BS13;
    }
    else
    {
GPIOC->BRR |= GPIO_BRR_BR13;
}

    }
}

Comments

Popular posts from this blog

HackRF with srsLTE and openlte

Blinking a LED in STM32F103C8T6 (Blue Pill) Board

Read Continuously from Serial Port in QT