找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3383|回复: 3
收起左侧

STM32新手ADC改编 输出十六个通道数据程序源码

[复制链接]
ID:387303 发表于 2018-8-23 11:14 | 显示全部楼层 |阅读模式
刚开始学  调程序可以参考下

单片机源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "lcd.h"
  6. #include "usart.h"         
  7. #include "adc.h"





  8. int main(void)
  9. {               
  10.         u16 i=0;
  11.         u16 times=0;
  12.         u16 adcx;
  13.         float temp;
  14.         //float temp;
  15.         delay_init();                     //延时函数初始化          
  16.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
  17.         uart_init(115200);         //串口初始化为115200
  18.         LED_Init();                             //LED端口初始化
  19.         KEY_Init();          //初始化与按键连接的硬件接口
  20.         Adc_Init();
  21.          
  22.          
  23.          
  24.         while(1)
  25.         {
  26.                 for(i=0;i<=15;i++)
  27.                 {switch(i)
  28.                         {case 0:
  29.                 adcx=Get_Adc_Average(ADC_Channel_0,1);
  30.                 printf("adcx0:");                               
  31.                 printf("%d\n",adcx);
  32.                 temp=(float)adcx*(3.3/4096);
  33.                 printf("voltage:");                               
  34.                 printf("%f\n",temp);
  35.                         break;
  36.                 case 1:
  37.                 adcx=Get_Adc_Average(ADC_Channel_1,1);
  38.                 printf("adcx1:");                               
  39.                 printf("%d\n",adcx);
  40.                 temp=(float)adcx*(3.3/4096);
  41.                 printf("voltage:");                               
  42.                 printf("%f\n",temp);
  43.                         break;
  44.                         case 2:
  45.                 adcx=Get_Adc_Average(ADC_Channel_2,1);
  46.                 printf("adcx2:");                               
  47.                 printf("%d\n",adcx);
  48.                 temp=(float)adcx*(3.3/4096);
  49.                 printf("voltage:");                               
  50.                 printf("%f\n",temp);
  51.                         break;
  52.                         case 3:
  53.                 adcx=Get_Adc_Average(ADC_Channel_3,1);
  54.                 printf("adcx3:");                               
  55.                 printf("%d\n",adcx);
  56.                 temp=(float)adcx*(3.3/4096);
  57.                 printf("voltage:");                               
  58.                 printf("%f\n",temp);
  59.                         break;
  60.                         case 4:
  61.                 adcx=Get_Adc_Average(ADC_Channel_4,1);
  62.                 printf("adcx4:");                               
  63.                 printf("%d\n",adcx);
  64.                 temp=(float)adcx*(3.3/4096);
  65.                 printf("voltage:");                               
  66.                 printf("%f\n",temp);
  67.                         break;
  68.                         case 5:
  69.                 adcx=Get_Adc_Average(ADC_Channel_5,1);
  70.                 printf("adcx5:");                               
  71.                 printf("%d\n",adcx);
  72.                 temp=(float)adcx*(3.3/4096);
  73.                 printf("voltage:");                               
  74.                 printf("%f\n",temp);
  75.                         break;
  76.                         case 6:
  77.                 adcx=Get_Adc_Average(ADC_Channel_6,1);
  78.                 printf("adcx6:");                               
  79.                 printf("%d\n",adcx);
  80.                 temp=(float)adcx*(3.3/4096);
  81.                 printf("voltage:");                               
  82.                 printf("%f\n",temp);
  83.                         break;
  84.                         case 7:
  85.                 adcx=Get_Adc_Average(ADC_Channel_7,1);
  86.                 printf("adcx7:");                               
  87.                 printf("%d\n",adcx);
  88.                 temp=(float)adcx*(3.3/4096);
  89.                 printf("voltage:");                               
  90.                 printf("%f\n",temp);
  91.                         break;
  92.                         case 8:
  93.                 adcx=Get_Adc_Average(ADC_Channel_8,1);
  94.                 printf("adcx8:");                               
  95.                 printf("%d\n",adcx);
  96.                 temp=(float)adcx*(3.3/4096);
  97.                 printf("voltage:");                               
  98.                 printf("%f\n",temp);
  99.                         break;
  100.                         case 9:
  101.                 adcx=Get_Adc_Average(ADC_Channel_9,1);
  102.                 printf("adcx9:");                               
  103.                 printf("%d\n",adcx);
  104.                 temp=(float)adcx*(3.3/4096);
  105.                 printf("voltage:");                               
  106.                 printf("%f\n",temp);
  107.                         break;
  108.                         case 10:
  109.                 adcx=Get_Adc_Average(ADC_Channel_10,1);
  110.                 printf("adcx10:");                               
  111.                 printf("%d\n",adcx);
  112.                 temp=(float)adcx*(3.3/4096);
  113.                 printf("voltage:");                               
  114.                 printf("%f\n",temp);
  115.                         break;
  116.                         case 11:
  117.                 adcx=Get_Adc_Average(ADC_Channel_11,1);
  118.                 printf("adcx11:");                               
  119.                 printf("%d\n",adcx);
  120.                 temp=(float)adcx*(3.3/4096);
  121.                 printf("voltage:");                               
  122.                 printf("%f\n",temp);
  123.                         break;
  124.                         case 12:
  125.                 adcx=Get_Adc_Average(ADC_Channel_12,1);
  126.                 printf("adcx12:");                               
  127.                 printf("%d\n",adcx);
  128.                 temp=(float)adcx*(3.3/4096);
  129.                 printf("voltage:");                               
  130.                 printf("%f\n",temp);
  131.                         break;
  132.                         case 13:
  133.                 adcx=Get_Adc_Average(ADC_Channel_13,1);
  134.                 printf("adcx13:");                               
  135.                 printf("%d\n",adcx);
  136.                 temp=(float)adcx*(3.3/4096);
  137.                 printf("voltage:");                               
  138.                 printf("%f\n",temp);
  139.                         break;
  140.                         case 14:
  141.                 adcx=Get_Adc_Average(ADC_Channel_14,1);
  142.                 printf("adcx14:");                               
  143.                 printf("%d\n",adcx);
  144.                 temp=(float)adcx*(3.3/4096);
  145.                 printf("voltage:");                               
  146.                 printf("%f\n",temp);
  147.                         break;
  148.                         case 15:
  149.                 adcx=Get_Adc_Average(ADC_Channel_15,1);
  150.                 printf("adcx15:");                               
  151.                 printf("%d\n",adcx);
  152.                 temp=(float)adcx*(3.3/4096);
  153.                 printf("voltage:");                               
  154.                 printf("%f\n",temp);
  155.                         break;       
  156.                 }       
  157.         }
  158.                 delay_ms(1000);       
  159. }
  160.         }
复制代码

所有资料51hei提供下载:
ADC改编.rar (338.06 KB, 下载次数: 41)
回复

使用道具 举报

ID:441972 发表于 2019-1-16 15:23 | 显示全部楼层
程序能运行吗?下载到开发板没有数据输出,编译没有问题
回复

使用道具 举报

ID:441972 发表于 2019-1-16 17:11 | 显示全部楼层
感谢,搞了快2个小时才发现问题,可以运行
回复

使用道具 举报

ID:277960 发表于 2019-3-28 01:03 | 显示全部楼层
感谢,,虽然有一个致命错误,,,
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表