#include<avr/io.h>#include<avr/delay.h>#include<inttypes.h>#define rs PA0#define rw PA1#define en PA2void lcd_init();void ADC_init();unsignedint ADC_read(unsignedchar);void dis_cmd(char);void dis_data(char);void lcdcmd(char);void lcddata(char);int main(void){
DDRA=0xEF;
ADC_init();unsignedchar data0[]="Temperatue=";unsignedchar data1,adc_val;
lcd_init();
LCD_print(data0);
adc_val=ADC_read(3);
data1=adc_val;
LCD_print(data1);while(1);}void lcd_init()// Function for initialize{
dis_cmd(0x02);// To initialize LCD in 4-bit mode.
dis_cmd(0x28);// To initialize LCD in 2 lines, 5X7 dots in 4bit mode.
dis_cmd(0x0F);// Blinking Cursor
dis_cmd(0x06);// Entry mode
dis_cmd(0x80);// This command gives the location of first letter ** 80 + 'x' ** shifts the display 'x' units right.
_delay_ms(500);}void dis_cmd(char cmd_value){char cmd_value1;
cmd_value1 = cmd_value &0xF0;// Mask lower nibble because PA4-PA7 pins are used (Extracting Upper Four bits)// Masking means clearing bits// Upper nibble is sent first and then the lower nibble
lcdcmd(cmd_value1);// Send to LCD
cmd_value1 =((cmd_value<<4)&0xF0);// Shift 4-bit and mask (Extracting Upper Four Bits)
lcdcmd(cmd_value1);// Send to LCD}void dis_data(char data_value){char data_value1;
data_value1=data_value &0xF0;
lcddata(data_value1);
data_value1=((data_value<<4)&0xF0);
lcddata(data_value1);}void lcdcmd(char cmdout){//Commands on LCD is initialized by having a negative transition on the enable pin.// 1) RS=RW=0 & EN=1;// 2) RS=RW=0 & EN=0;
PORTA=cmdout;
PORTA&=~(1<<rs);
PORTA&=~(1<<rw);
PORTA|=(1<<en);
_delay_ms(1);
PORTA&=~(1<<en);}void lcddata(char dataout){//Letters on LCD is displayed by having a negative transition on the enable pin.// 1) RS=RW=1 & EN=1;// 2) RS=RW=1 & EN=0;
PORTA=dataout;
PORTA|=(1<<rs);
PORTA&=~(1<<rw);
PORTA|=(1<<en);
_delay_ms(1);
PORTA&=~(1<<en);}void ADC_init(){
ADMUX=(1<<REFS0);
ADCSRA=(1<ADEN)|(1<<ADPS2)|(1<<ADPS0);}unsignedint ADC_read(unsignedchar ch){
ch= ch &0b00000111;// channel must be b/w 0 to 7
ADMUX |= ch;// selecting channel
ADCSRA|=(1<<ADSC);// start conversionwhile(!(ADCSRA &(1<<ADIF)));// waiting for ADIF, conversion complete
ADCSRA|=(1<<ADIF);// clearing of ADIF, it is done by writing 1 to itreturn(ADC);}void LCD_print(char* str){unsignedchar i=0;while(str[i]!=0){
dis_data(str[i]);
i++;}}
adc is not converting
i dont know the problem can anyone tell me what is the problem in my code.