SHARE
TWEET

Untitled

a guest May 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <p24fj128ga010.h>
  2.  
  3. _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & BKBUG_OFF & COE_OFF & FWDTEN_OFF)
  4. _CONFIG2(FCKSM_CSDCMD & OSCIOFNC_ON & POSCMOD_HS & FNOSC_PRI)
  5.  
  6. #define SCALE 308L
  7.  
  8. /* numer ktĂłrym dostajemy siÄ? do potencjometru */
  9. #define TVOLT 5
  10. #define AINPUTS 0xffcf
  11.  
  12. void ADCinit(int amask)
  13. {
  14.     AD1PCFG = amask;
  15.     AD1CON1 = 0x00e0;
  16.     AD1CSSL = 0;
  17.     AD1CON2 = 0;
  18.     AD1CON3 = 0x1f02;
  19.     AD1CON1bits.ADON = 1;
  20. }
  21.  
  22. int readADC(int ch)
  23. {
  24.     AD1CHS = ch;
  25.     AD1CON1bits.SAMP = 1;
  26.     while (!AD1CON1bits.DONE);
  27.     return ADC1BUF0;
  28. }
  29.  
  30. int main(void)
  31. {
  32.     unsigned long i;
  33.     unsigned char display=0;
  34.  
  35.     int volt;
  36.     int speed=500;
  37.  
  38.     //maksymalna wartoĹ?Ä? jakÄ? moĹźna odczytaÄ? to ok 1123. na jej
  39.     //podstawie przeskalujemy wynik
  40.     int maxOdczyt = 1123;
  41.    
  42.     //inicjalizacja
  43.     PORTA = 0x0000;
  44.     TRISA=0xFF00;
  45.     TRISD=0xFFFF;
  46.     ADCinit(AINPUTS); //inicjalizacja konwertera AD
  47.  
  48.  
  49.     while (1) {
  50.         Nop();
  51.         PORTA=(unsigned int) display;
  52.         for (i = speed * SCALE; i > 0; i--) Nop();
  53.         display=display+1;
  54.         volt = readADC(TVOLT); //Odczytanie potencjometru
  55.         //display=volt;
  56.  
  57.         if(volt > 100) speed = 100;
  58.         if(volt > 200) speed = 500;
  59.         if(volt > 300) speed = 1000;
  60.         if(volt > 400) speed = 1500;
  61.         if(volt > 500) speed = 2000;
  62.        
  63.         if (volt <= 10) volt=500;
  64.     }
  65.  
  66.     return 0;
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top