Stm32f103c8 LEDs blinking using Systick (Registres Programming)

83 Views Asked by At

I have an STM32f103c8 with 8Mhz SystemClock i configured My Systick to make delay every 1 seconde , i have a Button Connected to PA1 (Input Pull up) and Two Leds PB8 and PB9 i want when i press first time Button it starts blinking LEDs every 1 seconde for ever but when i press the button another time it turn off both LEDs i made a code and i want to see if it works because i don't really have the carte now ,

#include "stm32f10x.h"
int main(void){
    int S=0;
    RCC->APB2ENR|=0x0000000C;
    GPIOA->CRL=0;
    GPIOB->CRH=0;
    GPIOA->CRL|=0x00000880;
    GPIOA->ODR=1;
    GPIOB->CRH|=0x00000011;
    SysTick->LOAD=8000000;
    SysTick->VAL=0;
    SysTick->CTRL=5;
    while(1){
        if(!(GPIOA->IDR&(1<<1))){
            while(1){
        if((SysTick->CTRL&(1<<16))){
            if(S==0){
            GPIOB->BSRR=(1<<8);
            GPIOB->BSRR=(1<<25);
                S=1;
            }
                else{
                GPIOB->BSRR=(1<<24);
            GPIOB->BSRR=(1<<9);
                    S=0;
                }
            }
        if(!(GPIOA->IDR&0x02)){
        break;
        }
        }
                GPIOB->BSRR=(1<<24);
        GPIOB->BSRR=(1<<25);
        }
    }
}

I tried to use it in Proteus but the button doesn't work there i don't know why so i came here to see if my code is correct or poteus is not good

0

There are 0 best solutions below