C51 COMPILER V9.01 MAIN 12/16/2025 16:53:47 PAGE 1 C51 COMPILER V9.01, COMPILATION OF MODULE MAIN OBJECT MODULE PLACED IN .\Objects\main.obj COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE main.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listings\main -.lst) OBJECT(.\Objects\main.obj) line level source 1 #include "config.h" 2 #include "gpio.h" 3 #include "UART.h" 4 #include "string.h" 5 #include "UART_Set.h" 6 #include "pwm_control.h" 7 #include "Start_Init.h" 8 #include "key.h" 9 #include "WDT.h" 10 /************* 功能说明 ************** 11 12 本例程基于STC8H8K64U为主控芯片的实验箱8进行编写测试,STC8G、STC8H系列芯片可通用参考. 13 14 双串口全双工中断方式收发通讯程序。 15 16 通过PC向MCU发送数据, MCU收到后通过串口把收到的数据原样返回, 默认波特率:115200,N,8,1. 17 18 通过开启 UART.h 头文件里面的 UART1~UART4 定义,启动不同通道的串口通信。 19 20 用定时器做波特率发生器,建议使用1T模式(除非低波特率用12T),并选择可被波特率整除的时钟频率,以提高精度。 21 22 下载时, 选择时钟 22.1184MHz (可以在配置文件"config.h"中修改). 23 24 25 /******************* IO配置函数 *******************/ 26 27 28 void GPIO1_config(void) 29 { 30 1 GPIO_InitTypeDef GPIO_InitStructure; //结构定义 31 1 32 1 GPIO_InitStructure.Pin = GPIO_Pin_0 | GPIO_Pin_1; //指定要初始化的IO, GPIO_Pin_0 ~ GPIO_Pin_7 33 1 GPIO_InitStructure.Mode = GPIO_PullUp; //指定IO的输入或输出方式,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_O -UT_PP 34 1 GPIO_Inilize(GPIO_P3,&GPIO_InitStructure); //初始化 35 1 } 36 37 /*************** 串口初始化函数 *****************/ 38 void UART1_config(void) 39 { 40 1 COMx_InitDefine COMx_InitStructure; //结构定义 41 1 COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //模式, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART -_9bit_BRTx 42 1 COMx_InitStructure.UART_BRT_Use = BRT_Timer1; //使用波特率, BRT_Timer1, BRT_Timer2 (注意: 串口2固定使 -用BRT_Timer2) 43 1 COMx_InitStructure.UART_BaudRate = 115200; //波特率, 一般 110 ~ 115200 44 1 COMx_InitStructure.UART_RxEnable = ENABLE; //接收允许, ENABLE或DISABLE 45 1 COMx_InitStructure.BaudRateDouble = DISABLE; //波特率加倍, ENABLE或DISABLE 46 1 COMx_InitStructure.UART_Interrupt = ENABLE; //中断允许, ENABLE或DISABLE 47 1 COMx_InitStructure.UART_Priority = Priority_0; //指定中断优先级(低到高) Priority_0,Priority_1,Priori -ty_2,Priority_3 48 1 COMx_InitStructure.UART_P_SW = UART1_SW_P30_P31; //切换端口, UART1_SW_P30_P31,UART1_SW_P36_P37,UAR -T1_SW_P16_P17,UART1_SW_P43_P44 49 1 UART_Configuration(UART1, &COMx_InitStructure); //初始化串口1 UART1,UART2,UART3,UART4 C51 COMPILER V9.01 MAIN 12/16/2025 16:53:47 PAGE 2 50 1 51 1 //PrintString1("STC8H8K64U UART1 Test Programme!\r\n"); //UART1发送一个字符串 52 1 } 53 54 /********************WDT INT配置 ********************/ 55 void WDT_config(void) 56 { 57 1 WDT_InitTypeDef WDT_InitStructure; //结构定义 58 1 59 1 WDT_InitStructure.WDT_Enable = ENABLE; //中断使能 ENABLE或DISABLE 60 1 WDT_InitStructure.WDT_IDLE_Mode = WDT_IDLE_STOP; //IDLE模式是否停止计数 WDT_IDLE_STOP,WDT_IDLE_RUN 61 1 WDT_InitStructure.WDT_PS = WDT_SCALE_32; //看门狗定时器时钟分频系数 WDT_SCALE_2,WDT_SCALE_4,WDT -_SCALE_8,WDT_SCALE_16,WDT_SCALE_32,WDT_SCALE_64,WDT_SCALE_128,WDT_SCALE_256 62 1 WDT_Inilize(&WDT_InitStructure); //初始化 63 1 } 64 65 u8 count_flag=0; 66 void main(void) 67 { 68 1 GPIO_config(); 69 1 UART3_config(); 70 1 Start_Init(); 71 1 pwm_config(); 72 1 Timer2_Init_1ms(); 73 1 Key_Init(); 74 1 GPIO1_config(); 75 1 UART1_config(); 76 1 WDT_config(); //看门狗,629ms复位 77 1 78 1 PCON &= ~POF; //清除LVD中断标志位 79 1 RSTCFG = 0x41; //LVD:2.4V低压复位 80 1 EA = 1; 81 1 82 1 if(debug) 83 1 { 84 2 PrintString1("MCU Start"); 85 2 } 86 1 87 1 while (1) 88 1 { 89 2 WDT_Clear(); //清狗 90 2 count_flag++; 91 2 92 2 //为了保证某电压2.2V以上 93 2 if(count_flag==1) 94 2 { 95 3 P10=1; 96 3 } 97 2 if(count_flag==8) 98 2 { 99 3 P10=0; 100 3 } 101 2 if(count_flag==10) 102 2 { 103 3 count_flag=0; 104 3 } 105 2 106 2 Usart_judge_Data(); 107 2 108 2 Usart_Deal_Data(); 109 2 110 2 deal_command1(); C51 COMPILER V9.01 MAIN 12/16/2025 16:53:47 PAGE 3 111 2 112 2 deal_command2(); 113 2 114 2 // checkpwm(); 115 2 116 2 show_light(); 117 2 118 2 Usart_answer(); 119 2 120 2 Key_ScanTask(); 121 2 122 2 KEY_TEST(); 123 2 124 2 } 125 1 } 126 127 128 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 175 ---- CONSTANT SIZE = 10 ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 1 17 IDATA SIZE = ---- ---- BIT SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)