If you want to use a micro with in built RTC you can look here http://www.atmel.com/dyn/resources/prod_documents/doc1259.pdf
This application note describes how to implement a Real Time Clock (RTC) on
AVR® microcontrollers that features the RTC module. The implementation requires
only one discrete component – a 32.768 kHz watch crystal.
If you want to use external RTC, then you may use DS1307(without battery backup) or DS12887+(with inbuilt Li battery but costly!)
As you can see, STM32 using one 32-bit length register to store the time and one the same for calender. This routine calculate the real values from bcd-coded 32-bit register value. Hope it helps a little.
On 8-bit micro controllers i'm using few independent byte variables, organized in structure. Like this:
I am using PIC microcontroller
to build an interrupt which control an LED in traffic light using pwm
which adjust its brightness according to time ( peak time and offtime )
is it fairly simple to interface RTC with picmicro ?
It will be better to use light sensor (LDR or photo trinsistor, CDS etc) for traffic light. Apart from evening time the ambient light may get reduced due to cloud, heavy rain or Solar eclipse etc. They are small, inexpensive, low-power, easy to use and don't wear out. You are requested to please check : How to use photocells, LDRs, CdS cells, photoresistors!
From your previous posts it seems you are using a 4550 and C.
The two choices you have are an external RTC like the 1307 and associate parts, which also adds day, date and alarms etc. or go for a simpler software RTC based on a 32khz xtal connected to Timer1 input.
The advantage of the 1307 chips is that they have a battery backup so power outages are not a problem.
You didn't clearly tell, if your problems are mainly to have a clock (e.g. a RTC chip) or how to deal with time quantities in C library functions? Without using existing C libraries, it's often a resonable way to keep time of day as an integer number (e.g. minutes or seconds since midnight). You don't necessarily need a RTC chip as long as time keeping during power loss isn't an issue. Obviously, daytime related comparisons are much simpler by using an integer time representation instead of hour/minute/seconds. Date and time library functions are usually providing both formats and conversions betwen them.
Time quantities with separate hour/minute/seconds representation are usually stored in structures. If you are using existing library time and date function, you need to refer to the defined data types, otherwise you'r free to define your own. As said, I prefer integer quantities for time, e.g. timeofday as a 16 bit unsigned integer with the LSB representing 2 seconds.