STM32实验程序代码.docx
- 文档编号:24963108
- 上传时间:2023-06-03
- 格式:DOCX
- 页数:9
- 大小:15.35KB
STM32实验程序代码.docx
《STM32实验程序代码.docx》由会员分享,可在线阅读,更多相关《STM32实验程序代码.docx(9页珍藏版)》请在冰豆网上搜索。
STM32实验程序代码
实验1GPIO
#include""
#include""
*Input:
None
*Output:
None
*Return:
None
*******************************************************************************/
intmain(void)
{
/*Configurethesystemclocks*/
*Input:
None
*Output:
None
*Return:
None
*******************************************************************************/
voidNVIC_Configuration(void)
{
NVIC_InitTypeDefNVIC_InitStructure;
/*Configureonebitforpreemptionpriority*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/*EnabletheEXTI9_5Interrupt*/
*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_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
=GPIO_Speed_50MHz;
=GPIO_Mode_Out_PP;
GPIO_Init(GPIOF,&GPIO_InitStructure);
/*ConfigurePA9asinputfloating(EXTILine9)*/
=GPIO_Pin_9;
*Input:
None
*Output:
None
*Return:
None
*******************************************************************************/
intmain(void)
{
/*配置LED灯使用的GPIO管脚模式*/
RCC_APB2PeriphClockCmd(RCC_GPIO_LED,ENABLE);/*使能LED灯使用的GPIO时钟*/
=LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN|LD5_PIN|LD6_PIN|LD7_PIN|LD8_PIN;
=GPIO_Mode_Out_PP;
=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);*Input:
nCount:
specifiesthedelaytimelength.
*Output:
None
*Return:
None
*******************************************************************************/
voidDelay(vu32nCount)
{
for(;nCount!
=0;nCount--);
}
实验11串口收发
#include""
#include""
*@paramNone
*@retvalNone
*/
voidRCC_Configuration(void)
{
/*使能串口1和串口2使用的GPIO时钟*/
RCC_APB2PeriphClockCmd(USART1_GPIO_CLK|USART2_GPIO_CLK,ENABLE);
/*EnableUSART1Clock*/
/*使能串口1时钟*/
RCC_APB2PeriphClockCmd(USART1_CLK,ENABLE);
/*使能串口2时钟*/
RCC_APB1PeriphClockCmd(USART2_CLK,ENABLE);
/*使能LED灯使用的GPIO时钟*/
RCC_APB2PeriphClockCmd(RCC_GPIO_LED,ENABLE);
}
/**
*@briefConfiguresthedifferentGPIOports.
*@paramNone
*@retvalNone
*/
voidGPIO_Configuration(void)
{
GPIO_InitTypeDefGPIO_InitStructure;
/*串口1RX管脚配置*/
/*ConfigureUSART1Rxasinputfloating*/
=USART1_RxPin;
=GPIO_Mode_IN_FLOATING;
GPIO_Init(USART1_GPIO,&GPIO_InitStructure);
/*串口2RX管脚配置*/
/*ConfigureUSART2Rxasinputfloating*/
=USART2_RxPin;
GPIO_Init(USART2_GPIO,&GPIO_InitStructure);
/*串口1TX管脚配置*/
/*ConfigureUSART1Txasalternatefunctionpush-pull*/
=USART1_TxPin;
=GPIO_Speed_50MHz;
=GPIO_Mode_AF_PP;
GPIO_Init(USART1_GPIO,&GPIO_InitStructure);
/*串口2TX管脚配置*/
/*ConfigureUSART2Txasalternatefunctionpush-pull*/
=USART2_TxPin;
GPIO_Init(USART2_GPIO,&GPIO_InitStructure);
/*配置LED灯使用的GPIO管脚模式*/
=LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN;
=GPIO_Mode_Out_PP;
=GPIO_Speed_50MHz;
GPIO_Init(GPIO_LED,&GPIO_InitStructure);
}
/**
*@briefConfiguresthenestedvectoredinterruptcontroller.
*@paramNone
*@retvalNone
*/
voidNVIC_Configuration(void)
{
NVIC_InitTypeDefNVIC_InitStructure;
/*ConfiguretheNVICPreemptionPriorityBits*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/*EnabletheUSART1Interrupt*/
=USART1_IRQn;
=0;
=ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*EnabletheUSART2Interrupt*/
=USART2_IRQn;
=1;
=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**
*@briefComparestwobuffers.
*@parampBuffer1,pBuffer2:
bufferstobecompared.
*@paramBufferLength:
buffer'slength
*@retvalPASSED:
pBuffer1identicaltopBuffer2
*FAILED:
pBuffer1differsfrompBuffer2
*/
TestStatusBuffercmp(u8*pBuffer1,u8*pBuffer2,u16BufferLength)
{
while(BufferLength--)
{
if(*pBuffer1!
=*pBuffer2)
{
returnFAILED;
}
pBuffer1++;
pBuffer2++;
}
returnPASSED;
}
/**
*@briefThisfunctionhandlesUSART1globalinterruptrequest.
*@paramNone
*@retvalNone
*/
voidUSART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1,USART_IT_RXNE)!
=RESET)
{
/*Readonebytefromthereceivedataregister*/
RxBuffer1[RxCounter1++]=USART_ReceiveData(USART1);
if(RxCounter1==NbrOfDataToRead1)
{
/*DisabletheUSART1Receiveinterrupt*/
USART_ITConfig(USART1,USART_IT_RXNE,DISABLE);
}
}
if(USART_GetITStatus(USART1,USART_IT_TXE)!
=RESET)
{
/*Writeonebytetothetransmitdataregister*/
USART_SendData(USART1,TxBuffer1[TxCounter1++]);
if(TxCounter1==NbrOfDataToTransfer1)
{
/*DisabletheUSART1Transmitinterrupt*/
USART_ITConfig(USART1,USART_IT_TXE,DISABLE);
}
}
}
/**
*@briefThisfunctionhandlesUSART2globalinterruptrequest.
*@paramNone
*@retvalNone
*/
voidUSART2_IRQHandler(void)
{
if(USART_GetITStatus(USART2,USART_IT_RXNE)!
=RESET)
{
/*Readonebytefromthereceivedataregister*/
RxBuffer2[RxCounter2++]=USART_ReceiveData(USART2);
if(RxCounter2==NbrOfDataToRead1)
{
/*DisabletheUSART2Receiveinterrupt*/
USART_ITConfig(USART2,USART_IT_RXNE,DISABLE);
}
}
if(USART_GetITStatus(USART2,USART_IT_TXE)!
=RESET)
{
/*Writeonebytetothetransmitdataregister*/
USART_SendData(USART2,TxBuffer2[TxCounter2++]);
if(TxCounter2==NbrOfDataToTransfer2)
{
/*DisabletheUSART2Transmitinterrupt*/
USART_ITConfig(USART2,USART_IT_TXE,DISABLE);
}
}
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- STM32 实验程序代码 实验 程序代码
![提示](https://static.bdocx.com/images/bang_tan.gif)