C51 COMPILER V9.59.0.0 APP_AD_UART 06/10/2021 10:21:36 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE APP_AD_UART OBJECT MODULE PLACED IN .\list\APP_AD_UART.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE ..\App\src\APP_AD_UART.c LARGE OMF2 OPTIMIZE(8,SPEED) BROWSE INCDIR(..\D -river\inc;..\User;..\App\inc) DEBUG PRINT(.\list\APP_AD_UART.lst) TABS(2) OBJECT(.\list\APP_AD_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_AD_UART.h" 14 #include "STC8A_GPIO.h" 15 #include "STC8A_ADC.h" 16 #include "STC8A_UART.h" 17 #include "STC8A_NVIC.h" 18 19 20 /************* 功能说明 ************** 21 22 本程序演示多路ADC查询采样,通过串口发送给上位机,波特率115200,N,8,1。 23 24 用定时器做波特率发生器,建议使用1T模式(除非低波特率用12T),并选择可被波特率整除的时钟频率,以提高精度。 25 26 下载时, 选择时钟 22.1184MHz (可以在配置文件"config.h"中修改). 27 28 ******************************************/ 29 30 31 //======================================================================== 32 // 本地常量声明 33 //======================================================================== 34 35 36 //======================================================================== 37 // 本地变量声明 38 //======================================================================== 39 40 u8 index = 0; 41 42 //======================================================================== 43 // 本地函数声明 44 //======================================================================== 45 46 47 //======================================================================== 48 // 外部函数和变量声明 49 //======================================================================== 50 51 52 //======================================================================== 53 // 函数: ADtoUART_init 54 // 描述: 用户初始化程序. C51 COMPILER V9.59.0.0 APP_AD_UART 06/10/2021 10:21:36 PAGE 2 55 // 参数: None. 56 // 返回: None. 57 // 版本: V1.0, 2020-09-28 58 //======================================================================== 59 void ADtoUART_init(void) 60 { 61 1 ADC_InitTypeDef ADC_InitStructure; //结构定义 62 1 COMx_InitDefine COMx_InitStructure; //结构定义 63 1 64 1 P0_MODE_IN_HIZ(GPIO_Pin_LOW | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6); //P0.0~P0.6 设置为高阻输入 65 1 P1_MODE_IN_HIZ(GPIO_Pin_All); //P1.0~P1.7 设置为高阻输入 66 1 P3_MODE_IO_PU(GPIO_Pin_0 | GPIO_Pin_1); //P3.0,P3.1 设置为准双向口 67 1 68 1 COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //模式, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,U -ART_9bit_BRTx 69 1 COMx_InitStructure.UART_BRT_Use = BRT_Timer1; //使用波特率, BRT_Timer1, BRT_Timer2 (注意: 串口2固定使 -用BRT_Timer2) 70 1 COMx_InitStructure.UART_BaudRate = 115200ul; //波特率, 110 ~ 115200 71 1 COMx_InitStructure.UART_RxEnable = ENABLE; //接收允许, ENABLE或DISABLE 72 1 UART_Configuration(UART1, &COMx_InitStructure); //初始化串口 USART1,USART2,USART3,USART4 73 1 NVIC_UART1_Init(ENABLE,Priority_1); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Pri -ority_2,Priority_3 74 1 75 1 ADC_InitStructure.ADC_SMPduty = 31; //ADC 模拟信号采样时间控制, 0~31(注意: SMPDUTY 一定不能设置小于 -10) 76 1 ADC_InitStructure.ADC_CsSetup = 0; //ADC 通道选择时间控制 0(默认),1 77 1 ADC_InitStructure.ADC_CsHold = 1; //ADC 通道选择保持时间控制 0,1(默认),2,3 78 1 ADC_InitStructure.ADC_Speed = ADC_SPEED_2X1T; //设置 ADC 工作时钟频率 ADC_SPEED_2X1T~ADC_SPEED_2X16T 79 1 ADC_InitStructure.ADC_AdjResult = ADC_RIGHT_JUSTIFIED; //ADC结果调整, ADC_LEFT_JUSTIFIED,ADC_RIGHT_JUSTIF -IED 80 1 ADC_Inilize(&ADC_InitStructure); //初始化 81 1 ADC_PowerControl(ENABLE); //ADC电源开关, ENABLE或DISABLE 82 1 NVIC_ADC_Init(DISABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Prio -rity_2,Priority_3 83 1 } 84 85 //======================================================================== 86 // 函数: Sample_ADtoUART 87 // 描述: 用户应用程序. 88 // 参数: None. 89 // 返回: None. 90 // 版本: V1.0, 2020-09-24 91 //======================================================================== 92 void Sample_ADtoUART(void) 93 { 94 1 u16 j; 95 1 96 1 j = Get_ADCResult(index); //参数0~15,查询方式获取一次ADC, 返回值就是结果, == 4096 为错误 97 1 printf("AD%02bd=%04d ",index,j); 98 1 if((index & 7) == 7) printf("\r\n"); 99 1 100 1 index++; 101 1 if(index > 15) 102 1 { 103 2 index = 0; 104 2 } 105 1 } 106 107 108 C51 COMPILER V9.59.0.0 APP_AD_UART 06/10/2021 10:21:36 PAGE 3 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 168 ---- CONSTANT SIZE = 17 ---- XDATA SIZE = 1 14 PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = ---- ---- EDATA SIZE = ---- ---- HDATA SIZE = ---- ---- XDATA CONST SIZE = ---- ---- FAR CONST SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)