DIGITAL COUNTER/VISITOR COUNTER WITH ATMEGA16 MICROCONTROLER



#include <avr/io.h>
#include <util/delay.h>
#include"lcd.h"
int main(void)
{ int a=0,b=0;

char x[5];
DDRA=0b00000000;
DDRC=0b11111111;
DDRD=0b11111111;
lcd_init();
while(1)
{
if(PINA==0b00000001)
{  lcdcmd(0x01);
a++;
itoa(a,x,10);
display(x);
_delay_ms(500);
}
else if(PINA==0b00000010)
{
lcdcmd(0x01);
a--;
itoa(a,x,10);
display(x);
_delay_ms(500);
if(a<=0)
{lcdcmd(0x01);
a=0;
itoa(a,x,10);
display(x);
_delay_ms(100);
}
}
}}




// THE HEADER FILE FOR LCD IS:---


void lcdcmd(char x)
{
PORTD=x;
PORTC=0b00000100;
_delay_ms(10);
PORTC=0b00000000;
_delay_ms(10);
}
void lcddata(char x)
{
PORTD=x;
        PORTC=0b00000101;
_delay_ms(10);
PORTC=0b00000001;
_delay_ms(10);
}
void display(char a[])
{

       int i;
for(i=0;a[i]!='\0';i++)
{lcddata(a[i]);

}
}
void lcd_init()
{
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
}

Comments

Popular posts from this blog

AVR MICROCONTROLLER