找回密码
 立即注册

QQ登录

只需一步,快速开始

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

STM32 AD转换采样电压十二位二进制数LED灯显示Proteus仿真

[复制链接]
ID:436144 发表于 2018-12-18 17:09 | 显示全部楼层 |阅读模式
STM32单片机AD转换采样电压十二位二进制数LED灯显示proteus仿真
上周做的用LED灯显示AD采样电压十二位二进制显示
粗略的显示了一下,有些不足,希望大家能够给予指导并相互学习。

仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
0.png 0.png

单片机源程序如下:
  1. #include "stm32f10x.h"
  2. #include "usart1.h"
  3. #include "adc.h"
  4. #include "stdio.h"
  5. #include "led.h"

  6. float temp;
  7. int main(void)
  8. {
  9.         GPIO_Led_Config();
  10.   ADC1_GPIO_Config();
  11.   ADC_Config();
  12.         while(1)
  13.         {               
  14.     int a,b,c,d,e,f,g,h,i,j,k,l,m;                        
  15.                          ADCConvertedValue=ADC_GetConversionValue(ADC1);
  16. //                         temp=(float)ADCConvertedValue*(3.3/4096);         
  17.                 a=ADCConvertedValue;
  18.         b=a%2;
  19.         c=(a/2)%2;
  20.         d=(a/4)%2;
  21.         e=(a/8)%2;
  22.         f=(a/16)%2;
  23.         g=(a/32)%2;
  24.         h=(a/64)%2;
  25.         i=(a/128)%2;
  26.         j=(a/256)%2;
  27.         k=(a/512)%2;
  28.         l=(a/1024)%2;
  29.         m=(a/2048)%2;
  30.         
  31. if(b==1)        
  32.         GPIO_SetBits(GPIOB,GPIO_Pin_1);
  33. else
  34.         GPIO_ResetBits(GPIOB,GPIO_Pin_1);
  35. if(c==1)        
  36.         GPIO_SetBits(GPIOB,GPIO_Pin_2);
  37. else
  38.         GPIO_ResetBits(GPIOB,GPIO_Pin_2);
  39. if(d==1)        
  40.         GPIO_SetBits(GPIOB,GPIO_Pin_3);
  41. else
  42.         GPIO_ResetBits(GPIOB,GPIO_Pin_3);
  43. if(e==1)        
  44.         GPIO_SetBits(GPIOB,GPIO_Pin_4);
  45. else
  46.         GPIO_ResetBits(GPIOB,GPIO_Pin_4);
  47. if(f==1)        
  48.         GPIO_SetBits(GPIOB,GPIO_Pin_5);
  49. else
  50.         GPIO_ResetBits(GPIOB,GPIO_Pin_5);
  51. if(g==1)        
  52.         GPIO_SetBits(GPIOB,GPIO_Pin_6);
  53. else
  54.         GPIO_ResetBits(GPIOB,GPIO_Pin_6);
  55. if(h==1)        
  56.         GPIO_SetBits(GPIOB,GPIO_Pin_7);
  57. else
  58.         GPIO_ResetBits(GPIOB,GPIO_Pin_7);
  59. if(i==1)        
  60.         GPIO_SetBits(GPIOB,GPIO_Pin_8);
  61. else
  62.         GPIO_ResetBits(GPIOB,GPIO_Pin_8);
  63. if(j==1)        
  64.         GPIO_SetBits(GPIOB,GPIO_Pin_9);
  65. else
  66.         GPIO_ResetBits(GPIOB,GPIO_Pin_9);
  67. if(k==1)        
  68.         GPIO_SetBits(GPIOB,GPIO_Pin_10);
  69. else
  70.         GPIO_ResetBits(GPIOB,GPIO_Pin_10);
  71. if(l==1)        
  72.         GPIO_SetBits(GPIOB,GPIO_Pin_11);
  73. else
  74.         GPIO_ResetBits(GPIOB,GPIO_Pin_11);
  75. if(m==1)        
  76.         GPIO_SetBits(GPIOB,GPIO_Pin_12);
  77. else
  78.         GPIO_ResetBits(GPIOB,GPIO_Pin_12);
  79.         }
  80. }
  81.         
复制代码

所有资料51hei提供下载:
ADC.7z (262.74 KB, 下载次数: 84)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:224469 发表于 2018-12-25 09:56 | 显示全部楼层
运行protues直接卡死了
回复

使用道具 举报

ID:162058 发表于 2019-4-24 16:56 | 显示全部楼层
楼主,AD采样的参考电压是怎么设置的啊
回复

使用道具 举报

ID:324291 发表于 2020-11-12 11:17 | 显示全部楼层
lumilu 发表于 2019-4-24 16:56
楼主,AD采样的参考电压是怎么设置的啊

滑动变压器吧
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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