找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 6229|回復(fù): 1
收起左側(cè)

STM32C8T6源碼的工程模板下載(標準程序)

[復(fù)制鏈接]
ID:262787 發(fā)表于 2018-10-23 16:15 | 顯示全部樓層 |閱讀模式
根據(jù)自己的使用習(xí)慣建立的模板
則個demo是c8t6的標準程序,可以在這個程序的基礎(chǔ)上進行各種拓展

0.png

stm32C8T6單片機源程序如下:
  1. /*************************************************
  2. * 文件名  :usart1.c                 
  3. * 描述    :配置USART1         
  4. * 實驗平臺:STM32F103C8T6
  5. * 硬件連接:------------------------
  6. *          | PA9  - USART1(Tx)      |
  7. *          | PA10 - USART1(Rx)      |
  8. *           ------------------------
  9. * 庫版本  :ST3.0.0  
  10. *************************************************/

  11. #include "usart1.h"
  12. #include <stdarg.h>


  13. void USART1_Config(void)
  14. {
  15.         GPIO_InitTypeDef GPIO_InitStructure;
  16.         USART_InitTypeDef USART_InitStructure;

  17.         /* 使能 USART1 時鐘*/
  18.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);

  19.         /* USART1 使用IO端口配置 */   
  20.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  21.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //復(fù)用推挽輸出
  22.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  23.   GPIO_Init(GPIOA, &GPIO_InitStructure);   
  24.   
  25.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  26.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;        //浮空輸入
  27.   GPIO_Init(GPIOA, &GPIO_InitStructure);   //初始化GPIOA
  28.           
  29.         /* USART1 工作模式配置 */
  30.         USART_InitStructure.USART_BaudRate = 115200;        //波特率設(shè)置:115200
  31.         USART_InitStructure.USART_WordLength = USART_WordLength_8b;        //數(shù)據(jù)位數(shù)設(shè)置:8位
  32.         USART_InitStructure.USART_StopBits = USART_StopBits_1;         //停止位設(shè)置:1位
  33.         USART_InitStructure.USART_Parity = USART_Parity_No ;  //是否奇偶校驗:無
  34.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;        //硬件流控制模式設(shè)置:沒有使能
  35.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//接收與發(fā)送都使能
  36.         USART_Init(USART1, &USART_InitStructure);  //初始化USART1
  37.         USART_Cmd(USART1, ENABLE);// USART1使能
  38. }

  39. /*發(fā)送一個字節(jié)數(shù)據(jù)*/
  40. void UART1SendByte(unsigned char SendData)
  41. {          
  42.         USART_SendData(USART1,SendData);
  43.         while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);            
  44. }  

  45. /*接收一個字節(jié)數(shù)據(jù)*/
  46. unsigned char UART1GetByte(unsigned char* GetData)
  47. {             
  48.         if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)
  49.         {  return 0;//沒有收到數(shù)據(jù)
  50.                 }
  51.         *GetData = USART_ReceiveData(USART1);
  52.         return 1;//收到數(shù)據(jù)
  53. }
  54. /*接收一個數(shù)據(jù),馬上返回接收到的這個數(shù)據(jù)*/
  55. void UART1Test(void)
  56. {
  57.        unsigned char i = 0;

  58.        while(1)
  59.        {   
  60.                  while(UART1GetByte(&i))
  61.         {
  62.          USART_SendData(USART1,i);
  63.         }      
  64.        }     
  65. }
復(fù)制代碼

所有資料51hei提供下載:
stm32c8t6_demo.rar (211.76 KB, 下載次數(shù): 292)


回復(fù)

使用道具 舉報

ID:920167 發(fā)表于 2021-5-12 17:28 | 顯示全部樓層
學(xué)習(xí)學(xué)習(xí)模板的代碼
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表