Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help...Problem on ATmega8535

Status
Not open for further replies.

end

Newbie level 6
Joined
Dec 18, 2006
Messages
11
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,356
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.



56_1169724096.gif




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....
 

atmega8535

Hi,
Your program set the ADMUX=0 , that mean use reference voltage = AVref.Try to set ADMUX|=0x40 (reference voltage = AVCC) , i think it will be ok .
 

using lcd.h on atmega8535

Ok... thanks for support

how is the code if i use two channel ADC (adc0, adc1) and display

the result on the lCD
 

atmega8535 proteus

Hi,

the ADMUX register you set first in the main code
void main()
{
ADMUX=0x40;
.......
while(1)
{
//your code here
}

}

and in the read_adc procedure , you can write :

unsigned int read_adc(unsigned char adc_input)
{
.......
ADMUX&=0xf0; //clear last adc_input
ADMUX |= adc_input;
.........
}

or if you no need to init ADMUX in main code , you can write :
unsigned int read_adc(unsigned char adc_input)
{
.......
ADMUX = adc_input|0x40;
......
}
 

simulate atmega8535 proteus

your program is good but you must tied AREF at +5V
 

Hi, I’m trying to simulate to the ATmega8535 on Proteus but I can’t find the library that contains this model anywhere the Avr library has as far as ATmega128
Do you think you can point me in the right direction by telling me where to download it or something….
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top