1、STM实验程序代码实验1 GPIO#include stm32f10x.h#include delay.h/#include sys.h#include stm32f10x_exti.h/QHKJ TEB-CM5000实验箱STM32实验1/固件库V3.5工程模板 /QHKJGPIO_InitTypeDef GPIO_InitStructure;EXTI_InitTypeDef EXTI_InitStructure;/* Private function prototypes -*/void RCC_Configuration(void);void NVIC_Configuration(voi
2、d);void GPIO_Configuration(void); /* Private functions -*/* Function Name : main* Description : Main program.* Input : None* Output : None* Return : None*/int main(void) /* Configure the system clocks */ RCC_Configuration();/ SysTick_Configuration(); delay_init(); /* NVIC Configuration */ NVIC_Confi
3、guration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* Connect EXTI Line9 to PA.9 */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource9); /* Configure EXTI Line8 to generate an interrupt on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line9; EXTI_InitStructure.EXTI_Mode =
4、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
5、, 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); /* Function Name : NVIC_Configuration* Description : Configures Vector Table base location.* Input : None*
6、 Output : None* Return : None*/void NVIC_Configuration(void) NVIC_InitTypeDef NVIC_InitStructure; /* Configure one bit for preemption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Enable the EXTI9_5 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; NVIC_InitStruc
7、ture.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);/* Function Name : GPIO_Configuration* Description : Configures the differe
8、nt GPIO ports.* Input : None* Output : None* Return : None*/void GPIO_Configuration(void) GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIOA, GPIOF and AFIO clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOF | RCC_APB2Periph_AFIO, ENABLE); /* Configure PF. as Output push-
9、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); /* Configure PA9 as input floating
10、 (EXTI Line9) */ 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);实验7 LED流水灯#include stm32f10x.h/QHKJ TEB-CM5000实验箱STM32实验7/固件库V3.5工程模板 /QHKJ /*LED灯相关定义*/#define RCC_GP
11、IO_LED RCC_APB2Periph_GPIOF /*LED使用的GPIO时钟*/#define LEDn 8 /*LED数量*/#define GPIO_LED GPIOF /*LED灯使用的GPIO组*/#define LD1_PIN GPIO_Pin_3 /*LD1使用的GPIO管脚*/#define LD2_PIN GPIO_Pin_4 /*LD2使用的GPIO管脚*/#define LD3_PIN GPIO_Pin_5 /*LD3使用的GPIO管脚*/#define LD4_PIN GPIO_Pin_6 /*LD4使用的GPIO管脚*/#define LD5_PIN GPIO_
12、Pin_7 /*LD5使用的GPIO管脚*/#define LD6_PIN GPIO_Pin_8 /*LD6使用的GPIO管脚*/#define LD7_PIN GPIO_Pin_9 /*LD7使用的GPIO管脚*/#define LD8_PIN GPIO_Pin_10 /*LD8使用的GPIO管脚*/* Private macro -*/* Private variables -*/GPIO_InitTypeDef GPIO_InitStructure;u8 count=0;/* Private function prototypes -*/void RCC_Configuration(vo
13、id);/void NVIC_Configuration(void);void Delay(vu32 nCount);void Turn_On_LED(u8 LED_NUM);/* Private functions -*/* Function Name : main* Description : Main program.* Input : None* Output : None* Return : None*/int main(void) /* 配置LED灯使用的GPIO管脚模式*/ RCC_APB2PeriphClockCmd(RCC_GPIO_LED, ENABLE); /*使能LED
14、灯使用的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_
15、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); /*点亮对应灯*/void Turn_On_LED(u8 LED_NUM) switch(LED_NUM
16、) case 0: GPIO_SetBits(GPIO_LED,LD1_PIN); /*点亮LD1灯*/ break; case 1: GPIO_SetBits(GPIO_LED,LD2_PIN); /*点亮LD2灯*/ break; case 2: GPIO_SetBits(GPIO_LED,LD3_PIN); /*点亮LD3灯*/ break; case 3: GPIO_SetBits(GPIO_LED,LD4_PIN); /*点亮LD4灯*/ break; case 4: GPIO_SetBits(GPIO_LED,LD5_PIN); /*点亮LD5灯*/ break; case 5:
17、GPIO_SetBits(GPIO_LED,LD6_PIN); /*点亮LD6灯*/ break; case 6: GPIO_SetBits(GPIO_LED,LD7_PIN); /*点亮LD7灯*/ break; case 7: 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; /* Function Name :
18、Delay* Description : Inserts a delay time.* Input : nCount: specifies the delay time length.* Output : None* Return : None*/void Delay(vu32 nCount) for(; nCount != 0; nCount-); 实验11 串口收发#include stm32f10x.h#include stm32f10x_usart.h/QHKJ TEB-CM5000实验箱STM32实验11/固件库V3.5工程模板 /QHKJ/* Private typedef -*/
19、*LED灯相关定义*/#define RCC_GPIO_LED RCC_APB2Periph_GPIOF /*LED使用的GPIO时钟*/#define LEDn 4 /*LED数量*/#define GPIO_LED GPIOF /*LED灯使用的GPIO组*/#define LD1_PIN GPIO_Pin_3 /*LD1使用的GPIO管脚*/#define LD2_PIN GPIO_Pin_4 /*LD2使用的GPIO管脚*/#define LD3_PIN GPIO_Pin_5 /*LD3使用的GPIO管脚*/#define LD4_PIN GPIO_Pin_6 /*LD4使用的GPIO
20、管脚*/*串口相关定义*/#define USART1_GPIO GPIOA#define USART1_CLK RCC_APB2Periph_USART1#define USART1_GPIO_CLK RCC_APB2Periph_GPIOA#define USART1_RxPin GPIO_Pin_10#define USART1_TxPin GPIO_Pin_9/#define USART1_IRQn USART1_IRQn/#define USART1_IRQHandler USART1_IRQHandler #define USART2_GPIO GPIOA#define USART
21、2_CLK RCC_APB1Periph_USART2#define USART2_GPIO_CLK RCC_APB2Periph_GPIOA#define USART2_RxPin GPIO_Pin_3#define USART2_TxPin GPIO_Pin_2/#define USART2_IRQn USART2_IRQn/#define USART2_IRQHandler USART2_IRQHandlerGPIO_InitTypeDef GPIO_InitStructure;/* Private typedef -*/typedef enum FAILED = 0, PASSED =
22、 !FAILED TestStatus;/* Private define -*/#define TxBufferSize1 (countof(TxBuffer1) - 1)#define TxBufferSize2 (countof(TxBuffer2) - 1)#define RxBufferSize1 TxBufferSize2#define RxBufferSize2 TxBufferSize1/* Private macro -*/#define countof(a) (sizeof(a) / sizeof(*(a)/* Private variables -*/USART_Init
23、TypeDef USART_InitStructure;u8 TxBuffer1 = 串口中断收发示例: 串口1 - 串口2 (中断收发);u8 TxBuffer2 = 串口中断收发示例: 串口2 - 串口1 (中断收发);u8 RxBuffer1RxBufferSize1;u8 RxBuffer2RxBufferSize2;u8 TxCounter1 = 0x00;u8 TxCounter2 = 0x00;u8 RxCounter1 = 0x00; u8 RxCounter2 = 0x00;u8 NbrOfDataToTransfer1 = TxBufferSize1;u8 NbrOfDat
24、aToTransfer2 = TxBufferSize2;u8 NbrOfDataToRead1 = RxBufferSize1;u8 NbrOfDataToRead2 = RxBufferSize2;u8 TransferStatus1 = FAILED; u8 TransferStatus2 = FAILED;/* Private function prototypes -*/void RCC_Configuration(void);void GPIO_Configuration(void);void NVIC_Configuration(void);TestStatus Buffercm
25、p(u8* pBuffer1, u8* pBuffer2, u16 BufferLength);/* Private functions -*/* * brief Main program * param None * retval None */int main(void) /* System Clocks Configuration */ RCC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); GPIO_ResetBits(GPIO_LED,LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN);/*关闭所有的LED指示灯*/* USART1 and USART2 configuration -*/ /* USART1 and USART2 configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - One St
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2