Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Sending lower nibble to LCD in C

fm101

Newbie level 5
Joined
Apr 13, 2020
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
69
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
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,190
Helped
4,687
Reputation
9,389
Reaction score
4,440
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
121,179
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.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
17,471
Helped
3,947
Reputation
7,892
Reaction score
3,816
Trophy points
113
Activity points
115,832
Hi,

Are you sure you keep timing requirements of the LCD?

Klaus
 

fm101

Newbie level 5
Joined
Apr 13, 2020
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
69
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!
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
46,987
Helped
13,938
Reputation
28,124
Reaction score
12,576
Trophy points
1,393
Location
Bochum, Germany
Activity points
273,971
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:

Aussie Susan

Advanced Member level 4
Joined
Jan 5, 2015
Messages
1,161
Helped
360
Reputation
720
Reaction score
356
Trophy points
83
Activity points
12,605
Also in what way is it "...not working..."?
No data displayed?
Wrong data displayed?
Susan
 

fm101

Newbie level 5
Joined
Apr 13, 2020
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
69
hi,
the solution was to send low nibble first...for anyone in future

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

Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top