diff --git a/Embedded/xingyi-Starry/Project/.vscode/c_cpp_properties.json b/Embedded/xingyi-Starry/Project/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..8262eb4 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/.vscode/c_cpp_properties.json @@ -0,0 +1,93 @@ +{ + "configurations": [ + { + "name": "Target 1", + "includePath": [ + "c:\\Users\\97329\\Desktop\\works\\BUPTSmartCarTask2\\Embedded\\xingyi-Starry\\Project\\Start", + "c:\\Users\\97329\\Desktop\\works\\BUPTSmartCarTask2\\Embedded\\xingyi-Starry\\Project\\Library", + "c:\\Users\\97329\\Desktop\\works\\BUPTSmartCarTask2\\Embedded\\xingyi-Starry\\Project\\User", + "c:\\Users\\97329\\Desktop\\works\\BUPTSmartCarTask2\\Embedded\\xingyi-Starry\\Project\\System", + "c:\\Users\\97329\\Desktop\\works\\BUPTSmartCarTask2\\Embedded\\xingyi-Starry\\Project\\Hardware", + "C:\\Keil_v5\\ARM\\ARMCC\\include", + "C:\\Keil_v5\\ARM\\ARMCC\\include\\rw" + ], + "defines": [ + "USE_STDPERIPH_DRIVER", + "__CC_ARM", + "__arm__", + "__align(x)=", + "__ALIGNOF__(x)=", + "__alignof__(x)=", + "__asm(x)=", + "__forceinline=", + "__restrict=", + "__global_reg(n)=", + "__inline=", + "__int64=long long", + "__INTADDR__(expr)=0", + "__irq=", + "__packed=", + "__pure=", + "__smc(n)=", + "__svc(n)=", + "__svc_indirect(n)=", + "__svc_indirect_r7(n)=", + "__value_in_regs=", + "__weak=", + "__writeonly=", + "__declspec(x)=", + "__attribute__(x)=", + "__nonnull__(x)=", + "__register=", + "__breakpoint(x)=", + "__cdp(x,y,z)=", + "__clrex()=", + "__clz(x)=0U", + "__current_pc()=0U", + "__current_sp()=0U", + "__disable_fiq()=", + "__disable_irq()=", + "__dmb(x)=", + "__dsb(x)=", + "__enable_fiq()=", + "__enable_irq()=", + "__fabs(x)=0.0", + "__fabsf(x)=0.0f", + "__force_loads()=", + "__force_stores()=", + "__isb(x)=", + "__ldrex(x)=0U", + "__ldrexd(x)=0U", + "__ldrt(x)=0U", + "__memory_changed()=", + "__nop()=", + "__pld(...)=", + "__pli(...)=", + "__qadd(x,y)=0", + "__qdbl(x)=0", + "__qsub(x,y)=0", + "__rbit(x)=0U", + "__rev(x)=0U", + "__return_address()=0U", + "__ror(x,y)=0U", + "__schedule_barrier()=", + "__semihost(x,y)=0", + "__sev()=", + "__sqrt(x)=0.0", + "__sqrtf(x)=0.0f", + "__ssat(x,y)=0", + "__strex(x,y)=0U", + "__strexd(x,y)=0", + "__strt(x,y)=", + "__swp(x,y)=0U", + "__usat(x,y)=0U", + "__wfe()=", + "__wfi()=", + "__yield()=", + "__vfp_status(x,y)=0" + ], + "intelliSenseMode": "${default}" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/Embedded/xingyi-Starry/Project/.vscode/keil-assistant.log b/Embedded/xingyi-Starry/Project/.vscode/keil-assistant.log new file mode 100644 index 0000000..80fbfa7 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/.vscode/keil-assistant.log @@ -0,0 +1,8 @@ +[info] Log at : 2023/11/2|14:22:58|GMT+0800 + +[info] Log at : 2023/11/2|16:04:28|GMT+0800 + +[info] Log at : 2023/11/2|18:57:07|GMT+0800 + +[info] Log at : 2023/11/2|19:25:01|GMT+0800 + diff --git a/Embedded/xingyi-Starry/Project/.vscode/uv4.log b/Embedded/xingyi-Starry/Project/.vscode/uv4.log new file mode 100644 index 0000000..c6f3005 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/.vscode/uv4.log @@ -0,0 +1,3 @@ +Load "c:\\Users\\97329\\Desktop\\works\\BUPTSmartCarTask2\\Embedded\\xingyi-Starry\\4-1 OLEDʾ\\Objects\\Project.axf" +Erase Done.Programming Done.Verify OK.Application running ... +Flash Load finished at 18:54:14 diff --git a/Embedded/xingyi-Starry/Project/.vscode/uv4.log.lock b/Embedded/xingyi-Starry/Project/.vscode/uv4.log.lock new file mode 100644 index 0000000..dd2b649 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/.vscode/uv4.log.lock @@ -0,0 +1 @@ +2023/11/2 18:54:15 \ No newline at end of file diff --git a/Embedded/xingyi-Starry/Project/Hardware/ADC.c b/Embedded/xingyi-Starry/Project/Hardware/ADC.c new file mode 100644 index 0000000..442971f --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/ADC.c @@ -0,0 +1,48 @@ +#include "stm32f10x.h" + +void AD_Init(void) +{ + //开启外设时钟 + RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); + + //配置ADC预分频器 + RCC_ADCCLKConfig(6); + + //GPIO初始化 + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOB,&GPIO_InitStructure); + + //配置多路开关 + ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_55Cycles5); + + //配置ADC转换器 + ADC_InitTypeDef ADC_Initstructure; + ADC_Initstructure.ADC_ContinuousConvMode = DISABLE; + ADC_Initstructure.ADC_DataAlign = ADC_DataAlign_Right; + ADC_Initstructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; + ADC_Initstructure.ADC_Mode = ADC_Mode_Independent; + ADC_Initstructure.ADC_NbrOfChannel = 1; + ADC_Initstructure.ADC_ScanConvMode = DISABLE; + ADC_Init(ADC1, &ADC_Initstructure); + + //开启ADC + ADC_Cmd(ADC1, ENABLE); + + //校准ADC + ADC_ResetCalibration(ADC1); //复位校准 + while (ADC_GetResetCalibrationStatus(ADC1) == SET); //等待复位完成 + + ADC_StartCalibration(ADC1); //启动校准 + while (ADC_GetResetCalibrationStatus(ADC1) == SET); //等待校准完成 +} + +uint16_t AD_GetValue(void) +{ + ADC_SoftwareStartConvCmd(ADC1, ENABLE); //启动转换 + while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); //等待转换完成 + return ADC_GetConversionValue(ADC1); +} diff --git a/Embedded/xingyi-Starry/Project/Hardware/ADC.h b/Embedded/xingyi-Starry/Project/Hardware/ADC.h new file mode 100644 index 0000000..68d96e7 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/ADC.h @@ -0,0 +1,6 @@ +#ifndef __AD_H +#define __AD_H +void AD_Init(void); +uint16_t AD_GetValue(void); + +#endif diff --git a/Embedded/xingyi-Starry/Project/Hardware/Key.c b/Embedded/xingyi-Starry/Project/Hardware/Key.c new file mode 100644 index 0000000..96321eb --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/Key.c @@ -0,0 +1,46 @@ +#include "stm32f10x.h" // Device header +#include "Delay.h" +#include "LED.h" + +void Key_Init(void) +{ + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); + + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOB,&GPIO_InitStructure); + + GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource13); + + EXTI_InitTypeDef EXTI_InitStructure; + EXTI_InitStructure.EXTI_Line = EXTI_Line13; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_Init(&EXTI_InitStructure); + + NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); + NVIC_InitTypeDef NVIC_InitStructure; + NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; + NVIC_Init(&NVIC_InitStructure); +} + +void EXTI15_10_IRQHandler(void) +{ + if (EXTI_GetITStatus(EXTI_Line13) == SET) + { + LED2_Turn(); + Delay_ms(10); + while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13) == 1); + Delay_ms(10); + EXTI_ClearITPendingBit(EXTI_Line13); + + } + +} diff --git a/Embedded/xingyi-Starry/Project/Hardware/Key.h b/Embedded/xingyi-Starry/Project/Hardware/Key.h new file mode 100644 index 0000000..0cd38a4 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/Key.h @@ -0,0 +1,6 @@ +#ifndef __KEY_H +#define __KEY_H + +void Key_Init(void); + +#endif diff --git a/Embedded/xingyi-Starry/Project/Hardware/LED.c b/Embedded/xingyi-Starry/Project/Hardware/LED.c new file mode 100644 index 0000000..f56e25a --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/LED.c @@ -0,0 +1,38 @@ +#include "stm32f10x.h" // Device header + +void LED_Init(void) +{ + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); + + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_6; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOA, &GPIO_InitStructure); + + GPIO_SetBits(GPIOA, GPIO_Pin_3 | GPIO_Pin_6); +} + +void LED1_Turn(void) +{ + if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_3) == 0) + { + GPIO_SetBits(GPIOA, GPIO_Pin_3); + } + else + { + GPIO_ResetBits(GPIOA, GPIO_Pin_3); + } +} + +void LED2_Turn(void) +{ + if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_6) == 0) + { + GPIO_SetBits(GPIOA, GPIO_Pin_6); + } + else + { + GPIO_ResetBits(GPIOA, GPIO_Pin_6); + } +} diff --git a/Embedded/xingyi-Starry/Project/Hardware/LED.h b/Embedded/xingyi-Starry/Project/Hardware/LED.h new file mode 100644 index 0000000..615a374 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/LED.h @@ -0,0 +1,8 @@ +#ifndef __LED_H +#define __LED_H + +void LED_Init(void); +void LED1_Turn(void); +void LED2_Turn(void); + +#endif diff --git a/Embedded/xingyi-Starry/Project/Hardware/OLED.c b/Embedded/xingyi-Starry/Project/Hardware/OLED.c new file mode 100644 index 0000000..f1ea503 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/OLED.c @@ -0,0 +1,321 @@ +#include "stm32f10x.h" +#include "OLED_Font.h" + +/*引脚配置*/ +#define OLED_W_SCL(x) GPIO_WriteBit(GPIOB, GPIO_Pin_8, (BitAction)(x)) +#define OLED_W_SDA(x) GPIO_WriteBit(GPIOB, GPIO_Pin_9, (BitAction)(x)) + +/*引脚初始化*/ +void OLED_I2C_Init(void) +{ + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); + + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; + GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; + GPIO_Init(GPIOB, &GPIO_InitStructure); + + OLED_W_SCL(1); + OLED_W_SDA(1); +} + +/** + * @brief I2C开始 + * @param 无 + * @retval 无 + */ +void OLED_I2C_Start(void) +{ + OLED_W_SDA(1); + OLED_W_SCL(1); + OLED_W_SDA(0); + OLED_W_SCL(0); +} + +/** + * @brief I2C停止 + * @param 无 + * @retval 无 + */ +void OLED_I2C_Stop(void) +{ + OLED_W_SDA(0); + OLED_W_SCL(1); + OLED_W_SDA(1); +} + +/** + * @brief I2C发送一个字节 + * @param Byte 要发送的一个字节 + * @retval 无 + */ +void OLED_I2C_SendByte(uint8_t Byte) +{ + uint8_t i; + for (i = 0; i < 8; i++) + { + OLED_W_SDA(Byte & (0x80 >> i)); + OLED_W_SCL(1); + OLED_W_SCL(0); + } + OLED_W_SCL(1); //额外的一个时钟,不处理应答信号 + OLED_W_SCL(0); +} + +/** + * @brief OLED写命令 + * @param Command 要写入的命令 + * @retval 无 + */ +void OLED_WriteCommand(uint8_t Command) +{ + OLED_I2C_Start(); + OLED_I2C_SendByte(0x78); //从机地址 + OLED_I2C_SendByte(0x00); //写命令 + OLED_I2C_SendByte(Command); + OLED_I2C_Stop(); +} + +/** + * @brief OLED写数据 + * @param Data 要写入的数据 + * @retval 无 + */ +void OLED_WriteData(uint8_t Data) +{ + OLED_I2C_Start(); + OLED_I2C_SendByte(0x78); //从机地址 + OLED_I2C_SendByte(0x40); //写数据 + OLED_I2C_SendByte(Data); + OLED_I2C_Stop(); +} + +/** + * @brief OLED设置光标位置 + * @param Y 以左上角为原点,向下方向的坐标,范围:0~7 + * @param X 以左上角为原点,向右方向的坐标,范围:0~127 + * @retval 无 + */ +void OLED_SetCursor(uint8_t Y, uint8_t X) +{ + OLED_WriteCommand(0xB0 | Y); //设置Y位置 + OLED_WriteCommand(0x10 | ((X & 0xF0) >> 4)); //设置X位置高4位 + OLED_WriteCommand(0x00 | (X & 0x0F)); //设置X位置低4位 +} + +/** + * @brief OLED清屏 + * @param 无 + * @retval 无 + */ +void OLED_Clear(void) +{ + uint8_t i, j; + for (j = 0; j < 8; j++) + { + OLED_SetCursor(j, 0); + for(i = 0; i < 128; i++) + { + OLED_WriteData(0x00); + } + } +} + +/** + * @brief OLED显示一个字符 + * @param Line 行位置,范围:1~4 + * @param Column 列位置,范围:1~16 + * @param Char 要显示的一个字符,范围:ASCII可见字符 + * @retval 无 + */ +void OLED_ShowChar(uint8_t Line, uint8_t Column, char Char) +{ + uint8_t i; + OLED_SetCursor((Line - 1) * 2, (Column - 1) * 8); //设置光标位置在上半部分 + for (i = 0; i < 8; i++) + { + OLED_WriteData(OLED_F8x16[Char - ' '][i]); //显示上半部分内容 + } + OLED_SetCursor((Line - 1) * 2 + 1, (Column - 1) * 8); //设置光标位置在下半部分 + for (i = 0; i < 8; i++) + { + OLED_WriteData(OLED_F8x16[Char - ' '][i + 8]); //显示下半部分内容 + } +} + +/** + * @brief OLED显示字符串 + * @param Line 起始行位置,范围:1~4 + * @param Column 起始列位置,范围:1~16 + * @param String 要显示的字符串,范围:ASCII可见字符 + * @retval 无 + */ +void OLED_ShowString(uint8_t Line, uint8_t Column, char *String) +{ + uint8_t i; + for (i = 0; String[i] != '\0'; i++) + { + OLED_ShowChar(Line, Column + i, String[i]); + } +} + +/** + * @brief OLED次方函数 + * @retval 返回值等于X的Y次方 + */ +uint32_t OLED_Pow(uint32_t X, uint32_t Y) +{ + uint32_t Result = 1; + while (Y--) + { + Result *= X; + } + return Result; +} + +/** + * @brief OLED显示数字(十进制,正数) + * @param Line 起始行位置,范围:1~4 + * @param Column 起始列位置,范围:1~16 + * @param Number 要显示的数字,范围:0~4294967295 + * @param Length 要显示数字的长度,范围:1~10 + * @retval 无 + */ +void OLED_ShowNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length) +{ + uint8_t i; + for (i = 0; i < Length; i++) + { + OLED_ShowChar(Line, Column + i, Number / OLED_Pow(10, Length - i - 1) % 10 + '0'); + } +} + +/** + * @brief OLED显示数字(十进制,带符号数) + * @param Line 起始行位置,范围:1~4 + * @param Column 起始列位置,范围:1~16 + * @param Number 要显示的数字,范围:-2147483648~2147483647 + * @param Length 要显示数字的长度,范围:1~10 + * @retval 无 + */ +void OLED_ShowSignedNum(uint8_t Line, uint8_t Column, int32_t Number, uint8_t Length) +{ + uint8_t i; + uint32_t Number1; + if (Number >= 0) + { + OLED_ShowChar(Line, Column, '+'); + Number1 = Number; + } + else + { + OLED_ShowChar(Line, Column, '-'); + Number1 = -Number; + } + for (i = 0; i < Length; i++) + { + OLED_ShowChar(Line, Column + i + 1, Number1 / OLED_Pow(10, Length - i - 1) % 10 + '0'); + } +} + +/** + * @brief OLED显示数字(十六进制,正数) + * @param Line 起始行位置,范围:1~4 + * @param Column 起始列位置,范围:1~16 + * @param Number 要显示的数字,范围:0~0xFFFFFFFF + * @param Length 要显示数字的长度,范围:1~8 + * @retval 无 + */ +void OLED_ShowHexNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length) +{ + uint8_t i, SingleNumber; + for (i = 0; i < Length; i++) + { + SingleNumber = Number / OLED_Pow(16, Length - i - 1) % 16; + if (SingleNumber < 10) + { + OLED_ShowChar(Line, Column + i, SingleNumber + '0'); + } + else + { + OLED_ShowChar(Line, Column + i, SingleNumber - 10 + 'A'); + } + } +} + +/** + * @brief OLED显示数字(二进制,正数) + * @param Line 起始行位置,范围:1~4 + * @param Column 起始列位置,范围:1~16 + * @param Number 要显示的数字,范围:0~1111 1111 1111 1111 + * @param Length 要显示数字的长度,范围:1~16 + * @retval 无 + */ +void OLED_ShowBinNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length) +{ + uint8_t i; + for (i = 0; i < Length; i++) + { + OLED_ShowChar(Line, Column + i, Number / OLED_Pow(2, Length - i - 1) % 2 + '0'); + } +} + +/** + * @brief OLED初始化 + * @param 无 + * @retval 无 + */ +void OLED_Init(void) +{ + uint32_t i, j; + + for (i = 0; i < 1000; i++) //上电延时 + { + for (j = 0; j < 1000; j++); + } + + OLED_I2C_Init(); //端口初始化 + + OLED_WriteCommand(0xAE); //关闭显示 + + OLED_WriteCommand(0xD5); //设置显示时钟分频比/振荡器频率 + OLED_WriteCommand(0x80); + + OLED_WriteCommand(0xA8); //设置多路复用率 + OLED_WriteCommand(0x3F); + + OLED_WriteCommand(0xD3); //设置显示偏移 + OLED_WriteCommand(0x00); + + OLED_WriteCommand(0x40); //设置显示开始行 + + OLED_WriteCommand(0xA1); //设置左右方向,0xA1正常 0xA0左右反置 + + OLED_WriteCommand(0xC8); //设置上下方向,0xC8正常 0xC0上下反置 + + OLED_WriteCommand(0xDA); //设置COM引脚硬件配置 + OLED_WriteCommand(0x12); + + OLED_WriteCommand(0x81); //设置对比度控制 + OLED_WriteCommand(0xCF); + + OLED_WriteCommand(0xD9); //设置预充电周期 + OLED_WriteCommand(0xF1); + + OLED_WriteCommand(0xDB); //设置VCOMH取消选择级别 + OLED_WriteCommand(0x30); + + OLED_WriteCommand(0xA4); //设置整个显示打开/关闭 + + OLED_WriteCommand(0xA6); //设置正常/倒转显示 + + OLED_WriteCommand(0x8D); //设置充电泵 + OLED_WriteCommand(0x14); + + OLED_WriteCommand(0xAF); //开启显示 + + OLED_Clear(); //OLED清屏 +} diff --git a/Embedded/xingyi-Starry/Project/Hardware/OLED.h b/Embedded/xingyi-Starry/Project/Hardware/OLED.h new file mode 100644 index 0000000..16e0f4a --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/OLED.h @@ -0,0 +1,13 @@ +#ifndef __OLED_H +#define __OLED_H + +void OLED_Init(void); +void OLED_Clear(void); +void OLED_ShowChar(uint8_t Line, uint8_t Column, char Char); +void OLED_ShowString(uint8_t Line, uint8_t Column, char *String); +void OLED_ShowNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length); +void OLED_ShowSignedNum(uint8_t Line, uint8_t Column, int32_t Number, uint8_t Length); +void OLED_ShowHexNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length); +void OLED_ShowBinNum(uint8_t Line, uint8_t Column, uint32_t Number, uint8_t Length); + +#endif diff --git a/Embedded/xingyi-Starry/Project/Hardware/OLED_Font.h b/Embedded/xingyi-Starry/Project/Hardware/OLED_Font.h new file mode 100644 index 0000000..a2619c4 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/OLED_Font.h @@ -0,0 +1,293 @@ +#ifndef __OLED_FONT_H +#define __OLED_FONT_H + +/*OLED字模库,宽8像素,高16像素*/ +const uint8_t OLED_F8x16[][16]= +{ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0 + + 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1 + + 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2 + + 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00, + 0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3 + + 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00, + 0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4 + + 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00, + 0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5 + + 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00, + 0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6 + + 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7 + + 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00, + 0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8 + + 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00, + 0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9 + + 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00, + 0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10 + + 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00, + 0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11 + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12 + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13 + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14 + + 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04, + 0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15 + + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00, + 0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16 + + 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00, + 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17 + + 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00, + 0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18 + + 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00, + 0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19 + + 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00, + 0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20 + + 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00, + 0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21 + + 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00, + 0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22 + + 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00, + 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23 + + 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00, + 0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24 + + 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00, + 0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25 + + 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00, + 0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26 + + 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27 + + 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00, + 0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28 + + 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00, + 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29 + + 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00, + 0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30 + + 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00, + 0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31 + + 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00, + 0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32 + + 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00, + 0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33 + + 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00, + 0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34 + + 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00, + 0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35 + + 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00, + 0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36 + + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00, + 0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37 + + 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00, + 0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38 + + 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00, + 0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39 + + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08, + 0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40 + + 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00, + 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41 + + 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00, + 0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42 + + 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00, + 0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43 + + 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00, + 0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44 + + 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00, + 0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45 + + 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08, + 0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46 + + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00, + 0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47 + + 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00, + 0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48 + + 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00, + 0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49 + + 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00, + 0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50 + + 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00, + 0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51 + + 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00, + 0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52 + + 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08, + 0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53 + + 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08, + 0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54 + + 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00, + 0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55 + + 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08, + 0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56 + + 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00, + 0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57 + + 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00, + 0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58 + + 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00, + 0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59 + + 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60 + + 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00, + 0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61 + + 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62 + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63 + + 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64 + + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00, + 0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65 + + 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00, + 0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66 + + 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00, + 0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67 + + 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00, + 0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68 + + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00, + 0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69 + + 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18, + 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70 + + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00, + 0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71 + + 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00, + 0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72 + + 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00, + 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73 + + 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00, + 0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74 + + 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00, + 0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75 + + 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00, + 0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76 + + 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00, + 0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77 + + 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00, + 0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78 + + 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00, + 0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79 + + 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00, + 0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80 + + 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00, + 0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81 + + 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00, + 0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82 + + 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00, + 0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83 + + 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00, + 0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84 + + 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00, + 0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85 + + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80, + 0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86 + + 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80, + 0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87 + + 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00, + 0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88 + + 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80, + 0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89 + + 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00, + 0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90 + + 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02, + 0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91 + + 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92 + + 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00, + 0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93 + + 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94 +}; + +#endif diff --git a/Embedded/xingyi-Starry/Project/Hardware/PWM.c b/Embedded/xingyi-Starry/Project/Hardware/PWM.c new file mode 100644 index 0000000..ac43e57 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/PWM.c @@ -0,0 +1,44 @@ +#include "stm32f10x.h" + +void PWM_Init() +{ + // 开启外设时钟 + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); + + // GPIO初始化 + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOA, &GPIO_InitStructure); + + // 选择定时器 + TIM_InternalClockConfig(TIM2); + + // 定时器初始化 + TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseStructure.TIM_Period = 100 - 1; + TIM_TimeBaseStructure.TIM_Prescaler = 720 - 1; + TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; + TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); + + // 输出比较单元初始化 + TIM_OCInitTypeDef TIM_OCInitStructure; + TIM_OCStructInit(&TIM_OCInitStructure); // 结构体初始化防止出bug + TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; + TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; + TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; + TIM_OCInitStructure.TIM_Pulse = 50; // CCR的值,重要 + TIM_OC1Init(TIM2, &TIM_OCInitStructure); + + // 使能定时器 + TIM_Cmd(TIM2, ENABLE); +} + +void PWM_SetCompare1(uint8_t Compare) +{ + TIM_SetCompare1(TIM2, Compare); +} diff --git a/Embedded/xingyi-Starry/Project/Hardware/PWM.h b/Embedded/xingyi-Starry/Project/Hardware/PWM.h new file mode 100644 index 0000000..db2f9ac --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/PWM.h @@ -0,0 +1,7 @@ +#ifndef __PWM_H +#define __PWM_H + +void PWM_Init(); +void PWM_SetCompare1(uint8_t Compare); + +#endif diff --git a/Embedded/xingyi-Starry/Project/Hardware/Timer.c b/Embedded/xingyi-Starry/Project/Hardware/Timer.c new file mode 100644 index 0000000..1b1f7b6 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/Timer.c @@ -0,0 +1,101 @@ +#include "stm32f10x.h" +#include "LED.h" +#include "PWM.h" + +//TIM3用于实现LED闪烁,TIM4用于实现PWM调频 + +uint8_t PWM_flag = 0; +uint8_t PWM_CCR = 0; + +void Timer_Init(void) +{ +//开启定时器时钟 + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE); + +//选择定时器 + TIM_InternalClockConfig(TIM3); + TIM_InternalClockConfig(TIM4); + +//定时器初始化 + TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseStructure.TIM_Period = 7199; + TIM_TimeBaseStructure.TIM_Prescaler = 9999; + TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; + TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure); + + TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseStructure.TIM_Period = 7199; + TIM_TimeBaseStructure.TIM_Prescaler = 199; + TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; + TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStructure); + +//使能中断 + TIM_ClearFlag(TIM3,TIM_FLAG_Update); + TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); + + TIM_ClearFlag(TIM4,TIM_FLAG_Update); + TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE); + +//NVIC优先级分组 + NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); + +//NVIC初始化 + NVIC_InitTypeDef NVIC_InitStructure; + NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; + NVIC_Init(&NVIC_InitStructure); + + NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; + NVIC_Init(&NVIC_InitStructure); + +//使能定时器 + TIM_Cmd(TIM3,ENABLE); + TIM_Cmd(TIM4,ENABLE); +} + +//LED闪烁 +void TIM3_IRQHandler(void) +{ + if (TIM_GetITStatus(TIM3, TIM_IT_Update) == SET) + { + LED1_Turn(); + TIM_ClearITPendingBit(TIM3, TIM_IT_Update); + } +} + +//PWM呼吸灯 +void TIM4_IRQHandler(void) +{ + if (TIM_GetITStatus(TIM4, TIM_IT_Update) == SET) + { + if (PWM_CCR == 0) + { + PWM_flag = 0; + } + else if (PWM_CCR == 100) + { + PWM_flag = 1; + } + + if (PWM_flag == 0) + { + PWM_CCR++; + } + else if(PWM_flag == 1) + { + PWM_CCR--; + } + + PWM_SetCompare1(PWM_CCR); + TIM_ClearITPendingBit(TIM4, TIM_IT_Update); + } +} diff --git a/Embedded/xingyi-Starry/Project/Hardware/Timer.h b/Embedded/xingyi-Starry/Project/Hardware/Timer.h new file mode 100644 index 0000000..63da7ae --- /dev/null +++ b/Embedded/xingyi-Starry/Project/Hardware/Timer.h @@ -0,0 +1,6 @@ +#ifndef __TIMER_H +#define __TIMER_H + +void Timer_Init(void); + +#endif diff --git a/Embedded/xingyi-Starry/Project/System/Delay.c b/Embedded/xingyi-Starry/Project/System/Delay.c new file mode 100644 index 0000000..12b08c5 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/System/Delay.c @@ -0,0 +1,41 @@ +#include "stm32f10x.h" + +/** + * @brief 微秒级延时 + * @param xus 延时时长,范围:0~233015 + * @retval 无 + */ +void Delay_us(uint32_t xus) +{ + SysTick->LOAD = 72 * xus; //设置定时器重装值 + SysTick->VAL = 0x00; //清空当前计数值 + SysTick->CTRL = 0x00000005; //设置时钟源为HCLK,启动定时器 + while(!(SysTick->CTRL & 0x00010000)); //等待计数到0 + SysTick->CTRL = 0x00000004; //关闭定时器 +} + +/** + * @brief 毫秒级延时 + * @param xms 延时时长,范围:0~4294967295 + * @retval 无 + */ +void Delay_ms(uint32_t xms) +{ + while(xms--) + { + Delay_us(1000); + } +} + +/** + * @brief 秒级延时 + * @param xs 延时时长,范围:0~4294967295 + * @retval 无 + */ +void Delay_s(uint32_t xs) +{ + while(xs--) + { + Delay_ms(1000); + } +} diff --git a/Embedded/xingyi-Starry/Project/System/Delay.h b/Embedded/xingyi-Starry/Project/System/Delay.h new file mode 100644 index 0000000..cef7c3c --- /dev/null +++ b/Embedded/xingyi-Starry/Project/System/Delay.h @@ -0,0 +1,8 @@ +#ifndef __DELAY_H +#define __DELAY_H + +void Delay_us(uint32_t us); +void Delay_ms(uint32_t ms); +void Delay_s(uint32_t s); + +#endif diff --git a/Embedded/xingyi-Starry/Project/User/main.c b/Embedded/xingyi-Starry/Project/User/main.c new file mode 100644 index 0000000..3ee21ad --- /dev/null +++ b/Embedded/xingyi-Starry/Project/User/main.c @@ -0,0 +1,28 @@ +/*本工程使用stm32f103c8t6实现*/ +/*视频展示BV1Qu4y1h7mp*/ + +#include "stm32f10x.h" // Device header +#include "LED.h" //按键点灯和闪烁的硬件实现 +#include "OLED.h" //OLED显示屏 +#include "Key.h" //外部中断实现按键控制 +#include "PWM.h" +#include "Timer.h" //定时器中断实现LED闪烁和PWM调频 +#include "ADC.h" + + +int main(void) +{ + LED_Init(); + OLED_Init(); + Key_Init(); + PWM_Init(); + Timer_Init(); + AD_Init(); + + OLED_ShowString(1, 1, "ADC:"); + + while (1) + { + OLED_ShowNum(1, 5, AD_GetValue(), 4); + } +} diff --git a/Embedded/xingyi-Starry/Project/User/stm32f10x_conf.h b/Embedded/xingyi-Starry/Project/User/stm32f10x_conf.h new file mode 100644 index 0000000..cbb8819 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/User/stm32f10x_conf.h @@ -0,0 +1,77 @@ +/** + ****************************************************************************** + * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_conf.h + * @author MCD Application Team + * @version V3.5.0 + * @date 08-April-2011 + * @brief Library configuration file. + ****************************************************************************** + * @attention + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + *

© COPYRIGHT 2011 STMicroelectronics

+ ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F10x_CONF_H +#define __STM32F10x_CONF_H + +/* Includes ------------------------------------------------------------------*/ +/* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */ +#include "stm32f10x_adc.h" +#include "stm32f10x_bkp.h" +#include "stm32f10x_can.h" +#include "stm32f10x_cec.h" +#include "stm32f10x_crc.h" +#include "stm32f10x_dac.h" +#include "stm32f10x_dbgmcu.h" +#include "stm32f10x_dma.h" +#include "stm32f10x_exti.h" +#include "stm32f10x_flash.h" +#include "stm32f10x_fsmc.h" +#include "stm32f10x_gpio.h" +#include "stm32f10x_i2c.h" +#include "stm32f10x_iwdg.h" +#include "stm32f10x_pwr.h" +#include "stm32f10x_rcc.h" +#include "stm32f10x_rtc.h" +#include "stm32f10x_sdio.h" +#include "stm32f10x_spi.h" +#include "stm32f10x_tim.h" +#include "stm32f10x_usart.h" +#include "stm32f10x_wwdg.h" +#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Uncomment the line below to expanse the "assert_param" macro in the + Standard Peripheral Library drivers code */ +/* #define USE_FULL_ASSERT 1 */ + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT + +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function which reports + * the name of the source file and the source line number of the call + * that failed. If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0) +#endif /* USE_FULL_ASSERT */ + +#endif /* __STM32F10x_CONF_H */ + +/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/Embedded/xingyi-Starry/Project/User/stm32f10x_it.c b/Embedded/xingyi-Starry/Project/User/stm32f10x_it.c new file mode 100644 index 0000000..18acee1 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/User/stm32f10x_it.c @@ -0,0 +1,160 @@ +/** + ****************************************************************************** + * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.c + * @author MCD Application Team + * @version V3.5.0 + * @date 08-April-2011 + * @brief Main Interrupt Service Routines. + * This file provides template for all exceptions handler and + * peripherals interrupt service routine. + ****************************************************************************** + * @attention + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + *

© COPYRIGHT 2011 STMicroelectronics

+ ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f10x_it.h" + +/** @addtogroup STM32F10x_StdPeriph_Template + * @{ + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/******************************************************************************/ +/* Cortex-M3 Processor Exceptions Handlers */ +/******************************************************************************/ + +/** + * @brief This function handles NMI exception. + * @param None + * @retval None + */ +void NMI_Handler(void) +{ +} + +/** + * @brief This function handles Hard Fault exception. + * @param None + * @retval None + */ +void HardFault_Handler(void) +{ + /* Go to infinite loop when Hard Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles Memory Manage exception. + * @param None + * @retval None + */ +void MemManage_Handler(void) +{ + /* Go to infinite loop when Memory Manage exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles Bus Fault exception. + * @param None + * @retval None + */ +void BusFault_Handler(void) +{ + /* Go to infinite loop when Bus Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles Usage Fault exception. + * @param None + * @retval None + */ +void UsageFault_Handler(void) +{ + /* Go to infinite loop when Usage Fault exception occurs */ + while (1) + { + } +} + +/** + * @brief This function handles SVCall exception. + * @param None + * @retval None + */ +void SVC_Handler(void) +{ +} + +/** + * @brief This function handles Debug Monitor exception. + * @param None + * @retval None + */ +void DebugMon_Handler(void) +{ +} + +/** + * @brief This function handles PendSVC exception. + * @param None + * @retval None + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief This function handles SysTick Handler. + * @param None + * @retval None + */ +void SysTick_Handler(void) +{ +} + +/******************************************************************************/ +/* STM32F10x Peripherals Interrupt Handlers */ +/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ +/* available peripheral interrupt handler's name please refer to the startup */ +/* file (startup_stm32f10x_xx.s). */ +/******************************************************************************/ + +/** + * @brief This function handles PPP interrupt request. + * @param None + * @retval None + */ +/*void PPP_IRQHandler(void) +{ +}*/ + +/** + * @} + */ + + +/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ diff --git a/Embedded/xingyi-Starry/Project/User/stm32f10x_it.h b/Embedded/xingyi-Starry/Project/User/stm32f10x_it.h new file mode 100644 index 0000000..8890262 --- /dev/null +++ b/Embedded/xingyi-Starry/Project/User/stm32f10x_it.h @@ -0,0 +1,54 @@ +/** + ****************************************************************************** + * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.h + * @author MCD Application Team + * @version V3.5.0 + * @date 08-April-2011 + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * @attention + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + *

© COPYRIGHT 2011 STMicroelectronics

+ ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F10x_IT_H +#define __STM32F10x_IT_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f10x.h" + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ + +void NMI_Handler(void); +void HardFault_Handler(void); +void MemManage_Handler(void); +void BusFault_Handler(void); +void UsageFault_Handler(void); +void SVC_Handler(void); +void DebugMon_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F10x_IT_H */ + +/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/