Datasheet

LTC2485
37
2485fc
APPLICATIONS INFORMATION
/*** main() ********************************************************************
Main program initializes microcontroller registers, then reads the LTC2481
repeatedly
*******************************************************************************/
void main()
{
signed int32 x, y; // Integer result from LTC2481
oat voltage; // Variable for oating point math
int16 timeout;
initialize(); // Hardware initialization
while(1)
{
delay_ms(1); // Pace the main loop to something more than 1 ms
// This is a basic error detection scheme. The LTC2485 will never take more than
// 163.5ms, 149.9ms, or 136.5ms to complete a conversion in the 50Hz, 55Hz, and 60Hz
// rejection modes, respectively.
// If read_LTC2485() does not return non-zero within this time period, something
// is wrong, such as an incorrect i2c address or bus con ict.
if((x = read_LTC2485(LTC248XADDR, VIN | R50 | SLOW)) != 0)
{
// No timeout, everything is okay
timeout = 0; // reset timer
x ^= 0x80000000; // Invert MSB, result is 2’s complement
voltage = ( oat) x; // convert to oat
voltage = voltage * 5.0 / 2147483648.0;// Multiply by Vref, divide by 2^31
lcd_putc(‘\f’); // Clear screen
lcd_gotoxy(1,1); // Goto home position
printf(lcd_putc, “%01.6f”, voltage); // Display voltage
}
else
{
++timeout;
}
if(timeout > 200)
{
timeout = 200; // Prevent rollover
lcd_gotoxy(1,1);
printf(lcd_putc, “ERROR - TIMEOUT”);
delay_ms(500);
}
} // End of main loop
} // End of main()