Thursday, 5 November 2015

ADC PROGRAMMING OF ATMEGA32

Convert the analog value to digital and display it on LCD

#include <avr/io.h>
#include <util/delay.h>
void cmd(int);
void data(char);

int main(void)
{
int i,a,c,j;
char S[3]="000";

DDRA=0x30;
DDRB=0xff;
ADMUX=0x60;
ADCSRA=0x88;
cmd(0x38);
cmd(0x01);
cmd(0x0e);
cmd(0x06);
cmd(0x80);

    while(1)
    {
ADCSRA|=0x40;

while((ADCSRA&0x10)==0);
a=ADCH;
i=0;
while(a>0)
{
c=a%10;
a=a/10;
S[i]=c+48;
i++;
}
   
  for(j=2;j>=0;j--)
  {data(S[j]);
  }
  cmd(0x01);
  cmd(0x80);
    }
}
void cmd(int a)
{
PORTB=a;
PORTA=0x20;
_delay_ms(200);
PORTA=0x00;
}

void data(char a)
{
PORTB=a;
PORTA=0x30;
_delay_ms(200);
PORTA=0x10;
}

No comments:

Post a Comment