C51 COMPILER V9.59.0.0 APP_BMM_AD 06/10/2021 18:07:15 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE APP_BMM_AD OBJECT MODULE PLACED IN .\list\APP_BMM_AD.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE ..\App\src\APP_BMM_AD.c LARGE OMF2 OPTIMIZE(8,SPEED) BROWSE INCDIR(..\Dr -iver\inc;..\User;..\App\inc) DEBUG PRINT(.\list\APP_BMM_AD.lst) TABS(2) OBJECT(.\list\APP_BMM_AD.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_AD.h" 14 #include "STC8A_GPIO.h" 15 #include "STC8A_ADC.h" 16 #include "STC8A_UART.h" 17 #include "STC8A_BMM.h" 18 #include "STC8A_NVIC.h" 19 20 21 /************* 功能说明 ************** 22 23 本程序演示多路ADC BMM采样. 24 25 初始化时先把要ADC转换的引脚设置为高阻输入. 26 27 设置数据批量传输(BMM)功能,所有通道一次循环采集的数据自动存放到BMM定义的xdata空间. 28 29 通过串口1(P3.0 P3.1)将BMM定义的xdata空间所收到的数据发送给上位机,波特率115200,8,n,1. 30 31 用定时器做波特率发生器,建议使用1T模式(除非低波特率用12T),并选择可被波特率整除的时钟频率,以提高精度. 32 33 下载时, 选择时钟 22.1184MHz (可以在配置文件"config.h"中修改). 34 35 ******************************************/ 36 37 38 //======================================================================== 39 // 本地常量声明 40 //======================================================================== 41 42 #define ADC_CH 16 /* 1~16, ADC转换通道数, 需同步修改转换通道 */ 43 #define ADC_DATA 12 /* 6~n, 每个通道ADC转换数据总数, 2*转换次数+4, 需同步修改转换次数 */ 44 45 //======================================================================== 46 // 本地变量声明 47 //======================================================================== 48 49 u8 chn = 0; 50 bit BmmADCFlag = 0; 51 u8 xdata BmmAdBuffer[ADC_CH][ADC_DATA]; 52 53 //======================================================================== 54 // 本地函数声明 C51 COMPILER V9.59.0.0 APP_BMM_AD 06/10/2021 18:07:15 PAGE 2 55 //======================================================================== 56 57 58 //======================================================================== 59 // 外部函数和变量声明 60 //======================================================================== 61 62 63 //======================================================================== 64 // 函数: ADtoUART_init 65 // 描述: 用户初始化程序. 66 // 参数: None. 67 // 返回: None. 68 // 版本: V1.0, 2020-09-28 69 //======================================================================== 70 void BMM_AD_init(void) 71 { 72 1 ADC_InitTypeDef ADC_InitStructure; //结构定义 73 1 COMx_InitDefine COMx_InitStructure; //结构定义 74 1 BMM_ADC_InitTypeDef BMM_ADC_InitStructure; //结构定义 75 1 76 1 //---------------------------------------------- 77 1 P0_MODE_IN_HIZ(GPIO_Pin_LOW | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6); //P0.0~P0.6 设置为高阻输入 78 1 P1_MODE_IN_HIZ(GPIO_Pin_All); //P1.0~P1.7 设置为高阻输入 79 1 P3_MODE_IO_PU(GPIO_Pin_0 | GPIO_Pin_1); //P3.0,P3.1 设置为准双向口 80 1 81 1 //---------------------------------------------- 82 1 COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //模式, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,U -ART_9bit_BRTx 83 1 COMx_InitStructure.UART_BRT_Use = BRT_Timer1; //使用波特率, 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_1); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Pri -ority_2,Priority_3 88 1 89 1 //---------------------------------------------- 90 1 ADC_InitStructure.ADC_SMPduty = 31; //ADC 模拟信号采样时间控制, 0~31(注意: SMPDUTY 一定不能设置小于 -10) 91 1 ADC_InitStructure.ADC_CsSetup = 0; //ADC 通道选择时间控制 0(默认),1 92 1 ADC_InitStructure.ADC_CsHold = 1; //ADC 通道选择保持时间控制 0,1(默认),2,3 93 1 ADC_InitStructure.ADC_Speed = ADC_SPEED_2X1T; //设置 ADC 工作时钟频率 ADC_SPEED_2X1T~ADC_SPEED_2X16T 94 1 ADC_InitStructure.ADC_AdjResult = ADC_RIGHT_JUSTIFIED; //ADC结果调整, ADC_LEFT_JUSTIFIED,ADC_RIGHT_JUSTIF -IED 95 1 ADC_Inilize(&ADC_InitStructure); //初始化 96 1 ADC_PowerControl(ENABLE); //ADC电源开关, ENABLE或DISABLE 97 1 NVIC_ADC_Init(DISABLE,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Prio -rity_2,Priority_3 98 1 99 1 //---------------------------------------------- 100 1 BMM_ADC_InitStructure.BMM_Enable = ENABLE; //BMM使能 ENABLE,DISABLE 101 1 BMM_ADC_InitStructure.BMM_Channel = 0xffff; //ADC通道使能寄存器, 1:使能, bit15~bit0 对应 ADC15~ADC0 102 1 BMM_ADC_InitStructure.BMM_Buffer = BmmAdBuffer; //ADC转换数据存储地址 103 1 BMM_ADC_InitStructure.BMM_Times = ADC_4_Times; //每个通道转换次数, ADC_1_Times,ADC_2_Times,ADC_4_Times,AD -C_8_Times,ADC_16_Times,ADC_32_Times,ADC_64_Times,ADC_128_Times,ADC_256_Times 104 1 BMM_ADC_Inilize(&BMM_ADC_InitStructure); //初始化 105 1 NVIC_BMM_ADC_Init(ENABLE,Priority_0,Priority_0); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0~P -riority_3; 总线优先级(低到高) Priority_0~Priority_3 106 1 BMM_ADC_TRIG(); //触发启动转换 107 1 } 108 C51 COMPILER V9.59.0.0 APP_BMM_AD 06/10/2021 18:07:15 PAGE 3 109 //======================================================================== 110 // 函数: Sample_BMM_AD 111 // 描述: 用户应用程序. 112 // 参数: None. 113 // 返回: None. 114 // 版本: V1.0, 2020-09-24 115 //======================================================================== 116 void Sample_BMM_AD(void) 117 { 118 1 u8 i,n; 119 1 120 1 if(BmmADCFlag) 121 1 { 122 2 BmmADCFlag = 0; 123 2 for(i=0; i