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.

[SOLVED] Interfacing LCD with PIC16F877 using CCS C Compiler

Status
Not open for further replies.

maxim10373

Advanced Member level 4
Full Member level 1
Joined
Feb 26, 2010
Messages
116
Helped
1
Reputation
2
Reaction score
2
Trophy points
1,298
Visit site
Activity points
2,066
Hi
Please check the text file.
This is done in ccs compiler but nothing is showing on the LCD on proteus simulation .Can you help me?
I am using PIC16F877A and 4x20 LCD LM044L .

Regards
Maxim
 

Attachments

  • LCD.txt
    4.5 KB · Views: 321
  • LCD2.jpg
    LCD2.jpg
    79.8 KB · Views: 309

Hello!

In order to be helped, it might be wise to clearly say what's wrong. What do you want exactly?
I have tried to look at the code, but I would be in trouble if asked what it does.
Beside this, in any of your while loops, there are 2 occurrences of the measure function.
Usually you don't do that. You measure once per loop, you check other variables, buttons, etc,
and you update the display once per loop. You recalculate alpha (whatever it is) all the time,
etc...
Last but not least, you shouldn't use floats in an embedded system, except if there is really
no way to do otherwise.
Another thing: your LCD_DATAx are defined but never used in the whole file. Might be a reason
why it doesn't work. LCD_RW_PIN either.
I was saying "last but not least" but the more I look at the code, the more errors.
Your lcd.c includes lcd.c. Are you sure you want to do that?

Dora.
 
Hello!

In order to be helped, it might be wise to clearly say what's wrong. What do you want exactly?
I have tried to look at the code, but I would be in trouble if asked what it does.
Beside this, in any of your while loops, there are 2 occurrences of the measure function.
Usually you don't do that. You measure once per loop, you check other variables, buttons, etc,
and you update the display once per loop. You recalculate alpha (whatever it is) all the time,
etc...
Last but not least, you shouldn't use floats in an embedded system, except if there is really
no way to do otherwise.
Another thing: your LCD_DATAx are defined but never used in the whole file. Might be a reason
why it doesn't work. LCD_RW_PIN either.
I was saying "last but not least" but the more I look at the code, the more errors.
Your lcd.c includes lcd.c. Are you sure you want to do that?

Dora.
(Another thing: your LCD_DATAx are defined but never used in the whole file. Might be a reason
why it doesn't work. LCD_RW_PIN either.)
Yes, this could be the problem. I am trying to solve it

Thanks for reply
--- Updated ---

(Another thing: your LCD_DATAx are defined but never used in the whole file. Might be a reason
why it doesn't work. LCD_RW_PIN either.)
Yes, this could be the problem. I am trying to solve it

Thanks for reply
--- Updated ---

Everything else is fine but no characters are showing on the LCD, that's the issue, I'm a kid in programming, not good enough.
 
Last edited:

I would hope that your code has been corrupted in some way when you created the 'LCD.txt' file so that it lost all of its indenting and also messed up the bracketing styles. However I suspect not! I would strongly suggest that select one layout style and use that consistently in your code - you will find it a lot easier to check the logic of the code against the logic of your design.

Has your code (as shows to us) ever compiled successfully? I ask because there are several unusual aspects of your code.

You seem to be using the 'lcd_putc' function a lot, presumably to send characters to the LCD. According to the web site I looked at for the CCS compiler (https://www.ccsinfo.com/content.php?page=syntax-functions) - I've not used that compiler using the Microchip XC8 instead - there are built-in library functions that you could use but none of them are the functions you seem to use.
Also you have code such as:
lcd_putc('\f'); // Clear LCD screen printf(lcd_putc,".....
where you are passing a function to the 'printf' function as the first parameter. Also you "overload" the 'lcd_putc()' function by passing both characters (as above) and also strings as the parameter. As far as I am aware the CCS compilers do not allow C++ function overloads.
Take a step back and just write the code to put text on the LCD. Then you can add in the other code to provide the rest of the functionality.
(As an aside, I don't trust simulators because they can sometimes add a layer of bugs on top of yours. It is always better to use read hardware if you can.)
Susan
 

Looks like this might be a 'drive by posting' as the OP has not made an appearance for some time now.
The chip used in the OPs LCD is the bog-standard HD44780 so there are LOTS of code examples out there for how to drive that chip with a 4- or 8-bit parallel interface.
Compilers may indeed provide code libraries that can assist, but for beginners it is also instructive to write the (pretty simple) code themselves - and, as I said, there are lots of code examples around. Also when it comes to debugging, you have to trust the library code to do the right thing (read as: help me out when I pass dumb parameters).
Susan (from the 'old school' approach to coding!)
 

As far as I know, all the LCD pin defines should be placed before the LCD include, not after as you did, something like this:
C:
#define LCD_RS_PIN PIN_xx
#define LCD_ENABLE_PIN PIN_xx
#define LCD_RW_PIN PIN_xx
#define LCD_DATA4 PIN_xx
#define LCD_DATA5 PIN_xx
#define LCD_DATA6 PIN_xx
#define LCD_DATA7 PIN_xx

#include <lcd.c>

At a glance, your code is not let's say, the most understandable I've seen; so, if the LCD is not working, instead of dumping the whole code into simulator, think of starting with a bare 'Hello Word' just before getting into the main loop. BTW, I'm not a fan of the CCS compiler, even less running under Proteus simulation environment; It's one of the few combinations that didn't work out.
 

As far as I know, all the LCD pin defines should be placed before the LCD include, not after as you did
Absolutely correct. If the symbols are undefined at the time of lcd.c processing, some defaults defined in lcd.c will take effect, most likely different from what you expect.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top