//********************************************************************** /*   『低抵抗測定器』 */ //********************************************************************** #define SW1 PORTA.F5 #define SW2 PORTA.F4 #define LED PORTB.F0 //********************************************************************** void main() { static unsigned char buf[20]; static unsigned int cnt; static double ad, offset; // OSCCON = 0b01110000; // クロックは8Mhz CMCON = 0b00000111; // コンパレータは使用しない。 // A/D変換を使用する。 ANSEL = 0b00000100; 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_Chr(1, 6, 'm'); Lcd_Custom_Chr(1, 7, 0xF4); Lcd_Custom_Out(2, 6, "uV"); Lcd_Custom_Out(2, 14, "uV"); // offset = 0.0; LED = 0; // while (1) { //電圧の測定 ad = 0.0; for (cnt = 0; cnt < 1000; cnt++) { ad += Adc_Read(2); Delay_us(500); } ad = ad / 1000.0; if (ad > 1020.0) { Lcd_Custom_Out(1, 11, "error!"); Delay_ms(100); Lcd_Custom_Out(1, 11, " "); continue; } //レンジ切替 if (SW2 == 1) { ad = ((ad * 2.44140625) / 101.0) * 1000; } else { ad = ((ad * 2.44140625) / 11.0) * 1000; } //電圧の表示 WordToStr(ad, buf); Lcd_Custom_Out(2, 1, buf); //SW1がONであれば、測定電圧は、オフセット値とする。 if (SW1 == 0) { offset = ad; WordToStr(ad, buf); Lcd_Custom_Out(2, 9, buf); } //抵抗値を計算し表示する。 ad = (ad - offset) / 123.0; //123.0は定電流の値です。 WordToStr(ad, buf); Lcd_Custom_Out(1, 1, buf); // LED = 1; Delay_ms(100); LED = 0; Delay_ms(100); } } //**********************************************************************