亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码
標(biāo)題:
STM32F103 VCP代碼
[打印本頁]
作者:
普通人0o
時間:
2019-6-5 23:59
標(biāo)題:
STM32F103 VCP代碼
STM32F103 實(shí)現(xiàn)虛擬串口,進(jìn)行串口通信,實(shí)現(xiàn)了USB通信
單片機(jī)源程序如下:
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include <stdio.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/*LED燈相關(guān)定義*/
#define RCC_GPIO_LED RCC_APB2Periph_GPIOD /*LED使用的GPIO時鐘*/
#define LEDn 4 /*神舟III號LED數(shù)量*/
#define GPIO_LED GPIOD /*神舟III號LED燈使用的GPIO組*/
#define DS1_PIN GPIO_Pin_8 /*DS1使用的GPIO管腳*/
#define DS2_PIN GPIO_Pin_9 /*DS2使用的GPIO管腳*/
#define DS3_PIN GPIO_Pin_10 /*DS3使用的GPIO管腳*/
#define DS4_PIN GPIO_Pin_11 /*DS4使用的GPIO管腳*/
//按鍵的定義
#define RCC_GPIO_KEY1 RCC_APB2Periph_GPIOD /*按鍵1使用的GPIO時鐘*/
#define GPIO_KEY1 GPIOD /*按鍵使用的GPIO組*/
#define KEY1_PIN GPIO_Pin_0 /*按鍵1使用的GPIO管腳*/
#define RCC_GPIO_KEY2 RCC_APB2Periph_GPIOD /*按鍵2使用的GPIO時鐘*/
#define GPIO_KEY2 GPIOD /*按鍵2使用的GPIO組*/
#define KEY2_PIN GPIO_Pin_1 /*按鍵2使用的GPIO管腳*/
#define RCC_GPIO_KEY3 RCC_APB2Periph_GPIOD /*按鍵3使用的GPIO時鐘*/
#define GPIO_KEY3 GPIOD /*按鍵3使用的GPIO組*/
#define KEY3_PIN GPIO_Pin_2 /*按鍵3使用的GPIO管腳*/
#define RCC_GPIO_KEY4 RCC_APB2Periph_GPIOD /*按鍵4使用的GPIO時鐘*/
#define GPIO_KEY4 GPIOD /*按鍵4使用的GPIO組*/
#define KEY4_PIN GPIO_Pin_3 /*按鍵4使用的GPIO管腳*/
//串口1 TX PA9 RX-PA10
#define RCC_GPIO_UART1 RCC_APB2Periph_GPIOA /*按鍵4使用的GPIO時鐘*/
#define GPIO_UART1 GPIOA /*按鍵4使用的GPIO組*/
#define TX1_PIN GPIO_Pin_9 /*按鍵4使用的GPIO管腳*/
#define RX1_PIN GPIO_Pin_10 /*按鍵4使用的GPIO管腳*/
//串口2 TX -PA2 RX-PA3
#define RCC_GPIO_USART2 RCC_APB2Periph_GPIOA /*USART2的GPIO時鐘*/
#define GPIO_USART2 GPIOA /*USART2使用的GPIO組*/
#define TX3_PIN GPIO_Pin_2 /*USART2使用的GPIO管腳*/
#define RX3_PIN GPIO_Pin_3 /*USART2使用的GPIO管腳*/
/* Private macro -------------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
//宏定義 為適合不同的編譯系統(tǒng)
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
ErrorStatus HSEStartUpStatus;
u8 count=0;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
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)
{
u8 i=1;
/* 配置神舟III號LED燈使用的GPIO管腳模式*/
// RCC_DeInit();
// RCC_HSEConfig(RCC_HSE_ON);
// RCC_HSICmd(ENABLE);
// while(RCC_WaitForHSEStartUp()!=SUCCESS);
// RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_16 );
// RCC_PLLCmd(ENABLE);
//
// RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK );
//LED設(shè)置
RCC_APB2PeriphClockCmd(RCC_GPIO_LED, ENABLE); /*使能LED燈使用的GPIO時鐘*/
GPIO_InitStructure.GPIO_Pin = DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_Out_PP ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_LED, &GPIO_InitStructure); /*神州III號使用的LED燈相關(guān)的GPIO口初始化*/
GPIO_ResetBits(GPIO_LED,DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN);/*關(guān)閉所有的LED指示燈*/
//按鍵1設(shè)置
RCC_APB2PeriphClockCmd(RCC_GPIO_KEY1, ENABLE); /*使能LED燈使用的GPIO時鐘*/
GPIO_InitStructure.GPIO_Pin = KEY1_PIN;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPU ;
GPIO_Init(GPIO_KEY1, &GPIO_InitStructure); /*神州III號使用的按鍵1相關(guān)的GPIO口初始化*/
//按鍵2設(shè)置
RCC_APB2PeriphClockCmd(RCC_GPIO_KEY2, ENABLE); /*使能按鍵2使用的GPIO時鐘*/
GPIO_InitStructure.GPIO_Pin = KEY2_PIN;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPU ;
GPIO_Init(GPIO_KEY2, &GPIO_InitStructure); /*神州III號使用的按鍵1相關(guān)的GPIO口初始化*/
//按鍵3設(shè)置
RCC_APB2PeriphClockCmd(RCC_GPIO_KEY3, ENABLE); /*使能按鍵3使用的GPIO時鐘*/
GPIO_InitStructure.GPIO_Pin = KEY3_PIN;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPU ;
GPIO_Init(GPIO_KEY3, &GPIO_InitStructure); /*神州III號使用的按鍵1相關(guān)的GPIO口初始化*/
//按鍵4設(shè)置
RCC_APB2PeriphClockCmd(RCC_GPIO_KEY4, ENABLE); /*使能按鍵4使用的GPIO時鐘*/
GPIO_InitStructure.GPIO_Pin = KEY4_PIN;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPU ;
GPIO_Init(GPIO_KEY4, &GPIO_InitStructure); /*神州III號使用的按鍵1相關(guān)的GPIO口初始化*/
//********************************************************************
//串口1端口
/* Enable GPIO clock */
RCC_APB2PeriphClockCmd( RCC_GPIO_UART1|RCC_APB2Periph_AFIO, ENABLE);
/* Enable UART clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = TX1_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_UART1, &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = RX1_PIN;
GPIO_Init(GPIO_UART1, &GPIO_InitStructure);
/*串口1參數(shù)配置*/
USART_InitStructure.USART_BaudRate = 115200; /*設(shè)置波特率為115200*/
USART_InitStructure.USART_WordLength = USART_WordLength_8b; /*設(shè)置數(shù)據(jù)位為8位*/
USART_InitStructure.USART_StopBits = USART_StopBits_1; /*設(shè)置停止位為1位*/
USART_InitStructure.USART_Parity = USART_Parity_No; /*無奇偶校驗(yàn)*/
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; /*沒有硬件流控*/
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /*發(fā)送與接收*/
/*完成串口COM1的時鐘配置、GPIO配置,根據(jù)上述參數(shù)初始化并使能*/
/* USART configuration */
USART_Init(USART1, &USART_InitStructure);
/* Enable USART */
USART_Cmd(USART1, ENABLE);
//********************************************************************
//串口2端口
/* Enable GPIO clock */
RCC_APB2PeriphClockCmd( RCC_GPIO_USART2|RCC_APB2Periph_AFIO, ENABLE);
/* Enable UART clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = TX3_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_USART2, &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = RX3_PIN;
GPIO_Init(GPIO_USART2, &GPIO_InitStructure);
/*串口2參數(shù)配置*/
USART_InitStructure.USART_BaudRate = 115200; /*設(shè)置波特率為115200*/
USART_InitStructure.USART_WordLength = USART_WordLength_8b; /*設(shè)置數(shù)據(jù)位為8位*/
USART_InitStructure.USART_StopBits = USART_StopBits_1; /*設(shè)置停止位為1位*/
USART_InitStructure.USART_Parity = USART_Parity_No; /*無奇偶校驗(yàn)*/
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; /*沒有硬件流控*/
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /*發(fā)送與接收*/
/*完成串口COM1的時鐘配置、GPIO配置,根據(jù)上述參數(shù)初始化并使能*/
/* USART configuration */
USART_Init(USART2, &USART_InitStructure);
/* Enable USART */
USART_Cmd(USART2, ENABLE);
while(1)
{
printf("\nSTM32F103實(shí)驗(yàn)中。。。。。。\n");
printf("數(shù)字是%d",i);
i++;
Delay(0x1ffFFFF);
}
}
/*點(diǎn)亮對應(yīng)燈*/
void Turn_On_LED(u8 LED_NUM)
{
switch(LED_NUM)
{
case 0:
GPIO_ResetBits(GPIO_LED,DS1_PIN); /*點(diǎn)亮DS1燈*/
break;
case 1:
GPIO_ResetBits(GPIO_LED,DS2_PIN); /*點(diǎn)亮DS2燈*/
break;
case 2:
GPIO_ResetBits(GPIO_LED,DS3_PIN); /*點(diǎn)亮DS3燈*/
break;
case 3:
GPIO_ResetBits(GPIO_LED,DS4_PIN); /*點(diǎn)亮DS4燈*/
break;
default:
GPIO_ResetBits(GPIO_LED,DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN); /*點(diǎn)亮所有的燈*/
break;
}
}
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART2, (uint8_t) ch); /*發(fā)送一個字符函數(shù)*/
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET)/*等待發(fā)送完成*/
{
}
return ch;
}
/*******************************************************************************
* Function Name : 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--);
}
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
復(fù)制代碼
所有資料51hei提供下載:
STM32F103 實(shí)現(xiàn)虛擬串口,進(jìn)行串口通信,實(shí)現(xiàn)了USB通信.7z
(540.68 KB, 下載次數(shù): 22)
2019-6-7 02:15 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
JACKRENYONG
時間:
2022-7-22 11:52
編譯都沒通過,還封裝了一個靜態(tài)LIB.
歡迎光臨 (http://www.denmoz.com/bbs/)
Powered by Discuz! X3.1