Real Time Clock ATMega16


The ATMega16 chip in the M16 has a real-time counter that operates asynchronously when a 32,768hz watch crystal is connected to it, providing a real-time clock. Bascom has built-in support for the RTC, making it very easy to use time functions. The watch crystal needs to connect to pins TOSC1(pin 28) and TOSC2(pin 29). The time and date can be set via the PC serial port connection.
Real Time Clock M16

Hardware requirements

  • ATMega16
  • 32,768 KHz crystal
  • LCD display
  • RS232 port


BASCOM-AVR Real Time Clock example, the time can be set in a terminal program like hyperterminal.

'Real-Time Clock Example
'target device: ATMega16
'compilar: BASCOM-AVR
'date: 18-07-2008
    Enable Interrupts
    Config Clock = Soft       'This command inits the clock
    Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 ,
	Db7 = Portb.3 , E = Portb.6 , Rs = Portb.7
    $crystal = 10000000       'give here the value of the X-tal you use in Hertz
    $baud = 9600
    Config Date = Ymd , Separator = -                       ' ANSI-Format
    Input "Enter the time (hh:mm:ss):" , Time$
    Input "Enter the date (mm/dd/yy):" , Date$
    Cursor Off
    Locate 1 , 1
    Lcd "Real Time Clock"
       Locate 2 , 1
       Lcd Time$
       Locate 3 , 1
       Lcd Date$
       Wait 1

For more details, click: Real Time Clock ATMega16

About The Author

Ibrar Ayyub

Ibrar Ayyub is an experienced technical writer with a Master's degree in computer science from BZU Multan University. He has written for various industries, mainly home automation, and engineering. He has a clear and simple writing style and is skilled in using infographics and diagrams. He is a great researcher and is able to present information in a well-organized and logical manner.

Scroll to Top