#include "stm32c0xx.h"
void SystemClock_Config(void);
void myDelay(int ms);
int main(void)
{
RCC -> IOPENR |= (1UL << 1);
GPIOB -> MODER &=~(3UL<<14);
GPIOB ->MODER |= (1UL<<14);
GPIOB ->OTYPER &=~(1UL<<7);
SystemClock_Config();
SystemCoreClockUpdate();
while(1)
{
GPIOB ->ODR ^= (1UL<<7);
myDelay(500);
}
}
void SystemClock_Config(void)
{
// Initialize the RCC Oscillators
RCC->CR |= (1 << 8); // Enable HSI
while (!(RCC->CR & (1 << 10))); // Wait for HSI to stabilize
RCC->CR &= ~(7<<11);
RCC->CR &= ~(7<<5);
RCC->CFGR &= ~(0x7 << 0); // Clear SW bits
// RCC->CFGR |= (0x1 << 0);
// Configure the Flash latency
FLASH->ACR |= (0x1 << 0); // Set the appropriate latency value
// Configure the AHB and APB clocks
RCC->CFGR &= ~(0xF << 8); // Clear HPRE and PPRE bits
RCC->CFGR &= ~(0x7 << 12);
// RCC->CFGR |= (0x0 << 4) | (0x4 << 8);
// Update the SystemCoreClock variable (optional but recommended)
}
void myDelay(int ms)
{
SysTick->CTRL=0;
SysTick->LOAD = 48000-1;
SysTick->VAL =0;
SysTick->CTRL = 5;
for(int i=0;i<ms;i++){
while((SysTick->CTRL & (1<<16))==0) {}
}
}