ADC: joystick interface using Atmega328P

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The code isn’t working and what should i do next i need to show the joystick movement on lcd but this code isn’t working can somebody help.

; Replace with your application code

LDI R16,LOW(RAMEND);
OUT SPL,R16;
LDI R16,HIGH(RAMEND);
OUT SPH,R16;

Start:

LDI R16,0XFF;
OUT DDRD,R16;
OUT DDRB,R16;
LDI R16,0X00;
OUT DDRC,R16;
LDI R16,(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
STS ADCSRA,R16;
LDI R16,(1<<REFS0)|(1<<ADLAR)|(0<<MUX3)|(0<<MUX2)|(0<<MUX1)|(0<<MUX0);
STS ADMUX,R16;

Read_channel:

LDS R16,(1<<ADSC);
STS ADCSRA,R16;

Keep_Poling:

LDS R16,ADCSRA;
SBRC R16,ADSC;
RJMP Keep_Poling;
LDS R16,ADCSRA;
SBR R16,ADIF;
LDS R16,ADCL;
OUT PORTD,R16;
LDS R16,ADCH;
OUT PORTB,R16;
RJMP Read_channel;

M

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mhmd wrote:

Read_channel:

LDS R16,(1<<ADSC);
STS ADCSRA,R16;

Isn't doing what you think it's doing.

 

You need to load ADCSRA with LDS, then modify with ORI and STS back to ADCSRA

 

There are a few other problems as well.

 

Which device?  What clock speed?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Sat. Dec 14, 2019 - 05:51 AM