STM32实验程序代码.docx

上传人:b****6 文档编号:12559801 上传时间:2023-06-06 格式:DOCX 页数:22 大小:18.34KB
下载 相关 举报
STM32实验程序代码.docx_第1页
第1页 / 共22页
STM32实验程序代码.docx_第2页
第2页 / 共22页
STM32实验程序代码.docx_第3页
第3页 / 共22页
STM32实验程序代码.docx_第4页
第4页 / 共22页
STM32实验程序代码.docx_第5页
第5页 / 共22页
STM32实验程序代码.docx_第6页
第6页 / 共22页
STM32实验程序代码.docx_第7页
第7页 / 共22页
STM32实验程序代码.docx_第8页
第8页 / 共22页
STM32实验程序代码.docx_第9页
第9页 / 共22页
STM32实验程序代码.docx_第10页
第10页 / 共22页
STM32实验程序代码.docx_第11页
第11页 / 共22页
STM32实验程序代码.docx_第12页
第12页 / 共22页
STM32实验程序代码.docx_第13页
第13页 / 共22页
STM32实验程序代码.docx_第14页
第14页 / 共22页
STM32实验程序代码.docx_第15页
第15页 / 共22页
STM32实验程序代码.docx_第16页
第16页 / 共22页
STM32实验程序代码.docx_第17页
第17页 / 共22页
STM32实验程序代码.docx_第18页
第18页 / 共22页
STM32实验程序代码.docx_第19页
第19页 / 共22页
STM32实验程序代码.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

STM32实验程序代码.docx

《STM32实验程序代码.docx》由会员分享,可在线阅读,更多相关《STM32实验程序代码.docx(22页珍藏版)》请在冰点文库上搜索。

STM32实验程序代码.docx

STM32实验程序代码

实验1GPIO

#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流水灯

#include"stm32f10x.h"

//QHKJTEB-CM5000实验箱STM32实验7

//固件库V3.5工程模板

//QHKJ

/*LED灯相关定义*/

#defineRCC_GPIO_LEDRCC_APB2Periph_GPIOF/*LED使用的GPIO时钟*/

#defineLEDn8/*LED数量*/

#defineGPIO_LEDGPIOF/*LED灯使用的GPIO组*/

#defineLD1_PINGPIO_Pin_3/*LD1使用的GPIO管脚*/

#defineLD2_PINGPIO_Pin_4/*LD2使用的GPIO管脚*/

#defineLD3_PINGPIO_Pin_5/*LD3使用的GPIO管脚*/

#defineLD4_PINGPIO_Pin_6/*LD4使用的GPIO管脚*/

#defineLD5_PINGPIO_Pin_7/*LD5使用的GPIO管脚*/

#defineLD6_PINGPIO_Pin_8/*LD6使用的GPIO管脚*/

#defineLD7_PINGPIO_Pin_9/*LD7使用的GPIO管脚*/

#defineLD8_PINGPIO_Pin_10/*LD8使用的GPIO管脚*/

/*Privatemacro-------------------------------------------------------------*/

/*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灯使用的GPIO时钟*/

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)

{

case0:

GPIO_SetBits(GPIO_LED,LD1_PIN);/*点亮LD1灯*/

break;

case1:

GPIO_SetBits(GPIO_LED,LD2_PIN);/*点亮LD2灯*/

break;

case2:

GPIO_SetBits(GPIO_LED,LD3_PIN);/*点亮LD3灯*/

break;

case3:

GPIO_SetBits(GPIO_LED,LD4_PIN);/*点亮LD4灯*/

break;

case4:

GPIO_SetBits(GPIO_LED,LD5_PIN);/*点亮LD5灯*/

break;

case5:

GPIO_SetBits(GPIO_LED,LD6_PIN);/*点亮LD6灯*/

break;

case6:

GPIO_SetBits(GPIO_LED,LD7_PIN);/*点亮LD7灯*/

break;

case7:

GPIO_SetBits(GPIO_LED,LD8_PIN);/*点亮LD8灯*/

break;

default:

GPIO_SetBits(GPIO_LED,LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN|LD5_PIN|LD6_PIN|LD7_PIN|LD8_PIN);/*点亮所有的灯*/

break;

}

}

 

/*******************************************************************************

*FunctionName:

Delay

*Description:

Insertsadelaytime.

*Input:

nCount:

specifiesthedelaytimelength.

*Output:

None

*Return:

None

*******************************************************************************/

