I am trying to write C code for AVR microcontroller to send lower nibble via port B lower 4 pins as shown in figure below. My code to send data is also below but its not working. Can somebody tell me what i am doing wrong?
It depends on what values you have assigned to RW and RS.
If they have been assigned their bit position in PORTC, use these lines instead:
PORTC &= ~(1 << RW); // this makes the RW bit go low while leaving other bits as they were.
PORTC |= (1 << RS); // this makes the RS bit go high without changing other bits.
Make sure you change the bits back if necessary afterwards. I assume your latch() function just pulses 'E' low for a few mS.
if this part of the code :
PORTB = (PORTB & 0xF0) | (data & 0x0F);
is right then i should have no problem, because i have same working code but different port and pins(higher pins 7,6,5,4). but still nothing gets displayed on LCD!
The posted code snippet looks right, but there may be errors in other parts of your application, e.g. port setup, latch() function, definition of IO bits.
Also is your code failing in real hardware or Proteus simulation?
--- Updated ---
I just realized that you implement wrong order of 4-bit nibbles. Correct order is high nibble first low nibble second.