chipKIT® Development Platform

Inspired by Arduino™

UECIDE error on RTC code

Created Mon, 28 Apr 2014 07:16:46 +0000 by ajitnayak


ajitnayak

Mon, 28 Apr 2014 07:16:46 +0000

Here i am trying to upload below code. I am getting below error . let me know what i need to do.

UECIDE v0.8.4.d version i am using[attachment=0]R3.JPG[/attachment][attachment=1]RTC error.JPG[/attachment]

#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527

byte decToBcd(byte val){
	// Convert normal decimal numbers to binary coded decimal
	return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val)  {
	// Convert binary coded decimal to normal decimal numbers
	return ( (val/16*10) + (val%16) );
}


void setDateTime(){

	byte second =  45; //0-59
	byte minute =11; //0-59
	byte hour = 10; //0-23
	byte weekDay =2; //1-7
	byte monthDay =23; //1-31
	byte month = 03; //1-12
	byte year  =       14; //0-99

	Wire.beginTransmission(DS1307_ADDRESS);
	Wire.send(zero); //stop Oscillator

	Wire.send(decToBcd(second));
	Wire.send(decToBcd(minute));
	Wire.send(decToBcd(hour));
	Wire.send(decToBcd(weekDay));
	Wire.send(decToBcd(monthDay));
	Wire.send(decToBcd(month));
	Wire.send(decToBcd(year));

	Wire.send(zero); //start

	Wire.endTransmission();

}



void printDate(){

	// Reset the register pointer
	Wire.beginTransmission(DS1307_ADDRESS);
	Wire.send(zero);
	Wire.endTransmission();

	Wire.requestFrom(DS1307_ADDRESS, 7);

	int second = bcdToDec(Wire.receive());
	int minute = bcdToDec(Wire.receive());
	int hour = bcdToDec(Wire.receive() & 0b111111); //24 hour time
	int weekDay = bcdToDec(Wire.receive()); //0-6 -> sunday - Saturday
	int monthDay = bcdToDec(Wire.receive());
	int month = bcdToDec(Wire.receive());
	int year = bcdToDec(Wire.receive());

	/*  int second = 11;
	 int minute =18;
	 int hour = 18;
	 int weekDay = 1;
	 int monthDay = 2;
	 int month = 11;
	 int year = 12;
	 */
	//print the date EG   3/1/11 23:59:59
	Serial.print(monthDay);
	Serial.print("/");


	Serial.print(month);
	Serial.print("/");

	Serial.print(year);
	Serial.print(" ");
	Serial.print(hour);
	Serial.print(":");
	Serial.print(minute);
	Serial.print(":");
	Serial.println(second);

	// Serial.print("Week Day Of week");
	//  Serial.println(weekDay);


}


void setup(){
	Wire.begin();
	Serial.begin(9600);
	setDateTime(); //MUST CONFIGURE IN FUNCTION
}

void loop(){
	printDate();
	delay(1000);
}