Real time clock on LC60

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Real time clock on LC60

2,915 Views
birdbird
Contributor I
Hello i m a total noobie in programming and i need to initialise a real time clock that counts the time and date and display it on the LC60 demo kit. I am told to use the IRQ function in the LC60. Anybody knows how to do that?
Labels (1)
0 Kudos
8 Replies

796 Views
little_egg_tart
Contributor I

Hello!

 

I found this thread by chance. I myself have to do the same thing in school as a project. 

I have no clue how to implement it too. Do you know how to do it?

 

Regards, little.eggtart.

0 Kudos

796 Views
OmarAI
Contributor I

birdbird, I'm going to be honest with you. The code you showed me don't mean that much to me. The thing is that first of all you have to know C language (there's a lot of information about it on the internet). The next thing to do is read the DS1338C datasheet (http://datasheets.maxim-ic.com/en/ds/DS1338-DS1338Z.pdf). If you start reading from page 8, you will find all the information you need to work with the clock. As for the LCD screen (http://www.softbaugh.com/downloads/SBLCDA2_Specification.pdf) it looks like it has a dedicated pin for each segment, so all you need to do is access the right port (depends on how it is connected to your MCU, something similar to driving 7 segment led dispalys).

 

I can tell you this :

 

********* Looks like the code needed to start de RTC*********

 

void IICRTC_InitWrite (void){ //to initialize RTC sets at 8.40am wed
byte i;

while(IICS_BUSY);       // Wait till bus is free
  IICC_TX = 1;         // Transmit Mode
   IICC_MST = 1;        // Send start bit
   IICD = 0b11010000;   // Transmit slave address
   for (i=0; i<5; i++); // Delay
  
   while(IICS_TCF==0);  // Wait till transfer is complete
   for (i=0; i<5; i++); // Delay
   IICD= 0x00;          // Transmit word address

 

******** look at the comments on the right, they tell you what each line does **********

 

********the next lines seem to fill the registers with the information you want (hour. date...)***

 

for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 00h data (Seconds)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 01h data (Minutes)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 02h data (Hour)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 03h data  (Day??)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 04h data (watchdog/alarm registers unused)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 05h data (watchdog/alarm registers unused)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 06h data (watchdog/alarm registers unused)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x10;          // Transmit 07h data (set oscillator enable, 1Hz sq. wave output, diable all alarms)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 08h data
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0xAA;          // Transmit 09h data    (Trickle charger circuit, set 1 diode 2kOhm resistor)

 

   for(i=0; i<5; i++);  // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICC_MST=0;          // Generate stop signal    
}

 

*** where it says 0xh it means that you are filling register x and the number is in hexadecimal

*** format, and if you look at the DS1338 datasheet, each register is specified as in page 10, table 3

 

***the rest of the code do what the comments on the right say they do and the function name is important too

 

void IICRTC_Clear_Flag (void)
{
 byte i;  
      
   while(IICS_BUSY) ;   // Wait till bus is free
 
   IICC_TX = 1;         // Transmit Mode
   IICC_MST = 1;        // Send start bit
   IICD = 0b11010000;   // Transmit slave address
     
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
  
   for (i=0; i<5; i++); // Delay
   IICD= 0x0F;          // Transmit word address (SPR)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x48;          // Transmit 0Fh data
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICC_MST=0;          // Generate stop signal    
}

void IICRTC_set_Pointer_00h(void) //sets the pointer to a register to start reading, for example 01h for minutes.
{
   byte i;
      
   while(!IICS_TCF) ;   // Wait till transfer is complete
 
   IICC_TX = 1;         // Transmit Mode
   IICC_MST = 1;        // Send start bit
   IICD = 0b11010000;   // Transmit slave address
     
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
  
   for (i=0; i<5; i++); // Delay
   IICD= 0x00;          // Transmit word address 
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICC_MST=0;          // Generate stop signal      
}

 

What you have to have in mind is that I have no idea about the LC60 IIC interface or the RTC you use. I've jus interpreted the information that the one who wrote the code commented (it's something usefull to do that as in the future you won't remember everything you did at the time you wrote the code). 

I know that you wanted something more specific, but I can't help you. You need to find someone that had actually used the RTC you specify and the LCD too and if the mcu is the same one or similar, you are so lucky... But for the moment, my recomendation is to read the RTC datasheet (it explains everything you need to know about I2C to start using the RTC) and the IIC interface (I2C) section of your mcu datasheet. Once you think that the RTC is working (sending an receiving information through IIC), start looking for information on how to drive the LCD screen and some example code might help.

 

Take into account that 0xXX is hexadecimal notation as xxh. Knowing C language is mandatory if you try to do something like the code you showed before.

 

Regards.

0 Kudos

796 Views
birdbird
Contributor I
Hey thanks alot for your time helping to interpret the codes. Helped out alot.
0 Kudos

796 Views
OmarAI
Contributor I
Something I didn't tell you about the project in which I used the RTC is that all the bytes sequences to start and read the RTC are stored in the software that is installed on the computer, so our mcu basically translates the information it receives from the USB interface, that's also why my code is useless to you.
 
I'm interested in this sentence you wrote:
 
"I am told to use the IRQ function in the LC60" Are you sure you have an external RTC? IRQ is an interruption request you make to the cpu and is what the RTI (included in the LC60) does, based on a real time scale (seconds or milliseconds or...) and that's why you can use it as a time base for the RTC. If that is your task...you have to write software to count "real time" (seconds or minutes or hours, depends on how many register variables you are planning to use) and take a real calendar and start writing "if the register that stores the count reaches x time, then...” I think that the advantage of the LC60 is that you don't have errors in the counts because for other mcus you have to use the bus clock (or a multiple of it) and you always have an error when you try to count if the clock isn't a submultiple of a second.
Message Edited by OmarAI on 2009-06-22 01:47 AM
Message Edited by OmarAI on 2009-06-22 01:48 AM
0 Kudos

796 Views
OmarAI
Contributor I

Well, there are a lot of possibilities involved. For example, depending on which LCD screen or which RTC you use (different interfaces). If you are a total stranger to any written code (never wrote anything)...it isn't a good idea starting with this task. If you have some experience you just have to give it time to understand it. Having said that, if you have already chosen the RTC look at its datasheet for information about its interface (usually sci or I2C o SPI). Then, take a look at your mcu datasheet and find where it talks about the interface that the RTC uses. First of all write some code to start that interface (some examples or reference designs might help). Once you are certain that it's running as it should, read the RTC datasheet and find what it needs to start running (counting time). Generally, the datasheet will give you a list of the registers involved and which bit (in each register) and in what order they have to be received by the RTC. Those bits and bytes have to be sent via the interface chosen before (here is where your knowledge about the interface driven by the mcu has to be good enough, so be certain of what you are doing). The RTC will send back some data (hour, min, sec, date...) and that data will be stored in the mcu buffers corresponding to the interface we've been talking so far. Once you managed to get data from the RTC, the process is the same for everything you need to know (send some bytes asking for information and receiving what you want). The RTC will respond to almost everything you need if the bytes sent are the correct ones, so take your time and read its datasheet carefully. For the LCD the process is the same one...look for its datasheet, find its interface and the corresponding one in the mcu datasheet. Understand how to use that interface and start writing and receiving. Take into account that the RTC and the LCD are, generally, "slaves" to your mcu, so they will respond but rarely ask for something.
 
An example: the mcu I used was the HC908JB16. First, a friend and I wrote a code for the USB interface. Once that started working, and as that mcu has no I2C interface, we wrote a code to simulate an embedded one (bit-banging). Once we checked with and oscilloscope that the interface was working well, we connected the RTC (ISL120XX, from intersil semiconductors). After that, we just had to write some bytes and the clock started running. Our LCD screen was a PCD8544 driven one, so we looked at its datasheet and add some code to our I2C interface, as the one it uses is a special "serial" interface. The data gathered from the I2C interface with information from the RTC is then transferred to the other interface and received by the LCD, which shows what you need.
Everything I said is very basic. If you list the parts involved in your project, maybe I can really help you, because there are a lot of types and interfaces and there’s no general rule in almost anything you have to do. That’s why your mcu has a lot of interfaces and options that you may not use once your project is finished. Each mcu has its own registers (so my code won’t help you in anything at all, for example) and each device (LCD, RTC, temperature sensor,…) is different, depending on the company that makes it (different registers, methods and interfaces or even electrical characteristics). The exceptions are those common and legendary components that various companies make (LM555, LM317,…).

 

Sorry for the gramatical and spelling mistakes...I've wrote as fast as i could.

Hope this info gets you started. Remember to post the components you use (RTC and LCD driver).

Regards.

Message Edited by OmarAI on 2009-06-21 09:16 PM
0 Kudos

796 Views
birdbird
Contributor I

The RTC that i am using is the DS1338C and the lcd that i am using is SBLCDA2. So far i have found some codes that seems related to my RTC but dun really understand it. Can u explain it for me? Anw the interface of the RTC is I2C and these are the codes. Really appreciate your help. THks

 

void IICRTC_InitWrite (void){ //to initialize RTC sets at 8.40am wed
byte i;

while(IICS_BUSY);       // Wait till bus is free
  IICC_TX = 1;         // Transmit Mode
   IICC_MST = 1;        // Send start bit
   IICD = 0b11010000;   // Transmit slave address
   for (i=0; i<5; i++); // Delay
  
   while(IICS_TCF==0);  // Wait till transfer is complete
   for (i=0; i<5; i++); // Delay
   IICD= 0x00;          // Transmit word address

 

Really appreciate your help. THks
   
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 00h data (Seconds)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 01h data (Minutes)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 02h data (Hour)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 03h data  (Day??)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 04h data (watchdog/alarm registers unused)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 05h data (watchdog/alarm registers unused)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 06h data (watchdog/alarm registers unused)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x10;          // Transmit 07h data (set oscillator enable, 1Hz sq. wave output, diable all alarms)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x00;          // Transmit 08h data
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0xAA;          // Transmit 09h data    (Trickle charger circuit, set 1 diode 2kOhm resistor)
  
   for(i=0; i<5; i++);  // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICC_MST=0;          // Generate stop signal    
}


void IICRTC_Clear_Flag (void)
{
 byte i;  
      
   while(IICS_BUSY) ;   // Wait till bus is free
 
   IICC_TX = 1;         // Transmit Mode
   IICC_MST = 1;        // Send start bit
   IICD = 0b11010000;   // Transmit slave address
     
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
  
   for (i=0; i<5; i++); // Delay
   IICD= 0x0F;          // Transmit word address (SPR)
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICD= 0x48;          // Transmit 0Fh data
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICC_MST=0;          // Generate stop signal    
}

void IICRTC_set_Pointer_00h(void)
{
   byte i;
      
   while(!IICS_TCF) ;   // Wait till transfer is complete
 
   IICC_TX = 1;         // Transmit Mode
   IICC_MST = 1;        // Send start bit
   IICD = 0b11010000;   // Transmit slave address
     
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
  
   for (i=0; i<5; i++); // Delay
   IICD= 0x00;          // Transmit word address 
  
   for (i=0; i<5; i++); // Delay
   while(IICS_TCF==0);  // Wait till transfer is complete
   IICC_MST=0;          // Generate stop signal      
}

0 Kudos

796 Views
OmarAI
Contributor I

I've never used any HCS08 microcontroller and I have no idea what can be done with them. I've been using the HC908 (HC08) ones that look like a simpler version with less capabilities or futures. This doesn't mean that what Im going to tell you is useless, it depends... For a HC908 that has no RTI (real-time interrupt) the only reasonable way to have a RTC is to use an external one (as I did and it is very simple...just some interface information needed and the rest is gathering data and displaying it on an LCD screen (parallel or serial). Making assumptions (that is to say that I haven't spent a lot of time reading the LC60 datasheet) and based on the next phrase extracted from it's datasheet:

 

"Software-generated real-time clock (RTC) functions using real-time interrupt (RTI)"

 

I think that you should write something like a software calendar calculating every second or minute or day (depends on registers size and memory options) using interrupts and look for some "function" (y=f(x)) that can let you keep your software small enough and have a full calendar. I think that if you browse a little there should be some information about it. On the other hand, if an external RTC is an option, they come with a variety of options and with many features like battery check, alarms and temperature sensors. If you want more information about them I can help get started.

 

Regards.

Message Edited by OmarAI on 2009-06-21 05:07 AM
0 Kudos

796 Views
birdbird
Contributor I
hey thks for replying. Anw i am using an external RTC. Can you show me an example how to get started as i totally have no idea on how to start on the codes and display the time onto the LCD screen. Thks alot!
0 Kudos