STM实验程序代码.docx
《STM实验程序代码.docx》由会员分享,可在线阅读,更多相关《STM实验程序代码.docx(19页珍藏版)》请在冰豆网上搜索。
STM实验程序代码
实验1
#include"stm32f10x.h"
#include"delay.h"
//#include"sys.h"
#include"stm32f10x_exti.h"
//QHKJTEB-CM5000实验箱STM32实验1
//固件库V3.5工程模板
//QHKJ
GPIO_InitTypeDefGPIO_InitStructure;
EXTI_InitTypeDefEXTI_InitStructure;
/*Privatefunctionprototypes*/
voidRCC_Configuration(void);
voidNVIC_Configuration(void);
voidGPIO_Configuration(void);
/*Privatefunctions*/
*
****************************************************************************
*FunctionName:
main*Description:
Mainprogram.
*Input
:
None
*Output
:
None
*Return
:
None
*******************************************************************************
/
intmain(void)
{
/*Configurethesystemclocks*/
//RCC_Configuration();
//SysTick_Configuration();
delay_init();
/*NVICConfiguration*/
NVIC_Configuration();
/*ConfiguretheGPIOports*/
GPIO_Configuration();
/*ConnectEXTILine9toPA.9*/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource9);
/*ConfigureEXTILine8togenerateaninterruptonfallingedge*/
EXTI_InitStructure.EXTI_Line=EXTI_Line9;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStructure);
for(;;)
{
GPIO_Write(GPIOF,0xf80f);
delay_ms(100);
GPIO_Write(GPIOF,0xf817);
delay_ms(100);
GPIO_Write(GPIOF,0xf827);
delay_ms(100);
GPIO_Write(GPIOF,0xf847);
delay_ms(100);
GPIO_Write(GPIOF,0xf887);
delay_ms(100);
GPIO_Write(GPIOF,0x8907);
delay_ms(100);
GPIO_Write(GPIOF,0xfa07);
delay_ms(100);
GPIO_Write(GPIOF,0xfc07);
delay_ms(100);
}
*FunctionName:
NVIC_Configuration
*Description:
ConfiguresVectorTablebaselocation.
*Input:
None
*Output:
None
*Return:
None
*******************************************************************************
/
voidNVIC_Configuration(void)
{
NVIC_InitTypeDefNVIC_InitStructure;
/*Configureonebitforpreemptionpriority*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/*EnabletheEXTI9_5Interrupt*/
//NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
*FunctionName:
GPIO_Configuration
*Description:
ConfiguresthedifferentGPIOports.
*Input:
None
*Output:
None
*Return:
None
*******************************************************************************
/
voidGPIO_Configuration(void)
{
GPIO_InitTypeDefGPIO_InitStructure;
/*EnableGPIOA,GPIOFandAFIOclocks*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOF|
RCC_APB2Periph_AFIO,ENABLE);
/*ConfigurePF.asOutputpush-pull*/
GPIO_InitStructure.GPIO_Pin
GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOF,&GPIO_InitStructure);
/*ConfigurePA9asinputfloating(EXTILine9)*/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
//GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
实验7LED流水灯
GPIO管脚*/
管脚*/
#defineLD6_PIN
GPIO_Pin_8
/*LD6
使
用
的
GPIO管脚*/
#defineLD7_PIN
GPIO_Pin_9
/*LD7
使
用
的
GPIO管脚*/
#defineLD8_PIN
GPIO_Pin_10
/*LD8
使
用
的
GPIO管脚*/
/*Privatevariables*/
GPIO_InitTypeDefGPIO_InitStructure;
u8count=0;
/*Privatefunctionprototypes*/
//voidRCC_Configuration(void);
//voidNVIC_Configuration(void);
voidDelay(vu32nCount);
voidTurn_On_LED(u8LED_NUM);
/*Privatefunctions*/
*
****************************************************************************
*FunctionName:
main
*Description:
Mainprogram.
*Input
:
None
*Output
:
None
*Return
:
None
*******************************************************************************
/
intmain(void)
{
/*配置LED灯使用的GPIO管脚模式*/
RCC_APB2PeriphClockCmd(RCC_GPIO_LED,ENABLE);/*使能LED灯使用的GPI0时钟*/
GPIO_InitStructure.GPIO_Pin
LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN|LD5_PIN|LD6_PIN|LD7_PIN|LD8_PIN;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIO_LED,&GPIO_InitStructure);/*使用的LED灯相关的GPIO口初始化
*/
GPIO_ResetBits(GPIO_LED,LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN|LD5_PIN|LD6_PIN|LD7_PIN|LD8_PIN);/*关闭所有的LED指示灯*/
while
(1)
{
GPIO_ResetBits(GPIO_LED,LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN|LD5_PIN|LD6_PIN|LD7
PIN|LD8_PIN);/*关闭所有的LED指示灯*/
Turn_On_LED(count%8);〃点亮一个LED灯
count++;
Delay(0x0FFFFF);
}
}
/*点亮对应灯*/
voidTurn_On_LED(u8LED_NUM)
{
switch(LED_NUM)
{
点亮LD1灯*/
case0:
GPIO_SetBits(GPIO_LED,LD1_PIN);/*
break;
case1:
GPIO_SetB