RTC Module (Part 3)

Part 1234567

Now that we have the hardware and the routines and functions ready, let’s apply them to a simple application. This one will print “tic”, wait half a second, print “tac” followed by the second index. (Real nutty stuff :-[)

void loop() {
	int  pinState = ((PINB >> oneHertzPin) & 0x01);
	if (lastPinState != pinState) {
		if (pinState) {
			Serial.print("tic ");
		}
		else {
			Serial.print ("tac ");		
			byte result = bcdTobin(rtc_readRegister(0x00));
			Serial.println(result, DEC);
			}
	}
	lastPinState = pinState;
	delay(10);
}

Note: As the data is stored in BCD, I am using simple converters, namely bcdTobin and bcdTobcd

byte binTobcd (byte binValue) {
	return (((binValue / 10) << 4) | (binValue % 10));
}

byte bcdTobin (byte bcdValue) {
	return ((((bcdValue >> 4) & 0x0F) * 10) + (bcdValue & 0x0F));
}

The loop routine contains a level sensor attached to the 1 hertz signal input. Every change triggers a specific action which “tics” and “tacs” time. Second index is read on “tacs”. Just like this:

Coming next: time setting, stand alone clock application

Leave a Reply

You must be logged in to post a comment.