void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // P1.0 output
CACTL2 = P2CA4; // P1.1 = CA1
while (1) // Mainloop
{
Batt_Check();
}
}
void Batt_Check(void) {
CACTL1 = CAREF_1 + CAON; // 0.25*Vcc on P1.1, Comp. on
i = 16384; // delay
while(i>0) {
i--;
}
CACTL1 = CARSEL + CAREF_2 + CAREF_1 + CAON; // 0.55V on -, Comp. on
if (CACTL2 & CAOUT)
P1OUT ^= 0x01; // P1.0 toggle
else P1OUT |= 0x01; // P1.0 set
CACTL1 = 0x00; // Disable Comp_A, save power
} |