How to pass parameter on ATMEGA128 and AVR Studio 6?

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

Friends,

I don't understand on passing parameter on ATMEGA128 and AVR Studio 6,
I tested this function and working find

lcd_cmd()
{
			PORTD = 0xFF;
			_delay_ms(100);
			PORTD = 0x00;
			_delay_ms(100);
			
			en=0;
			_delay_ms(100);
			en=1;
			_delay_ms(100);
			rs=0;
			_delay_ms(100);
			rs=1;
			_delay_ms(100);
			rw=0;
			_delay_ms(100);
			rw=1;
			_delay_ms(100);

}
main()
{
 lcd_cmd();
}

PORTD (d0-d4) are appearing please see attachment

but by the time I put parameter to be passed, it doesn't work

lcd_cmd(unsigned char data_cmd)
{
			PORTD = data_cmd;
			_delay_ms(100);
			PORTD = data_cmd;
			_delay_ms(100);
			
			en=0;
			_delay_ms(100);
			en=1;
			_delay_ms(100);
			rs=0;
			_delay_ms(100);
			rs=1;
			_delay_ms(100);
			rw=0;
			_delay_ms(100);
			rw=1;
			_delay_ms(100);

}
main()
{
while(1)
{
 lcd_cmd(0xFF);
_delay_ms(100);
 lcd_cmd(0x00);
}
}

Please see attachment,
PORTD (d0-d4) are missing but rw,rs,and en are working

What do I miss here ? It's very strange for me....
Any experiences , shares or knowledges will be very appreciated,

Thank you

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
 en=0;
 rs=0; 
 rw=0; 

How are these defined? You realise you can't access port bits like this? I dare say this is the crux of the problem.

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

If the code does:

lcd_cmd(0xFF);
...
         PORTD = data_cmd; 
         _delay_ms(100); 
         PORTD = data_cmd; 
         _delay_ms(100); 

Then surely the expected result is that all the lines of D, including the d0..d3 in your scope picture, should go high and remain high? In that case this IS surely the correct result:

The difference is that in your code that "works" you do:

         PORTD = 0xFF; // all high
         _delay_ms(100); 
         PORTD = 0x00;  // all low
         _delay_ms(100); 

The FF makes the lines go high, the 00 makes them go low. That's why you see "pulses" on the lines. While in your parameter passing code you do:

         PORTD = data_cmd; 
         _delay_ms(100); 
         PORTD = data_cmd; 
         _delay_ms(100); 

with data_cmd = 0xFF. So the second write here has no effect. Surely you meant to do:

         PORTD = data_cmd; 
         _delay_ms(100); 
         PORTD = 0x00; // all back to low again
         _delay_ms(100); 

to be equivalent to the working code?

But the code does not make any sense. Surely it should be:

setup PORTD
wiggle en, rs, rw in some way
return PORTD to 0

You are doing:

setup PORTD
return PORTD to 0
wiggle en, rs, rw in some way

As it's the wiggling of "en" that "clocks" the presented data into the LCD controller the way you are doing it at present means the LCD only ever sees 0x00.

If this is about driving an HD44780 why waste your time reinventing the wheel for the millionth time. There are lots of good, tried, tested solutions:

http://www.johanekdahl.se/rwiki/...