Electronic – how to display current time

avrmicrocontroller

I am using ATmega32-A micro controller, coding in C language and compiling using CodeVisionAVR compiler.

I want to display current time, I have tried with "time.h":

int main(void){
 time_t now; 
 time(&now); 
 printf("(percent)s", ctime(&now)); 
}

but it seems this compiler and hardware won't support time.h. I know that all AVRs don't have a RTC/calendar in them.

Is there any other way to display current time. I am very new to programming micro controllers. Can any one help me with some examples.

I don't want to add external hardware to the existing board now. I am displaying information on the PC (hyperterminal) using USART communication. Is there any possibility that I can get current time from PC? if there can you explain about it a little bit?

Best Answer

No ATmega32 AVR has an RTC/calendar built into it AFAICS.

Assuming that the reference is to an external battery backed RTC on the AVR board, there isn't any source for the current time on a board without an RTC chip. At best, the bootloader you use with the microcontroller may keep data on many milliseconds have elapsed since the board was powered on - within the tolerance of the clock source and allowing for any occasional missed timer interrupts.

If you do have an RTC chip configured on the board, with the correct time set up on it, there might be a suitable RTC library for that chip. Such a library would typically provide hour(), minute(), second() and other time retrieval methods for your code to use.

The generic time.h C header does not ship with, and therefore is not supported by, AVRdude or Arduino, apparently.

There is a good tutorial on using AdaFruit's RTC breakout board, here.