OSDN Git Service

[Schematic][v1.0][MCU] Fix oops on LCD-CONNECTOR.
[openi2cradio/OpenI2CRadio.git] / adc_int.c
index 223031e..df2c628 100644 (file)
--- a/adc_int.c
+++ b/adc_int.c
 #include "adc_int.h"
 void intadc_init(void)
 {
-#if defined(pic18f23k22) || defined(pic18f24k22) || defined(pic18f25k22) || defined(pic18f26k22)
+#if defined(pic18f23k22) || defined(pic18f24k22) || defined(pic18f25k22) || defined(pic18f26k22) || \
+     defined(_18F23K22)  || defined(_18F24K22)  || defined(_18F25K22)  || defined(_18F26K22)
+
     ANSELA = AN_A_VAL;
     ANSELB = AN_B_VAL;
     ANSELC = AN_C_VAL;
 #endif
-#if defined(pic18f23k20) || defined(pic18f24k20) || defined(pic18f25k20) || defined(pic18f26k20)
+#if defined(pic18f23k20) || defined(pic18f24k20) || defined(pic18f25k20) || defined(pic18f26k20) || \
+      defined(_18F23K20)  || defined(_18F24K20)  || defined(_18F25K20)  || defined(_18F26K20)
+
     ANSEL=  _ADC_INITF;
     ANSELH = _ADCH_INITF;
 #endif
-#if defined(pic18f43k20) || defined(pic18f44k20) || defined(pic18f45k20) || defined(pic18f46k20)
+#if defined(pic18f43k20) || defined(pic18f44k20) || defined(pic18f45k20) || defined(pic18f46k20) || \
+    defined(_18F43K20)  || defined(_18F44K20)  || defined(_18F45K20)  || defined(_18F46K20)
     ANSEL = 0x00;
     ANSELH = 0x00;
     ANSELbits._ADC_INITF = 1;
@@ -49,89 +54,21 @@ void intadc_init(void)
 }
 
 
-#if 0
-void startadc(unsigned char ch)
-{
-    unsigned char a;
-    ADCON1bits.VCFG1 = 0;
-    ADCON1bits.VCFG0 = 0;
-    ADCON2 = 0b10110110;
-    a = 0b00000001; // Select AN7, Start.
-    switch(ch){
-        case 0:
-            a |= 0b00011100; // AN7
-            break;
-        default:
-            a |= 0b00011100; // AN7
-            break;
-    }
-    ADCON0 = a;
-    // Delay = 5uS + Tc + (tempalature - 25) * 0.05uS
-//    delay10tcy(8); // Tc = -13.5pF*(1K + 700 + (13K//39K)) = 1.52uS
-    // Wait < 1.52 + 5 + 1.25 = 7.77uS-> 8uS
-    PIR1bits.ADIF = 0;
-    PIE1bits.ADIE = 0;
-    IPR1bits.ADIP = 1; // High
-    ADCON0bits.GO_NOT_DONE = 1;
-}
 
 unsigned int polladc(void)
 {
     unsigned int a;
-    if(ADCON0bits.DONE == 1){ // converting or not enable.
-        PIE1bits.ADIE = 1;
-        PIR1bits.ADIF = 0;
-        return 0xffff;
-    } else { // Done, Clear interrupt
-//     if(ADCON0bits.ADON == 0){
-//         a = 0xffff;
-//     } else {
-        a = ((ADRESH << 8)  + ADRESL) & 0x03ff;
-//     }
-     PIE1bits.ADIE = 0;
-     PIR1bits.ADIF = 0;
-//     ADCON0bits.GO_NOT_DONE = 0;
-//        ADCON0bits.ADON = 0;
-        return a;
-    }
-}
-
-unsigned int polladc2(void)
-{
-    unsigned int a = 0;
-    do {
-        delay10tcy(8); // 10uS
-        a = ((ADRESH << 8)  + ADRESL) & 0x03ff;
-    } while(ADCON0bits.DONE);
-    return a;
-}
-
-void stopadc(void)
-{
-    ADCON0bits.GO_NOT_DONE = 0;
-//    ADCON0bits.ADON = 0;
-    PIR1bits.ADIF = 0;
     PIE1bits.ADIE = 0;
-}
-#else // Using sdcc's library.
-
-unsigned int polladc(void)
-{
-    unsigned int a;
+    PIR1bits.ADIF = 0;
     if(ADCON0bits.DONE){ // converting or not enable.
-        PIE1bits.ADIE = 1;
-        PIR1bits.ADIF = 0;
         return 0xffff;
     } else { // Done, Clear interrupt
         a = ((ADRESH << 8)  + ADRESL) & 0x03ff;
-     PIE1bits.ADIE = 0;
-     PIR1bits.ADIF = 0;
      ADCON0bits.GO_DONE = 0;
      return a;
     }
 }
 
-#endif
 
 unsigned int adc_rawtobatt(unsigned int b, unsigned int reflevel)
 {