Advertisement
Guest User

zad2

a guest
May 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include "stm32f10x.h"
  2. #include "evbLib.h"
  3. #include <stdio.h>
  4.  
  5. int x=0,y=0;
  6.  
  7. void czysc() {
  8. lcdGoTo(0,0); lcdWrite(" "); //16
  9. lcdGoTo(1,0); lcdWrite(" "); //16
  10. lcdGoTo(x,y);
  11. }
  12.  
  13. int main(void) {
  14. int ADC_value;
  15. float napiece_ADC;
  16. char odczyt[5];
  17. int i;
  18. ADC_InitTypeDef ADC_InitStruct;
  19. // wlaczenie taktowania zegara dla przetwornika ADC1
  20. RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
  21. //konfigurowanie przetwornika ADC
  22. ADC_InitStruct.ADC_Mode=ADC_Mode_Independent;
  23. ADC_InitStruct.ADC_ScanConvMode=DISABLE;
  24. ADC_InitStruct.ADC_ContinuousConvMode=ENABLE;
  25. ADC_InitStruct.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;
  26. ADC_InitStruct.ADC_DataAlign=ADC_DataAlign_Right;
  27. ADC_InitStruct.ADC_NbrOfChannel=1;
  28. ADC_Init(ADC1, &ADC_InitStruct);
  29. ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_71Cycles5);
  30. //wlaczenie ADC
  31. ADC_Cmd(ADC1, ENABLE);
  32. ADC_SoftwareStartConvCmd(ADC1, ENABLE);
  33.  
  34. while(1) {
  35. ADC_value= ADC_GetConversionValue(ADC1);
  36. napiece_ADC=ADC_value*0.0008056640625; // bitowa rozdzielczosc przetwarzania 3,3V/4096 = 0.0008056640625
  37. sprintf(odczyt,"%.2f V", napiece_ADC); // .2 okresla 2 miejsca po przecinku
  38. lcdWrite(odczyt);
  39. lcdGoTo(1,0);
  40. for(i=0;i<16;i++) {
  41. if(napiece_ADC>3.3*i/16) { lcdWrite("-"); }
  42. }
  43. delayMs(2000);
  44. czysc();
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement