Introduction :-
In this project we use ATmega16 controller and a 16x2 alphanumeric LCD. Program is loaded in the ATmega16 and the digital clock is ready to run.
Lcd Interfacing :-
see.. LCD INTERFACING WITH ATmega16 IN 4-BIT MODE
ATmega16 :-
In 4-bit mode ground the first 4 data pins of LCD means pin 7-11. make the connections as shown above.
In this project we use ATmega16 controller and a 16x2 alphanumeric LCD. Program is loaded in the ATmega16 and the digital clock is ready to run.
Lcd Interfacing :-
see.. LCD INTERFACING WITH ATmega16 IN 4-BIT MODE
ATmega16 :-
Components required :-
- 10k ohm registance
- 10k ohm variable registance
- 8 MHZ crystal oscilltor
- 16x2 LCD
- ATmega16 IC
- 12v battery
- Toggle button
- 7805 IC
- 330 ohm resistance
- 1N4007 diode
- 1000uf capacitor
- Green LED
Circuit Diagram :-
In 4-bit mode ground the first 4 data pins of LCD means pin 7-11. make the connections as shown above.
Code (compiled in CVAVR) :-
(see.. CVAVR TUTORIAL (CODE VISION AVR))
Note :- In CVAVR program window delete all the lines and paste the code given below. because there are so much unnecessary lines.
-----------------------------------------------------------------------------------------------------------------------
#include <mega16.h>
#include <delay.h>
#include <stdlib.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
void main(void)
{
int h,m,s,i=0;
char a[20];
// LCD module initialization
lcd_init(16);
while (1)
{
lcd_gotoxy(0,0);
itoa(i,a);
lcd_puts(a);
lcd_gotoxy(1,0);
lcd_puts(a);
lcd_gotoxy(2,0);
lcd_putchar(':');
lcd_gotoxy(3,0);
lcd_puts(a);
lcd_gotoxy(4,0);
lcd_puts(a);
lcd_gotoxy(5,0);
lcd_putchar(':');
lcd_gotoxy(6,0);
lcd_puts(a);
lcd_gotoxy(7,0);
lcd_puts(a);
for(h=0;h<=23;h++)
{
if(h>=12)
{
lcd_gotoxy(9,0);
lcd_putsf("PM");
if(h>=12&&h<13)
{
lcd_gotoxy(0,0);
itoa(h,a);
lcd_puts(a);
}
if(h>=13)
{
h=h-12;
if(h<=9)
{
lcd_gotoxy(0,0);
itoa(i,a);
lcd_puts(a);
lcd_gotoxy(1,0);
itoa(h,a);
lcd_puts(a);
}
else
{
lcd_gotoxy(0,0);
itoa(h,a);
lcd_puts(a);
}
h=h+12;
}
}
else
{
lcd_gotoxy(9,0);
lcd_putsf("AM");
if(h<=9)
{
lcd_gotoxy(0,0);
itoa(i,a);
lcd_puts(a);
lcd_gotoxy(1,0);
itoa(h,a);
lcd_puts(a);
}
else
{
lcd_gotoxy(0,0);
itoa(h,a);
lcd_puts(a);
}
}
for(m=0;m<=59;m++)
{
if(m<=9)
{
lcd_gotoxy(3,0);
itoa(i,a);
lcd_puts(a);
lcd_gotoxy(4,0);
itoa(m,a);
lcd_puts(a);
}
else
{
lcd_gotoxy(3,0);
itoa(m,a);
lcd_puts(a);
}
for(s=0;s<=59;s++)
{
if(s<=9)
{
lcd_gotoxy(6,0);
itoa(i,a);
lcd_puts(a);
lcd_gotoxy(7,0);
itoa(s,a);
lcd_puts(a);
delay_ms(1000);
}
else
{
lcd_gotoxy(6,0);
itoa(s,a);
lcd_puts(a);
delay_ms(1000);
}
}
}
}
}
}
-----------------------------------------------------------------------------------------------------------------------
Proteus simulation:-