Summary of Real Time Clock ATMega16
This article details a Real-Time Clock project using the ATMega16 microcontroller. It leverages the chip's asynchronous real-time counter driven by a 32,768Hz watch crystal connected to specific pins. The system utilizes BASCOM-AVR software to initialize the clock and display time/date on an LCD via a serial port connection for configuration.
Parts used in the Real-Time Clock Project:
- ATMega16
- 32,768 KHz crystal
- LCD display
- RS232 port
Description
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.
Hardware requirements
- ATMega16
- 32,768 KHz crystal
- LCD display
- RS232 port
Software
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
'www.avrprojects.net
'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$
Cls
Cursor Off
Locate 1 , 1
Lcd "Real Time Clock"
Do
Locate 2 , 1
Lcd Time$
Locate 3 , 1
Lcd Date$
Wait 1
Loop
For more details, click: Real Time Clock ATMega16
- How does the ATMega16 provide a real-time clock?
The ATMega16 has a real-time counter that operates asynchronously when a 32,768hz watch crystal is connected. - Which pins connect the watch crystal?
The watch crystal needs to connect to pins TOSC1(pin 28) and TOSC2(pin 29). - Can I set the time and date remotely?
Yes, the time and date can be set via the PC serial port connection. - What software supports this project?
BASCOM-AVR provides built-in support for the RTC and includes a Real Time Clock example. - How do I configure the clock initialization in code?
You use the command Config Clock = Soft to init the clock. - What format is used for the date setting?
The date uses ANSI-Format with Ymd separator configured as Date = Ymd , Separator = -. - What baud rate is used for communication?
The baud rate is set to 9600 using the variable $baud = 9600. - Where are the LCD data pins connected?
Data bits Db4 through Db7 connect to Portb.0 through Portb.3 respectively.