Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

交作业(嵌入式) #54

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions Embedded/xingyi-Starry/Project/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions Embedded/xingyi-Starry/Project/.vscode/keil-assistant.log
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions Embedded/xingyi-Starry/Project/.vscode/uv4.log
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Embedded/xingyi-Starry/Project/.vscode/uv4.log.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023/11/2 18:54:15
48 changes: 48 additions & 0 deletions Embedded/xingyi-Starry/Project/Hardware/ADC.c
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 6 additions & 0 deletions Embedded/xingyi-Starry/Project/Hardware/ADC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __AD_H
#define __AD_H
void AD_Init(void);
uint16_t AD_GetValue(void);

#endif
46 changes: 46 additions & 0 deletions Embedded/xingyi-Starry/Project/Hardware/Key.c
Original file line number Diff line number Diff line change
@@ -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);

}

}
6 changes: 6 additions & 0 deletions Embedded/xingyi-Starry/Project/Hardware/Key.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __KEY_H
#define __KEY_H

void Key_Init(void);

#endif
38 changes: 38 additions & 0 deletions Embedded/xingyi-Starry/Project/Hardware/LED.c
Original file line number Diff line number Diff line change
@@ -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);
}
}
8 changes: 8 additions & 0 deletions Embedded/xingyi-Starry/Project/Hardware/LED.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __LED_H
#define __LED_H

void LED_Init(void);
void LED1_Turn(void);
void LED2_Turn(void);

#endif
Loading