標(biāo)題: STM32 AD轉(zhuǎn)換采樣電壓十二位二進(jìn)制數(shù)LED燈顯示Proteus仿真 [打印本頁(yè)]

作者: niuzhendong    時(shí)間: 2018-12-18 17:09
標(biāo)題: STM32 AD轉(zhuǎn)換采樣電壓十二位二進(jìn)制數(shù)LED燈顯示Proteus仿真
STM32單片機(jī)AD轉(zhuǎn)換采樣電壓十二位二進(jìn)制數(shù)LED燈顯示proteus仿真
上周做的用LED燈顯示AD采樣電壓十二位二進(jìn)制顯示
粗略的顯示了一下,有些不足,希望大家能夠給予指導(dǎo)并相互學(xué)習(xí)。

仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  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.         
復(fù)制代碼

所有資料51hei提供下載:
ADC.7z (262.74 KB, 下載次數(shù): 86)



作者: pengy    時(shí)間: 2018-12-25 09:56
運(yùn)行protues直接卡死了
作者: lumilu    時(shí)間: 2019-4-24 16:56
樓主,AD采樣的參考電壓是怎么設(shè)置的啊
作者: 萬(wàn)能的小黑    時(shí)間: 2020-11-12 11:17
lumilu 發(fā)表于 2019-4-24 16:56
樓主,AD采樣的參考電壓是怎么設(shè)置的啊

滑動(dòng)變壓器吧





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1