//********************************************************************** /* <照度計> */ //********************************************************************** unsigned int measurement(unsigned short channel) { unsigned int ad, cnt; // ad = 0; for (cnt = 0; cnt < 50; cnt++) { ad += Adc_Read(channel); } return (ad); } //********************************************************************** void main() { static unsigned char buf[6]; static unsigned int ad; static double tmp; // OSCCON = 0b01110000; // クロックは8Mhz CMCON = 0b00000111; // コンパレータは使用しない。 // A/D変換を使用する。 ANSEL = 0b00010100; ADCON1.VCFG1 = 1; ADCON1.VCFG0 = 0; // ポートを初期化する。 TRISA = 0b10111100; TRISB = 0b00001111; // LCDを初期化する。 Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTA,6,0,1); Lcd_Custom_Cmd(LCD_CURSOR_OFF); Lcd_Custom_Cmd(LCD_CLEAR); // while (1) { ad = measurement(2); tmp = ((double)ad * 2.44140625) / 50.0; // if (tmp < 2000) { WordToStr(tmp, buf); Lcd_Custom_Out(1, 1, buf); Lcd_Custom_Out(1, 6, "mV"); // WordToStr(tmp / (11.0 * 0.033), buf); Lcd_Custom_Out(2, 1, buf); Lcd_Custom_Out(2, 6, "Lux"); } else { ad = measurement(4); tmp = ((double)ad * 2.44140625) / 50.0; // WordToStr(tmp, buf); Lcd_Custom_Out(1, 1, buf); Lcd_Custom_Out(1, 6, "mV"); // WordToStr(tmp / 0.033, buf); Lcd_Custom_Out(2, 1, buf); Lcd_Custom_Out(2, 6, "Lux"); } Delay_ms(500); } } //**********************************************************************