Generic Multi Function Meter |
Multi Tester (V, I, F, R)
Copyright (C) 2015 Scorpionz
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.
>> Email: scorpionzblog@gmail.com
>> Blog : scopionz.blogspot.com
***************************************************************************/
int v_in, i_in, r_in;
unsigned f_in;
char *vin = "V=00.0v I=00.00A";
char *fin = "F=00,000Hz 00%";
void main()
{
OSCCON = 0x70; //8MHz
ANSEL = 0x07; // AN0, AN1
T1CON = 0x0A; //1:1
OPTION_REG = 0x80; //WPUB
TRISA = 0x07;
TRISB = 0x40;
PORTA = 0;
PORTB = 0;
Sound_Init(&PORTA, 6);
Lcd_Config(&PORTB, 0, 1, 7, 5, 4, 3, 2);
delay_ms(10);
Lcd_Cmd(LCD_CURSOR_OFF);
Lcd_Out(1, 3, ".:SCORPIONZ:.");
Lcd_Out(2, 1, "Lab Multi Tester");
delay_ms(2000);
Lcd_Cmd(Lcd_Clear);
while(1) {
TMR1H=0;
TMR1L=0;
T1CON.TMR1ON=1;
Delay_ms(1000); // Wait for 1 sec
T1CON.TMR1ON=0;
f_in = 256*TMR1H+TMR1L;
v_in = Adc_Read(0);
i_in = Adc_Read(1);
r_in = Adc_Read(2);
if(v_in>1020 || i_in>1000) PORTA.F3=0;
else PORTA.F3=1;
v_in = v_in/2.05;
vin[2] = (v_in/100)%10 + 48;
vin[3] = (v_in/10) %10 + 48;
vin[5] = (v_in%10) + 48;
i_in = i_in/.2;
vin[10] = (i_in/1000)%10+ 48;
vin[11] = (i_in/100) %10+ 48;
vin[13] = (i_in/10) %10+ 48;
vin[14] = (i_in%10) + 48;
fin[2] = (f_in/10000)%10+ 48;
fin[3] = (f_in/1000)%10 + 48;
fin[5] = (f_in/100) %10 + 48;
fin[6] = (f_in/10) %10 + 48;
fin[7] = (f_in%10) + 48;
r_in = r_in/.205;
r_in = (4790/r_in);
if(r_in) Sound_Play(r_in*30, 100);
fin[13] = (r_in/10) %10 + 48;
fin[14] = (r_in%10) + 48;
Lcd_Out(1,1,vin);
Lcd_Out(2,1,fin);
}
}