//********************************************************************** /*   『簡易高抵抗測定器(High Resistance Meter)』 */ //********************************************************************** #define SW PORTA.F5 //********************************************************************** void main() { static unsigned char buf[20]; static unsigned int cnt; static double v1, v2, ohm, offset; // OSCCON = 0b01110000; // クロックは8Mhz CMCON = 0b00000111; // コンパレータは使用しない。 // A/D変換を使用する。 ANSEL = 0b000000011; ADCON1.VCFG1 = 1; ADCON1.VCFG0 = 0; // ポートを初期化する。 TRISA = 0b11111111; TRISB = 0b00000000; // LCDを初期化する。 Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTB,3,2,1); Lcd_Custom_Cmd(LCD_CURSOR_OFF); Lcd_Custom_Cmd(LCD_CLEAR); Lcd_Custom_Out(1, 1, "Resistance Meter"); Delay_ms(1000); Lcd_Custom_Cmd(LCD_CLEAR); Lcd_Custom_Chr(1, 12, 0xF4); Lcd_Custom_Out(2, 6, "mV"); Lcd_Custom_Out(2, 14, "mV"); // offset = 1.0; // while (1) { //非測定抵抗の入力電圧(V1)を測定します。 v1 = 0.0; for (cnt = 0; cnt < 5000; cnt++) { v1 += Adc_Read(0); } v1 = (v1 / 5000.0) * 2.44140625; WordToStr(v1, buf); Lcd_Custom_Out(2, 1, buf); // //非測定抵抗の出力電圧(V2)を測定します。 v2 = 0.0; for (cnt = 0; cnt < 5000; cnt++) { v2 += Adc_Read(1); } v2 = (v2 / 5000.0) * 2.44140625; // if (SW == 0) { offset = v1 / v2; // WordToStr(v2, buf); Lcd_Custom_Out(2, 9, buf); LongToStr(offset * 1000000, buf); buf[0] = buf[1]; buf[1] = buf[2]; buf[2] = buf[3]; buf[3] = buf[4]; buf[4] = '.'; Lcd_Custom_Out(1, 1, buf); Lcd_Custom_Chr(1, 12, '%'); // Lcd_Custom_Chr(1, 16, '*'); Delay_ms(100); Lcd_Custom_Chr(1, 16, ' '); Delay_ms(100); continue; } v2 = v2 * offset; WordToStr(v2, buf); Lcd_Custom_Out(2, 9, buf); //非測定抵抗の抵抗値を求めます。 ohm = (v1 - v2) / (v2 / 9800000); //基準となる抵抗の実測値を設定し精度を上げます。 //各値を表示します。 LongToStr(ohm, buf); Lcd_Custom_Out(1, 1, buf); Lcd_Custom_Chr(1, 12, 0xF4); } } //**********************************************************************