DIGITAL WATCH USING ATMEGA16
#include <avr/io.h>
#include <util/delay.h>
#include"lcd.h"
int main(void)
{
int hrs,sec,min;
char h[4],s[4],m[4];
lcd_init();
lcdcmd(0x80);
display("HOUR:MIN:SEC");
for(hrs=0;hrs<25;hrs++)
{
lcdcmd(0xc5);
display(" ");
itoa(hrs,h,10);
lcdcmd(0xc1);
display(h);
{
for(min=0;min<61;min++)
{
lcdcmd(0xc8);
display(" ");
itoa(min,m,10);
lcdcmd(0xc4);
display(m);
{
for(sec=0;sec<61;sec++)
{
itoa(sec,s,10);
lcdcmd(0xc7);
display(s);
_delay_ms(1000);
}
}}}
}
// THE HEADER FILE IS:----
void lcdcmd(char x)
{DDRD=0b11111111;
DDRC=0b11111111;
PORTD=x;
PORTC=0b00000100;
_delay_ms(10);
PORTC=0b00000000;
_delay_ms(10);
}
void lcddata(char x)
{
DDRD=0b11111111;
DDRC=0b11111111;
PORTD=x;
PORTC=0b00000101;
_delay_ms(10);
PORTC=0b00000001;
_delay_ms(10);
}
void display(char a[])
{
DDRD=0b11111111;
DDRC=0b11111111;
int i;
for(i=0;a[i]!='\0';i++)
{lcddata(a[i]);
}
}
void lcd_init()
{
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
}
Comments
Post a Comment