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