C51 COMPILER V9.59.0.0 APP_BMM_UART 06/10/2021 10:21:41 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE APP_BMM_UART OBJECT MODULE PLACED IN .\list\APP_BMM_UART.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE ..\App\src\APP_BMM_UART.c LARGE OMF2 OPTIMIZE(8,SPEED) BROWSE INCDIR(..\ -Driver\inc;..\User;..\App\inc) DEBUG PRINT(.\list\APP_BMM_UART.lst) TABS(2) OBJECT(.\list\APP_BMM_UART.obj) line level source 1 /*---------------------------------------------------------------------*/ 2 /* --- STC MCU Limited ------------------------------------------------*/ 3 /* --- STC 1T Series MCU Demo Programme -------------------------------*/ 4 /* --- Mobile: (86)13922805190 ----------------------------------------*/ 5 /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/ 6 /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/ 7 /* --- Web: www.STCMCU.com --------------------------------------------*/ 8 /* --- Web: www.STCMCUDATA.com ---------------------------------------*/ 9 /* --- QQ: 800003751 -------------------------------------------------*/ 10 /* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序 */ 11 /*---------------------------------------------------------------------*/ 12 13 #include "APP_BMM_UART.h" 14 #include "STC8A_GPIO.h" 15 #include "STC8A_UART.h" 16 #include "STC8A_NVIC.h" 17 #include "STC8A_BMM.h" 18 19 20 /************* 功能说明 ************** 21 22 通过PC向MCU发送数据, MCU将收到的数据自动存入BMM空间. 23 24 当BMM空间存满设置大小的内容后,通过串口的BMM自动发送功能把存储空间的数据原样返回. 25 26 用定时器做波特率发生器,建议使用1T模式(除非低波特率用12T),并选择可被波特率整除的时钟频率,以提高精度。 27 28 下载时, 选择时钟 22.1184MHz (可以在配置文件"config.h"中修改). 29 30 ******************************************/ 31 32 33 //======================================================================== 34 // 本地常量声明 35 //======================================================================== 36 37 38 //======================================================================== 39 // 本地变量声明 40 //======================================================================== 41 42 bit BmmTx1Flag; 43 bit BmmRx1Flag; 44 bit BmmTx2Flag; 45 bit BmmRx2Flag; 46 bit BmmTx3Flag; 47 bit BmmRx3Flag; 48 bit BmmTx4Flag; 49 bit BmmRx4Flag; 50 u8 xdata BmmBuffer[256]; //收发共用缓存,同时使用多路串口时每个串口需分别定义缓存,以免相互干扰 51 52 //======================================================================== 53 // 本地函数声明 54 //======================================================================== C51 COMPILER V9.59.0.0 APP_BMM_UART 06/10/2021 10:21:41 PAGE 2 55 56 57 //======================================================================== 58 // 外部函数和变量声明 59 //======================================================================== 60 61 62 //======================================================================== 63 // 函数: BMM_UART_init 64 // 描述: 用户初始化程序. 65 // 参数: None. 66 // 返回: None. 67 // 版本: V1.0, 2021-05-27 68 //======================================================================== 69 void BMM_UART_init(void) 70 { 71 1 u16 i; 72 1 COMx_InitDefine COMx_InitStructure; //结构定义 73 1 BMM_UART_InitTypeDef BMM_UART_InitStructure; //结构定义 74 1 75 1 //---------------------------------------------- 76 1 P3_MODE_IO_PU(GPIO_Pin_0 | GPIO_Pin_1); //P3.0,P3.1 设置为准双向口 - UART1 77 1 // P1_MODE_IO_PU(GPIO_Pin_0 | GPIO_Pin_1); //P1.0,P1.1 设置为准双向口 - UART2 78 1 // P0_MODE_IO_PU(GPIO_Pin_0 | GPIO_Pin_1); //P0.0,P0.1 设置为准双向口 - UART3 79 1 // P0_MODE_IO_PU(GPIO_Pin_2 | GPIO_Pin_3); //P0.2,P0.3 设置为准双向口 - UART4 80 1 81 1 //---------------------------------------------- 82 1 COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //模式, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UA -RT_9bit_BRTx 83 1 COMx_InitStructure.UART_BRT_Use = BRT_Timer2; //使用波特率, BRT_Timer1, BRT_Timer2 (注意: 串口2固定使 -用BRT_Timer2) 84 1 COMx_InitStructure.UART_BaudRate = 115200ul; //波特率, 110 ~ 115200 85 1 COMx_InitStructure.UART_RxEnable = ENABLE; //接收允许, ENABLE或DISABLE 86 1 UART_Configuration(UART1, &COMx_InitStructure); //初始化串口 USART1,USART2,USART3,USART4 87 1 NVIC_UART1_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Pri -ority_2,Priority_3 88 1 // UART_Configuration(UART2, &COMx_InitStructure); //初始化串口 USART1,USART2,USART3,USART4 89 1 // NVIC_UART2_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,P -riority_2,Priority_3 90 1 // UART_Configuration(UART3, &COMx_InitStructure); //初始化串口 USART1,USART2,USART3,USART4 91 1 // NVIC_UART3_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,P -riority_2,Priority_3 92 1 // UART_Configuration(UART4, &COMx_InitStructure); //初始化串口 USART1,USART2,USART3,USART4 93 1 // NVIC_UART4_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,P -riority_2,Priority_3 94 1 95 1 printf("STC8A8K64D4 UART BMM Test Programme!\r\n"); //UART发送一个字符串 96 1 97 1 //---------------------------------------------- 98 1 BMM_UART_InitStructure.BMM_TX_Length = 255; //BMM传输总字节数 (0~255) + 1 99 1 BMM_UART_InitStructure.BMM_TX_Buffer = BmmBuffer; //发送数据存储地址 100 1 BMM_UART_InitStructure.BMM_RX_Length = 255; //BMM传输总字节数 (0~255) + 1 101 1 BMM_UART_InitStructure.BMM_RX_Buffer = BmmBuffer; //接收数据存储地址 102 1 BMM_UART_InitStructure.BMM_TX_Enable = ENABLE; //BMM使能 ENABLE,DISABLE 103 1 BMM_UART_InitStructure.BMM_RX_Enable = ENABLE; //BMM使能 ENABLE,DISABLE 104 1 BMM_UART_Inilize(UART1, &BMM_UART_InitStructure); //初始化 105 1 // BMM_UART_Inilize(UART2, &BMM_UART_InitStructure); //初始化 106 1 // BMM_UART_Inilize(UART3, &BMM_UART_InitStructure); //初始化 107 1 // BMM_UART_Inilize(UART4, &BMM_UART_InitStructure); //初始化 108 1 109 1 NVIC_BMM_UART1_Tx_Init(ENABLE,Priority_0,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priorit -y_0~Priority_3; 总线优先级(低到高) Priority_0~Priority_3 C51 COMPILER V9.59.0.0 APP_BMM_UART 06/10/2021 10:21:41 PAGE 3 110 1 NVIC_BMM_UART1_Rx_Init(ENABLE,Priority_0,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priorit -y_0~Priority_3; 总线优先级(低到高) Priority_0~Priority_3 111 1 // NVIC_BMM_UART2_Tx_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Prior -ity_1,Priority_2,Priority_3 112 1 // NVIC_BMM_UART2_Rx_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Prior -ity_1,Priority_2,Priority_3 113 1 // NVIC_BMM_UART3_Tx_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Prior -ity_1,Priority_2,Priority_3 114 1 // NVIC_BMM_UART3_Rx_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Prior -ity_1,Priority_2,Priority_3 115 1 // NVIC_BMM_UART4_Tx_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Prior -ity_1,Priority_2,Priority_3 116 1 // NVIC_BMM_UART4_Rx_Init(ENABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Prior -ity_1,Priority_2,Priority_3 117 1 118 1 //---------------------------------------------- 119 1 BmmTx1Flag = 0; 120 1 BmmRx1Flag = 0; 121 1 BmmTx2Flag = 0; 122 1 BmmRx2Flag = 0; 123 1 BmmTx3Flag = 0; 124 1 BmmRx3Flag = 0; 125 1 BmmTx4Flag = 0; 126 1 BmmRx4Flag = 0; 127 1 for(i=0; i<256; i++) 128 1 { 129 2 BmmBuffer[i] = i; 130 2 } 131 1 BMM_UR1T_TRIG(); //触发UART1发送功能 132 1 BMM_UR1R_TRIG(); //触发UART1接收功能 133 1 // BMM_UR2T_TRIG(); //触发UART2发送功能 134 1 // BMM_UR2R_TRIG(); //触发UART2接收功能 135 1 // BMM_UR3T_TRIG(); //触发UART3发送功能 136 1 // BMM_UR3R_TRIG(); //触发UART3接收功能 137 1 // BMM_UR4T_TRIG(); //触发UART4发送功能 138 1 // BMM_UR4R_TRIG(); //触发UART4接收功能 139 1 } 140 141 //======================================================================== 142 // 函数: Sample_BMM_UART 143 // 描述: 用户应用程序. 144 // 参数: None. 145 // 返回: None. 146 // 版本: V1.0, 2021-05-27 147 //======================================================================== 148 void Sample_BMM_UART(void) 149 { 150 1 if((BmmTx1Flag) && (BmmRx1Flag)) 151 1 { 152 2 BmmTx1Flag = 0; 153 2 BmmRx1Flag = 0; 154 2 BMM_UR1T_TRIG(); //重新触发UART1发送功能 155 2 BMM_UR1R_TRIG(); //重新触发UART1接收功能 156 2 } 157 1 158 1 if((BmmTx2Flag) && (BmmRx2Flag)) 159 1 { 160 2 BmmTx2Flag = 0; 161 2 BmmRx2Flag = 0; 162 2 BMM_UR2T_TRIG(); //重新触发UART2发送功能 163 2 BMM_UR2R_TRIG(); //重新触发UART2接收功能 164 2 } C51 COMPILER V9.59.0.0 APP_BMM_UART 06/10/2021 10:21:41 PAGE 4 165 1 166 1 if((BmmTx3Flag) && (BmmRx3Flag)) 167 1 { 168 2 BmmTx3Flag = 0; 169 2 BmmRx3Flag = 0; 170 2 BMM_UR3T_TRIG(); //重新触发UART3发送功能 171 2 BMM_UR3R_TRIG(); //重新触发UART3接收功能 172 2 } 173 1 174 1 if((BmmTx4Flag) && (BmmRx4Flag)) 175 1 { 176 2 BmmTx4Flag = 0; 177 2 BmmRx4Flag = 0; 178 2 BMM_UR4T_TRIG(); //重新触发UART4发送功能 179 2 BMM_UR4R_TRIG(); //重新触发UART4接收功能 180 2 } 181 1 } 182 183 184 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 334 ---- CONSTANT SIZE = 39 ---- XDATA SIZE = 256 17 PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = 8 ---- EDATA SIZE = ---- ---- HDATA SIZE = ---- ---- XDATA CONST SIZE = ---- ---- FAR CONST SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)