Datasheet
LTC2481
37
2481fc
APPLICATIONS INFORMATION
lcd_init(); // Initialize LCD
delay_ms(6);
printf(lcd_putc, “Hello!”); // Obligatory hello message
delay_ms(500); // for half a second
} // End of initialize()
*** main() ********************************************************************
Main program initializes microcontroller registers, then reads the LTC2481
repeatedly
*******************************************************************************/
void main()
{
signed int32 x; // Integer result from LTC2481
fl oat voltage; // Variable for fl 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 LTC248X 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_LTC248X() does not return non-zero within this time period, something
// is wrong, such as an incorrect i2c address or bus confl ict.
if((x = read_LTC2481(LTC248XADDR, GAIN1 | VIN | R55)) != 0)
{
// No timeout, everything is okay
timeout = 0; // reset timer
x &= 0xFFFFFFC0; // clear confi g bits so they don’t affect math
x ^= 0x80000000; // Invert MSB, result is 2’s complement
voltage = (fl oat) x; // convert to fl 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, “V %01.4f”, 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()