voidDelay(vu32nCount)

{

for(;nCount!

=0;nCount--);

}

实验11串口收发

#include"stm32f10x.h"

#include"stm32f10x_usart.h"

 

//QHKJTEB-CM5000实验箱STM32实验11

//固件库V3.5工程模板

//QHKJ

/*Privatetypedef-----------------------------------------------------------*/

/*LED灯相关定义*/

#defineRCC_GPIO_LEDRCC_APB2Periph_GPIOF/*LED使用的GPIO时钟*/

#defineLEDn4/*LED数量*/

#defineGPIO_LEDGPIOF/*LED灯使用的GPIO组*/

#defineLD1_PINGPIO_Pin_3/*LD1使用的GPIO管脚*/

#defineLD2_PINGPIO_Pin_4/*LD2使用的GPIO管脚*/

#defineLD3_PINGPIO_Pin_5/*LD3使用的GPIO管脚*/

#defineLD4_PINGPIO_Pin_6/*LD4使用的GPIO管脚*/

/*串口相关定义*/

#defineUSART1_GPIOGPIOA

#defineUSART1_CLKRCC_APB2Periph_USART1

#defineUSART1_GPIO_CLKRCC_APB2Periph_GPIOA

#defineUSART1_RxPinGPIO_Pin_10

#defineUSART1_TxPinGPIO_Pin_9

//#defineUSART1_IRQnUSART1_IRQn

//#defineUSART1_IRQHandlerUSART1_IRQHandler

#defineUSART2_GPIOGPIOA

#defineUSART2_CLKRCC_APB1Periph_USART2

#defineUSART2_GPIO_CLKRCC_APB2Periph_GPIOA

#defineUSART2_RxPinGPIO_Pin_3

#defineUSART2_TxPinGPIO_Pin_2

//#defineUSART2_IRQnUSART2_IRQn

//#defineUSART2_IRQHandlerUSART2_IRQHandler

GPIO_InitTypeDefGPIO_InitStructure;

/*Privatetypedef-----------------------------------------------------------*/

typedefenum{FAILED=0,PASSED=!

FAILED}TestStatus;

/*Privatedefine------------------------------------------------------------*/

#defineTxBufferSize1(countof(TxBuffer1)-1)

#defineTxBufferSize2(countof(TxBuffer2)-1)

#defineRxBufferSize1TxBufferSize2

#defineRxBufferSize2TxBufferSize1

/*Privatemacro-------------------------------------------------------------*/

#definecountof(a)(sizeof(a)/sizeof(*(a)))

/*Privatevariables---------------------------------------------------------*/

USART_InitTypeDefUSART_InitStructure;

u8TxBuffer1[]="串口中断收发示例:

串口1->串口2(中断收发)";

u8TxBuffer2[]="串口中断收发示例:

串口2->串口1(中断收发)";

u8RxBuffer1[RxBufferSize1];

u8RxBuffer2[RxBufferSize2];

u8TxCounter1=0x00;

u8TxCounter2=0x00;

u8RxCounter1=0x00;

u8RxCounter2=0x00;

u8NbrOfDataToTransfer1=TxBufferSize1;

u8NbrOfDataToTransfer2=TxBufferSize2;

u8NbrOfDataToRead1=RxBufferSize1;

u8NbrOfDataToRead2=RxBufferSize2;

u8TransferStatus1=FAILED;

u8TransferStatus2=FAILED;

/*Privatefunctionprototypes-----------------------------------------------*/

voidRCC_Configuration(void);

voidGPIO_Configuration(void);

voidNVIC_Configuration(void);

TestStatusBuffercmp(u8*pBuffer1,u8*pBuffer2,u16BufferLength);

/*Privatefunctions---------------------------------------------------------*/

/**

*@briefMainprogram

*@paramNone

*@retvalNone

*/

intmain(void)

{

/*SystemClocksConfiguration*/

RCC_Configuration();

/*NVICconfiguration*/

NVIC_Configuration();

/*ConfiguretheGPIOports*/

GPIO_Configuration();

GPIO_ResetBits(GPIO_LED,LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN);/*关闭所有的LED指示灯*/

/*USART1andUSART2configuration------------------------------------------------------*/

/*USART1andUSART2configuredasfollow:

-BaudRate=9600baud

-WordLength=8Bits

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2