// Volt meter Test
// 10/03/2012 Friday
// Satya Ranjan Sarkar
// -----------------------------------------------------------------------------
//Display volt variable -------------------------------------------------------
unsigned int adc_volts1;
unsigned int volts1;
unsigned int adc_volts2;
unsigned int volts2;
unsigned int adc_volts3;
unsigned int volts3;
unsigned int adc_volts4;
unsigned int volts4;
char txt[8]; // used to display number string
//Display Name text variable ---------------------------------------------------
// wrap delay as a function call to save code size -----------------------------
void delay_500ms(void)
{
Delay_mS(500); // this value gives about 500ms per "pulse"
}
void main ()
{
TRISA = 0xFF; // All Input
TRISB = 0b00000000; // input & output
TRISC = 0b00000000; // All output
PORTB = 0x00; // PortB Clear
PORTC = 0x00; // PortC Clear
ADCON1=0X80; // all input are analog
delay_500ms(); // small delay for PSU to stabilise
Lcd_Init(&PORTB); // Initialize LCD connected to PORTB
Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
delay_500ms();
//Start loop here---------------------------------------------------------------
while(1)
{
adc_volts1 = ADC_Read(1); // read Batt Volt AD
delay_500ms();
volts1 = (adc_volts1 * 12); // 10 to 25 volts 12 to 30 volts 15 to 38 volts
wordtostr(volts1,txt); // format voltage int to text
txt[5] = txt[4]; // move 2 decimal places
txt[4] = txt[3];
txt[3] = '.'; // add dec point
txt[6] = 'V'; // add volts
txt[7] = 0; // and add NULL
Lcd_Out(1,1,txt); // display battery volt
delay_500ms();
adc_volts = ADC_Read(2); // read Batt Volt AD
delay_500ms();
volts2 = (adc_volts2 * 12); // 10 to 25 volts 12 to 30 volts 15 to 38 volts
wordtostr(volts2,txt); // format voltage int to text
txt[5] = txt[4]; // move 2 decimal places
txt[4] = txt[3];
txt[3] = '.'; // add dec point
txt[6] = 'V'; // add volts
txt[7] = 0; // and add NULL
Lcd_Out(1,8,txt); // display battery volt
delay_500ms();
adc_volts3 = ADC_Read(3); // read Batt Volt AD
delay_500ms();
volts3 = (adc_volts3 * 12); // 10 to 25 volts 12 to 30 volts 15 to 38 volts
wordtostr(volts3,txt); // format voltage int to text
txt[5] = txt[4]; // move 2 decimal places
txt[4] = txt[3];
txt[3] = '.'; // add dec point
txt[6] = 'V'; // add volts
txt[7] = 0; // and add NULL
Lcd_Out(2,1,txt); // display battery volt
delay_500ms();
adc_volts4 = ADC_Read(2); // read Batt Volt AD
delay_500ms();
volts4 = (adc_volts4 * 12); // 10 to 25 volts 12 to 30 volts 15 to 38 volts
wordtostr(volts4,txt); // format voltage int to text
txt[5] = txt[4]; // move 2 decimal places
txt[4] = txt[3];
txt[3] = '.'; // add dec point
txt[6] = 'V'; // add volts
txt[7] = 0; // and add NULL
Lcd_Out(2,8,txt); // display battery volt
}
}
// 10/03/2012 Friday
// Satya Ranjan Sarkar
// -----------------------------------------------------------------------------
//Display volt variable -------------------------------------------------------
unsigned int adc_volts1;
unsigned int volts1;
unsigned int adc_volts2;
unsigned int volts2;
unsigned int adc_volts3;
unsigned int volts3;
unsigned int adc_volts4;
unsigned int volts4;
char txt[8]; // used to display number string
//Display Name text variable ---------------------------------------------------
// wrap delay as a function call to save code size -----------------------------
void delay_500ms(void)
{
Delay_mS(500); // this value gives about 500ms per "pulse"
}
void main ()
{
TRISA = 0xFF; // All Input
TRISB = 0b00000000; // input & output
TRISC = 0b00000000; // All output
PORTB = 0x00; // PortB Clear
PORTC = 0x00; // PortC Clear
ADCON1=0X80; // all input are analog
delay_500ms(); // small delay for PSU to stabilise
Lcd_Init(&PORTB); // Initialize LCD connected to PORTB
Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
delay_500ms();
//Start loop here---------------------------------------------------------------
while(1)
{
adc_volts1 = ADC_Read(1); // read Batt Volt AD
delay_500ms();
volts1 = (adc_volts1 * 12); // 10 to 25 volts 12 to 30 volts 15 to 38 volts
wordtostr(volts1,txt); // format voltage int to text
txt[5] = txt[4]; // move 2 decimal places
txt[4] = txt[3];
txt[3] = '.'; // add dec point
txt[6] = 'V'; // add volts
txt[7] = 0; // and add NULL
Lcd_Out(1,1,txt); // display battery volt
delay_500ms();
adc_volts = ADC_Read(2); // read Batt Volt AD
delay_500ms();
volts2 = (adc_volts2 * 12); // 10 to 25 volts 12 to 30 volts 15 to 38 volts
wordtostr(volts2,txt); // format voltage int to text
txt[5] = txt[4]; // move 2 decimal places
txt[4] = txt[3];
txt[3] = '.'; // add dec point
txt[6] = 'V'; // add volts
txt[7] = 0; // and add NULL
Lcd_Out(1,8,txt); // display battery volt
delay_500ms();
adc_volts3 = ADC_Read(3); // read Batt Volt AD
delay_500ms();
volts3 = (adc_volts3 * 12); // 10 to 25 volts 12 to 30 volts 15 to 38 volts
wordtostr(volts3,txt); // format voltage int to text
txt[5] = txt[4]; // move 2 decimal places
txt[4] = txt[3];
txt[3] = '.'; // add dec point
txt[6] = 'V'; // add volts
txt[7] = 0; // and add NULL
Lcd_Out(2,1,txt); // display battery volt
delay_500ms();
adc_volts4 = ADC_Read(2); // read Batt Volt AD
delay_500ms();
volts4 = (adc_volts4 * 12); // 10 to 25 volts 12 to 30 volts 15 to 38 volts
wordtostr(volts4,txt); // format voltage int to text
txt[5] = txt[4]; // move 2 decimal places
txt[4] = txt[3];
txt[3] = '.'; // add dec point
txt[6] = 'V'; // add volts
txt[7] = 0; // and add NULL
Lcd_Out(2,8,txt); // display battery volt
}
}
No comments:
Post a Comment