Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
6.0 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. C51 COMPILER V8.02 A2D 02/07/2008 21:06:49 PAGE 1
  2. C51 COMPILER V8.02, COMPILATION OF MODULE A2D
  3. OBJECT MODULE PLACED IN A2D.OBJ
  4. COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE A2D.c OMF2 ROM(COMPACT) OPTIMIZE(9,SPEED) ORDER NOINTPROMOTE NOINTVECTOR
  5. line level source
  6. 1 #include "StdAfx.h"
  7. 2 #include "SysClock.h"
  8. 3 #include "A2D.h"
  9. 4 #include "Timer.h"
  10. 5
  11. 6 static WORD wValueA2D;
  12. 7
  13. 8 sfr16 ADC0 = 0xBE; // ADC0 data
  14. 9
  15. 10 #define ADC_SAR_CLOCK 2500000L
  16. 11
  17. 12 void ADC0_Init()
  18. 13 {
  19. 14 1 // Save Current SFR page
  20. 15 1 XBYTE SFRPAGE_SAVE = SFRPAGE;
  21. 16 1
  22. 17 1 XBYTE nSAR = SYSCLK / (2 * ADC_SAR_CLOCK) - 1;
  23. 18 1
  24. 19 1 // Set ADC page
  25. 20 1 SFRPAGE = ADC0_PAGE;
  26. 21 1
  27. 22 1 // enable temp sensor, on-chip VREF,
  28. 23 1 // and VREF output buffer
  29. 24 1 REF0CN = 0x07;
  30. 25 1
  31. 26 1 // select TEMP sens as ADC mux output
  32. 27 1 AMX0SL = 0x0F;
  33. 28 1
  34. 29 1 // all inputs a independant
  35. 30 1 AMX0CF = 0x00;
  36. 31 1
  37. 32 1 // ADC0 disabled; normal tracking
  38. 33 1 // mode; ADC0 conversions are initiated
  39. 34 1 // on Busy bit; ADC0 data is
  40. 35 1 // right-justified
  41. 36 1 ADC0CN = 0x00;
  42. 37 1 // ADC conversion clock = 2.5 MHz
  43. 38 1 ADC0CF = 0x20;//nSAR << 3;
  44. 39 1 // PGA gain = 1
  45. 40 1 ADC0CF |= 0x00;
  46. 41 1
  47. 42 1 // set tracking mode
  48. 43 1 AD0TM = 0;//1; // for mirror was 1, for normal system is 0. ???
  49. 44 1
  50. 45 1 // enable ADC
  51. 46 1 AD0EN = 1;
  52. 47 1
  53. 48 1 // Restore SFR page
  54. 49 1 SFRPAGE = SFRPAGE_SAVE;
  55. 50 1 }
  56. 51 /*
  57. 52 void ADC0_Start( BYTE bChannel )
  58. 53 {
  59. 54 XBYTE SFRPAGE_SAVE = SFRPAGE;
  60. 55
  61. C51 COMPILER V8.02 A2D 02/07/2008 21:06:49 PAGE 2
  62. 56 SFRPAGE = ADC0_PAGE;
  63. 57
  64. 58 AMX0SL = bChannel;
  65. 59 AD0INT = 0;
  66. 60 AD0BUSY = 1;
  67. 61
  68. 62 SFRPAGE = SFRPAGE_SAVE;
  69. 63 }
  70. 64
  71. 65 BOOL ADC0_GetValue( PWORD pValue )
  72. 66 {
  73. 67 XBYTE SFRPAGE_SAVE = SFRPAGE;
  74. 68 SFRPAGE = ADC0_PAGE;
  75. 69
  76. 70 if( !AD0INT )
  77. 71 {
  78. 72 SFRPAGE = SFRPAGE_SAVE;
  79. 73
  80. 74 return FALSE;
  81. 75 }
  82. 76
  83. 77 AD0INT = 0;
  84. 78
  85. 79 *pValue = ADC0;
  86. 80
  87. 81 SFRPAGE = SFRPAGE_SAVE;
  88. 82
  89. 83 return TRUE;
  90. 84 }
  91. 85 */
  92. 86 WORD ADC0_Convert( BYTE bChannel )
  93. 87 {
  94. 88 1 static BYTE SFRPAGE_SAVE;
  95. 89 1 SFRPAGE_SAVE = SFRPAGE;
  96. 90 1 SFRPAGE = ADC0_PAGE;
  97. 91 1
  98. 92 1 // select channel
  99. 93 1 AMX0SL = bChannel;
  100. 94 1 AD0INT = 0;
  101. 95 1
  102. 96 1 // settling time for accurate conversion (around 2.5 uS on 100 MHz)
  103. 97 1 // HiResTimer0_Wait( MICRO_SEC_TO_HIRES(2) );
  104. 98 1 HiResTimer1_Wait( 5 );
  105. 99 1
  106. 100 1 // start conversion
  107. 101 1 AD0BUSY = 1;
  108. 102 1
  109. 103 1 // wait for end of conversion
  110. 104 1 while( !AD0INT );
  111. 105 1
  112. 106 1 // clear condition
  113. 107 1 AD0INT = 0;
  114. 108 1
  115. 109 1 // copy result
  116. 110 1 wValueA2D = ADC0;
  117. 111 1
  118. 112 1 SFRPAGE = SFRPAGE_SAVE;
  119. 113 1
  120. 114 1 return wValueA2D;
  121. 115 1 }
  122. 116
  123. 117 /*
  124. C51 COMPILER V8.02 A2D 02/07/2008 21:06:49 PAGE 3
  125. 118 LONG ADC0_Adc2Temperature( WORD wValue )
  126. 119 {
  127. 120 LONG lTemperature = ( ((LONG)(INT)wValue) * V_REF * 1000L - 7760L * MAX_ADC * PGAIN ) / ( 286L * MAX_ADC
  128. - * PGAIN / 10L );
  129. 121
  130. 122 // compensate self heating
  131. 123 return lTemperature;// * 10000L / 11875L;
  132. 124 }
  133. 125
  134. 126 WORD ADC0_Temperature2Adc( LONG lTemperature )
  135. 127 {
  136. 128 wValueA2D = (lTemperature * ( 286L * MAX_ADC * PGAIN / 10L ) + 7760L * MAX_ADC * PGAIN) / (V_REF * 1000L
  137. -);
  138. 129
  139. 130 // compensate self heating
  140. 131 return wValueA2D;// * 11875L / 10000L;
  141. 132 }
  142. 133 */
  143. MODULE INFORMATION: STATIC OVERLAYABLE
  144. CODE SIZE = 74 ----
  145. CONSTANT SIZE = ---- ----
  146. XDATA SIZE = ---- 2
  147. PDATA SIZE = ---- ----
  148. DATA SIZE = 3 ----
  149. IDATA SIZE = ---- ----
  150. BIT SIZE = ---- ----
  151. EDATA SIZE = ---- ----
  152. HDATA SIZE = ---- ----
  153. XDATA CONST SIZE = ---- ----
  154. FAR CONST SIZE = ---- ----
  155. END OF MODULE INFORMATION.
  156. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)