Jump to content
43oh

RTC to I2C LCD Working on TM4C123 / LM4F120


Recommended Posts

Just been able to get an RTC output on an I2C LCD working on a TM4C123.

Using this RTC Library which I understand uses the chips built in RTC/hibernate function

and this I2C LCD Library, which seems to only like I2C(3)


// Core library for code-sense - IDE-based
#if defined(WIRING) // Wiring specific
#   include "Wiring.h"
#elif defined(ENERGIA) // LaunchPad specific
#   include "Energia.h"
#else // error
#   error Platform not defined
#endif // end IDE

// Include application, user and local libraries
// The time library provides all the tools.
// No need for reinventing them!
#include "time.h"
#define CEST 2*60*60

#include "DateTimeLibrary.h"


const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
//LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x27 for a 16 character, 2 line display

// Prototypes
char * datestamp = __DATE__;
char * timestamp = __TIME__;

// Define variables and constants
time_t myEpochRTC;
tm myTimeRTC;

DateTime myRTC;


// Add setup code
void setup()
{
    Wire.begin(3);
    Wire.setModule(3);
    lcd.init();                      // initialize the lcd
    Serial.begin(9600);
    delay(300);
    
    myRTC.begin();
    myRTC.setTimeZone(tz_GMT);

    Serial.print("*** datestamp = ");
    Serial.println(datestamp);
    Serial.print("*** timestamp = ");
    Serial.println(timestamp);
    
    // Fri, 31 Jul 2015 20:41:48 GMT
    myEpochRTC = 946743570;
    
    // Set time to RTC, only once
    myRTC.setTime(myEpochRTC);
    Serial.print("Set RTC = ");
    Serial.println(myEpochRTC, DEC);
    
    myEpochRTC = 0;
}

// Add loop code
void loop()
{
    lcd.backlight();
    lcd.setCursor(0,0);
    lcd.print("Session time:");
    // Local time zone
    myEpochRTC = myRTC.getLocalTime();
    lcd.setCursor(0,1);
    //lcd.print(stringDateTime(myEpochRTC));
    // Even more flexible output!
    // see http://www.cplusplus.com/reference/ctime/strftime/
    convertEpoch2Structure(myEpochRTC, myTimeRTC);
    lcd.print(stringFormatDateTime("%I:%M:%S %p.", myTimeRTC));
    delay(100);
}

post-35889-0-28183800-1443523532_thumb.jpg

 

Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...