end
Newbie level 6
lcd using at mega 8535 code vson sample code
Hi...
i simulate the ADC ATMega8535 using proteus and compile the C code with
Code Vision AVR.
here it is the schematic.
i try to read the analog input from PORTA.0 using free running mode,
and display the value to the LCD display.
here it is the c code..
#include "mega8535.h"
#include "stdio.h"
#include "delay.h"
#include "lcd.h"
#asm // Alphanumeric LCD Module functions
.equ __lcd_port = 0x15
#endasm
unsigned int ADC_VALUE;
unsigned int read_adc(unsigned char adc_input)
{
ADMUX = adc_input;
ADCSRA |= 0x40;
while ((ADCSRA & 0x10) == 0); // Wait for the AD conversion to complete
ADCSRA |= 0x10;
return ADCW;
}
void main(void)
{
unsigned char sbuf[16];
unsigned int TEMP;
DDRA = 0x00;
DDRC = 0xFF;
lcd_init(16); // LCD module initialization
ADCSRA = 0x85;
SFIOR &= 0xEF;
while(1)
{
ADC_VALUE = read_adc(0);
lcd_gotoxy(0,0);
sprintf(sbuf, "VALUE : %4d", ADC_VALUE);
lcd_puts(sbuf);
delay_ms(10);
}
}
the source compiled with CVAVR and simulate using proteus based on the schema above.
the simulation works..but the value displayed in LCD(LCD dispay "1023" persistent) doesn't change when i change the potensiometer value..
what wrong with my code ?
Thanks for the help....
Hi...
i simulate the ADC ATMega8535 using proteus and compile the C code with
Code Vision AVR.
here it is the schematic.
i try to read the analog input from PORTA.0 using free running mode,
and display the value to the LCD display.
here it is the c code..
#include "mega8535.h"
#include "stdio.h"
#include "delay.h"
#include "lcd.h"
#asm // Alphanumeric LCD Module functions
.equ __lcd_port = 0x15
#endasm
unsigned int ADC_VALUE;
unsigned int read_adc(unsigned char adc_input)
{
ADMUX = adc_input;
ADCSRA |= 0x40;
while ((ADCSRA & 0x10) == 0); // Wait for the AD conversion to complete
ADCSRA |= 0x10;
return ADCW;
}
void main(void)
{
unsigned char sbuf[16];
unsigned int TEMP;
DDRA = 0x00;
DDRC = 0xFF;
lcd_init(16); // LCD module initialization
ADCSRA = 0x85;
SFIOR &= 0xEF;
while(1)
{
ADC_VALUE = read_adc(0);
lcd_gotoxy(0,0);
sprintf(sbuf, "VALUE : %4d", ADC_VALUE);
lcd_puts(sbuf);
delay_ms(10);
}
}
the source compiled with CVAVR and simulate using proteus based on the schema above.
the simulation works..but the value displayed in LCD(LCD dispay "1023" persistent) doesn't change when i change the potensiometer value..
what wrong with my code ?
Thanks for the help....