/********************************** (C) COPYRIGHT *******************************
* File Name : system_ch32v00x.c
* Author : WCH
* Version : V1.0.0
* Date : 2023/12/26
* Description : CH32V00x Device Peripheral Access Layer System Source File.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include <ch32v00x.h>
/*
* Uncomment the line corresponding to the desired System clock (SYSCLK) frequency (after
* reset the HSI is used as SYSCLK source).
* If none of the define below is enabled, the HSI is used as System clock source.
*/
//#define SYSCLK_FREQ_8MHz_HSI 8000000
//#define SYSCLK_FREQ_24MHZ_HSI HSI_VALUE
//#define SYSCLK_FREQ_48MHZ_HSI 48000000
//#define SYSCLK_FREQ_8MHz_HSE 8000000
//#define SYSCLK_FREQ_24MHz_HSE HSE_VALUE
#define SYSCLK_FREQ_48MHz_HSE 48000000
/* Clock Definitions */
#ifdef SYSCLK_FREQ_8MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_8MHz_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_24MHZ_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_24MHZ_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_48MHZ_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_48MHZ_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_8MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_8MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_24MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_24MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_48MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz_HSE; /* System Clock Frequency (Core Clock) */
#else
uint32_t SystemCoreClock = HSI_VALUE;
#endif
__I uint8_t AHBPrescTable[16] = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8};
/* system_private_function_proto_types */
static void SetSysClock(void);
#ifdef SYSCLK_FREQ_8MHz_HSI
static void SetSysClockTo_8MHz_HSI(void);
#elif defined SYSCLK_FREQ_24MHZ_HSI
static void SetSysClockTo_24MHZ_HSI(void);
#elif defined SYSCLK_FREQ_48MHZ_HSI
static void SetSysClockTo_48MHZ_HSI(void);
#elif defined SYSCLK_FREQ_8MHz_HSE
static void SetSysClockTo_8MHz_HSE(void);
#elif defined SYSCLK_FREQ_24MHz_HSE
static void SetSysClockTo_24MHz_HSE(void);
#elif defined SYSCLK_FREQ_48MHz_HSE
static void SetSysClockTo_48MHz_HSE(void);
#endif
/*********************************************************************
* @fn SystemInit
*
* @brief Setup the microcontroller system Initialize the Embedded Flash Interface,
* the PLL and update the SystemCoreClock variable.
*
* @return none
*/
void SystemInit (void)
{
RCC->CTLR |= (uint32_t)0x00000001;
RCC->CFGR0 &= (uint32_t)0xF8FF0000;
RCC->CTLR &= (uint32_t)0xFEF6FFFF;
RCC->CTLR &= (uint32_t)0xFFFBFFFF;
RCC->CFGR0 &= (uint32_t)0xFFFEFFFF;
RCC->INTR = 0x009F0000;
RCC_AdjustHSICalibrationValue(0x10);
SetSysClock();
}
/*********************************************************************
* @fn SystemCoreClockUpdate
*
* @brief Update SystemCoreClock variable according to Clock Register Values.
*
* @return none
*/
void SystemCoreClockUpdate (void)
{
uint32_t tmp = 0, pllsource = 0;
tmp = RCC->CFGR0 & RCC_SWS;
switch (tmp)
{
case 0x00:
SystemCoreClock = HSI_VALUE;
break;
case 0x04:
SystemCoreClock = HSE_VALUE;
break;
case 0x08:
pllsource = RCC->CFGR0 & RCC_PLLSRC;
if (pllsource == 0x00)
{
SystemCoreClock = HSI_VALUE * 2;
}
else
{
SystemCoreClock = HSE_VALUE * 2;
}
break;
default:
SystemCoreClock = HSI_VALUE;
break;
}
tmp = AHBPrescTable[((RCC->CFGR0 & RCC_HPRE) >> 4)];
if(((RCC->CFGR0 & RCC_HPRE) >> 4) < 8)
{
SystemCoreClock /= tmp;
}
else
{
SystemCoreClock >>= tmp;
}
}
/*********************************************************************
* @fn SetSysClock
*
* @brief Configures the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClock(void)
{
RCC->APB2PCENR |= RCC_APB2Periph_GPIOD;
GPIOD->CFGLR&=(~0xF0);
GPIOD->CFGLR|=0x80;
GPIOD->BSHR =0x2;
//GPIO_IPD_Unused();
#ifdef SYSCLK_FREQ_8MHz_HSI
SetSysClockTo_8MHz_HSI();
#elif defined SYSCLK_FREQ_24MHZ_HSI
SetSysClockTo_24MHZ_HSI();
#elif defined SYSCLK_FREQ_48MHZ_HSI
SetSysClockTo_48MHZ_HSI();
#elif defined SYSCLK_FREQ_8MHz_HSE
SetSysClockTo_8MHz_HSE();
#elif defined SYSCLK_FREQ_24MHz_HSE
SetSysClockTo_24MHz_HSE();
#elif defined SYSCLK_FREQ_48MHz_HSE
SetSysClockTo_48MHz_HSE();
#endif
/* If none of the define above is enabled, the HSI is used as System clock.
* source (default after reset)
*/
}
#ifdef SYSCLK_FREQ_8MHz_HSI
/*********************************************************************
* @fn SetSysClockTo_8MHz_HSI
*
* @brief Sets HSI as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo_8MHz_HSI(void)
{
/* Flash 0 wait state */
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_0;
/* HCLK = SYSCLK = APB1 */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV3;
}
#elif defined SYSCLK_FREQ_24MHZ_HSI
/*********************************************************************
* @fn SetSysClockTo_24MHZ_HSI
*
* @brief Sets System clock frequency to 24MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo_24MHZ_HSI(void)
{
/* Flash 0 wait state */
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_0;
/* HCLK = SYSCLK = APB1 */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
}
#elif defined SYSCLK_FREQ_48MHZ_HSI
/*********************************************************************
* @fn SetSysClockTo_48MHZ_HSI
*
* @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo_48MHZ_HSI(void)
{
uint8_t tmp = 0;
tmp = *( uint8_t * )CFG0_PLL_TRIM;
if(tmp != 0xFF)
{
RCC_AdjustHSICalibrationValue((tmp & 0x1F));
}
/* Flash 0 wait state */
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_1;
/* HCLK = SYSCLK = APB1 */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PLL configuration: PLLCLK = HSI * 2 = 48 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Mul2);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#elif defined SYSCLK_FREQ_8MHz_HSE
/*********************************************************************
* @fn SetSysClockTo_8MHz_HSE
*
没有合适的资源?快使用搜索试试~ 我知道了~
ch32v003f4p6通过软件IIC点亮oled灯
共76个文件
o:24个
d:24个
mk:7个
需积分: 0 3 下载量 52 浏览量
2024-08-15
23:18:30
上传
评论
收藏 402KB ZIP 举报
温馨提示
ch32v003f4p6通过软件IIC点亮oled灯
资源推荐
资源详情
资源评论
收起资源包目录
软件IIC_OLED.zip (76个子文件)
软件IIC_OLED
.cproject 25KB
User
OLED_Font.c 9KB
OLED_Font.h 140B
OLED.c 8KB
OLED.h 567B
ch32v00x_it.h 762B
system_ch32v00x.c 13KB
system_ch32v00x.h 1KB
main.c 3KB
ch32v00x_it.c 1KB
ch32v00x_conf.h 1KB
.settings
language.settings.xml 1KB
org.eclipse.core.resources.prefs 128B
obj
makefile 2KB
Core
subdir.mk 1KB
core_riscv.o 15KB
core_riscv.d 94B
User
subdir.mk 1KB
OLED.o 57KB
OLED_Font.o 12KB
main.d 4KB
system_ch32v00x.o 24KB
ch32v00x_it.d 4KB
OLED_Font.d 4KB
main.o 22KB
ch32v00x_it.o 12KB
OLED.d 4KB
system_ch32v00x.d 4KB
sources.mk 610B
GPIO_Toggle.hex 17KB
Startup
startup_ch32v00x.o 6KB
subdir.mk 1KB
startup_ch32v00x.d 112B
GPIO_Toggle.elf 106KB
objects.mk 245B
Peripheral
src
ch32v00x_tim.o 169KB
ch32v00x_usart.d 4KB
subdir.mk 13KB
ch32v00x_spi.o 40KB
ch32v00x_adc.o 72KB
ch32v00x_pwr.d 4KB
ch32v00x_rcc.o 53KB
ch32v00x_iwdg.d 4KB
ch32v00x_opa.o 16KB
ch32v00x_gpio.d 4KB
ch32v00x_spi.d 4KB
ch32v00x_rcc.d 4KB
ch32v00x_adc.d 4KB
ch32v00x_wwdg.o 20KB
ch32v00x_i2c.d 4KB
ch32v00x_dbgmcu.o 17KB
ch32v00x_misc.d 4KB
ch32v00x_dma.o 28KB
ch32v00x_pwr.o 27KB
ch32v00x_exti.d 4KB
ch32v00x_iwdg.o 18KB
ch32v00x_opa.d 4KB
ch32v00x_dma.d 4KB
ch32v00x_flash.o 88KB
ch32v00x_i2c.o 62KB
ch32v00x_tim.d 4KB
ch32v00x_wwdg.d 4KB
ch32v00x_dbgmcu.d 4KB
ch32v00x_gpio.o 45KB
ch32v00x_exti.o 23KB
ch32v00x_misc.o 20KB
ch32v00x_flash.d 4KB
ch32v00x_usart.o 58KB
GPIO_Toggle.lst 92KB
Debug
subdir.mk 1KB
debug.d 4KB
debug.o 31KB
GPIO_Toggle.map 82KB
GPIO_Toggle.wvproj 202B
.template 711B
.project 2KB
共 76 条
- 1
资源评论
marxing
- 粉丝: 9
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功