Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  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 czujnika temperatury */
  9.  
  10. #define TSENS 4
  11. #define AINPUTS 0xffcf
  12. void ADCinit(int amask)
  13.  
  14. {
  15. AD1PCFG = amask;
  16. AD1CON1 = 0x00e0;
  17. AD1CSSL = 0;
  18. AD1CON2 = 0;
  19. AD1CON3 = 0x1f02;
  20. AD1CON1bits.ADON = 1;
  21. }
  22.  
  23. int readADC(int ch)
  24.  
  25. {
  26. AD1CHS = ch;
  27. AD1CON1bits.SAMP = 1;
  28. while (!AD1CON1bits.DONE);
  29. return ADC1BUF0;
  30. }
  31.  
  32.  
  33. int main(void)
  34. {
  35. TRISA = 0xFF00;
  36. TRISD = 0xFFFF;
  37.  
  38. unsigned long x=0,i,czas=1;
  39. unsigned char display = 0;
  40. int temp;
  41. unsigned int szybkosc = 100L;
  42. unsigned long kontrolna= 250;
  43.  
  44. PORTA = 0x0000;
  45. ADCinit(AINPUTS); /*inicjalizacja konwertera AD*/
  46.  
  47.  
  48.  
  49. while (1) {
  50.  
  51. Nop();
  52.  
  53. for (i = szybkosc * SCALE; i > 0; i--) Nop();
  54. temp = readADC(TSENS);
  55. if(x==0)
  56. {
  57. if(temp>kontrolna)
  58. {
  59. if(czas<8)
  60. {
  61. for (i = szybkosc * SCALE; i > 0; i--) Nop();
  62. temp = readADC(TSENS);
  63. display = 1;
  64. PORTA = (unsigned int)display;
  65. for (i = szybkosc * SCALE; i > 0; i--) Nop();
  66. display = 0;
  67. PORTA = (unsigned int)display;
  68. czas++;
  69. if(PORTDbits.RD13 == 0)
  70. {
  71. display=0;
  72. PORTA=(unsigned int) display;
  73. x=1;
  74. }
  75. if(PORTDbits.RD6 == 0)
  76. {
  77. kontrolna=kontrolna+10;
  78. }
  79. }
  80. if(czas>=8)
  81. {
  82. display=255;
  83. PORTA=(unsigned int) display;
  84. if(PORTDbits.RD13 == 0)
  85. {
  86. display=0;
  87. PORTA=(unsigned int) display;
  88. x=1;
  89. }
  90. if(PORTDbits.RD6 == 0)
  91. {
  92. kontrolna=kontrolna+10;
  93. }
  94. }
  95.  
  96. }
  97.  
  98. }
  99. }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement