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.

Sending lower nibble to LCD in C

Status
Not open for further replies.

fm101

Member level 5
Member level 5
Joined
Apr 13, 2020
Messages
81
Helped
1
Reputation
2
Reaction score
4
Trophy points
18
Activity points
591
hi,

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?

thanks

C:
  void lcdchar(uint8_t data){
      
      PORTB = (PORTB & 0xF0) | (data & 0x0F);  // send low nibble
      PORTC &= ~RW;    //send 0 for write operation
      PORTC |= RS;    //send 1 to select data register
      latch();
    
      PORTB = (PORTB & 0xF0) | (data>>4);  // send high nibble
      latch();
      
      }

lcd.jpg
 

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.

Brian.
 

Hi,

Are you sure you keep timing requirements of the LCD?

Klaus
 

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.
 
Last edited:

Also in what way is it "...not working..."?
No data displayed?
Wrong data displayed?
Susan
 

hi,
the solution was to send low nibble first...for anyone in future

thanks everybody, FvM post hinted out in soln direction......
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top