View previous topic :: View next topic |
Author |
Message |
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
how to do LCD program? |
Posted: Fri Oct 05, 2012 11:34 pm |
|
|
Hi, I'm new to programming. I did led programs. It successfully worked. Now I'm writing a program to interface LCD with pic 18F2520 controller. Without using inbuilt drivers, how to send data to LCD display? I want to display "HELLOW" in the LCD. Please help me with sample code. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Oct 05, 2012 11:40 pm |
|
|
If you look in the examples directory (and the drivers) directory of PICC, you should see ready made examples requiring only adaptation to your hardware.
Additionally, just search for LCD in the code library of this forum and you'll find LOTS of stuff.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Sat Oct 06, 2012 12:18 am |
|
|
I've looked in to code library. Mostly it uses the inbuilt driver 'lcd.c' or 'flex.c'... I don't want to use those drivers. I like to interface LCD without those drivers. Please update some examples here. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sat Oct 06, 2012 12:33 am |
|
|
what's wrong with those drivers?
Those are exactly (to a large degree) the same thing anyone would write for you.
Given the provided code that comes with PIC-C and the abundant examples in the code library on this forum, I don't think anyone is going to stop, drop and code at your command. You're going to have to put some effort into it.
If you're not willing to take a stab at the many examples out there, why should we?
Now, if you'd like to hire someone, there are plenty of people here that would gladly offer their coding services. Then you won't have to really think about it at all if that's your ultimate goal.
Regards..
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Sat Oct 06, 2012 12:45 am |
|
|
I have tried with inbuild drivers 'lcd.c'.
I have connected,
LCD D4 to uc PIN_C4
LCD D5 to uc PIN_C5
LCD D6 to uc PIN_C6
LCD D7 to uc PIN_C7
LCD RS to uc PIN_C2
LCD EN to uc PIN_C3
but shows following errors
*** Error 12 "C:\Program Files (x86)\PICC\drivers\lcd.c" Line 91(29,30): Undefined identifier -- set_tris_d
*** Error 12 "C:\Program Files (x86)\PICC\drivers\lcd.c" Line 103(30,31): Undefined identifier -- set_tris_d
*** Error 12 "C:\Program Files (x86)\PICC\drivers\lcd.c" Line 133(28,29): Undefined identifier -- set_tris_d
Please bear with me. How to rectify these errors ? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Oct 06, 2012 1:37 am |
|
|
If all else fails, post the SHORTEST possible COMPLETE and COMPILABLE code which shows your problem. Then we can copy and test it.
Mike |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Sat Oct 06, 2012 1:45 am |
|
|
Code: | #include "18F2520.h"
#include <string.h>
#fuses HS, NOPROTECT, INTRC_IO
#use delay(clock=4000000)
#include <lcd.c>
#define RS PIN_C2
#define EN PIN_C3
#define R/W PIN_A4
#define D4 PIN_C4
#define D5 PIN_C5
#define D6 PIN_C6
#define D7 PIN_C7
void main()
{
setup_oscillator(OSC_4MHZ);
set_tris_c(0x00);
lcd_init();
//output_high(RS);
//output_high(EN);
printf(lcd_putc,"hellow");
//output_low(EN);
while(1);
}
|
|
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Sat Oct 06, 2012 1:46 am |
|
|
driver lcd.c ...
Code: |
//// LCDD.C ////
//// Driver for common LCD modules ////
|
+++++++++++++++++++++++++
Driver code deleted.
Reason: Forum rule #10
10. Don't post the CCS example code or drivers
Forum rules:
http://www.ccsinfo.com/forum/viewtopic.php?t=26245
- Forum Moderator
+++++++++++++++++++++++++ |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sat Oct 06, 2012 1:59 am |
|
|
hemnath wrote: | Code: | #include "18F2520.h"
#include <string.h>
#fuses HS, NOPROTECT, INTRC_IO
#use delay(clock=4000000)
#include <lcd.c>
#define RS PIN_C2
#define EN PIN_C3
#define R/W PIN_A4
#define D4 PIN_C4
#define D5 PIN_C5
#define D6 PIN_C6
#define D7 PIN_C7
void main()
{
setup_oscillator(OSC_4MHZ);
set_tris_c(0x00);
lcd_init();
//output_high(RS);
//output_high(EN);
printf(lcd_putc,"hellow");
//output_low(EN);
while(1);
}
|
|
Pin definitions have to be set _before_ you load the driver.
The code in the driver will be using the default definitions, including therefore port D, which does not exist on your chip....
Best Wishes |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Oct 06, 2012 3:26 am |
|
|
As I understand it, the CCS driver is expecting all the LCD pins to be driven from the same port. Yours are not. I believe you will be better served by the flex_LCD drivers which permit any pin combination.
Also you need to add a ~1s delay before you initialise the LCD. This allows everything to settle properly after power up.
Mike
EDIT You're not supposed to post CCS drivers, everybody with a licence already has them. |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Sat Oct 06, 2012 4:19 am |
|
|
i'm exhausted with lcd drivers. so i've tried without using drivers.
Code: | #include "18F2520.h"
#include <string.h>
#fuses HS, NOPROTECT, INTRC_IO
#use delay(clock=4000000)
#define RS PIN_A7
#define EN PIN_A6
#define D0 PIN_C0
#define D1 PIN_C1
#define D2 PIN_C2
#define D3 PIN_C3
#define D4 PIN_C4
#define D5 PIN_C5
#define D6 PIN_C6
#define D7 PIN_C7
void lcd_cmd(CHAR a);
void lcd_print(CHAR rstr[]);
char msg[20];
void main()
{
while(1)
{
setup_oscillator(OSC_4MHZ);
set_tris_c(0x00);
set_tris_a(0x00);
output_c(0x00);
output_a(0x00);
delay_ms(100);
output_low (RS);//set LCD to command mode
lcd_cmd (0x30);//set LCD to 1x8 LINE DISPLAY (8 bit) ok
lcd_cmd (0x01);//clear LCD screen
lcd_cmd (0x02);//move cursor to home position
strcpy (msg, "Hellow");
lcd_print (msg) ;
delay_ms (3000);
}
void lcd_cmd(CHAR msg) // TO enable LCD microcontroler // function definition
{
output_b (msg);
delay_ms (10);
output_high (EN);
delay_ms (10);
output_low (EN);
}
void lcd_print(CHAR rstr[])
{
INT i;
FOR (i=0; rstr[i]!='\0'; i++)
{
output_high (rs);//set LCD to data mode
lcd_cmd (rstr[i]);//printing the charact to display LCD
}
}
It shows error . wats the problem in the code? |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sat Oct 06, 2012 4:57 am |
|
|
Use:
Code: |
// Replace the first 20 lines of flex_lcd.c with:
---------------------
// flex_lcd.c
// These pins are for the Microchip PicDem2-Plus board,
// which is what I used to test the driver. Change these
// pins to fit your own board.
#define LCD_DB4 PIN_C4
#define LCD_DB5 PIN_C5
#define LCD_DB6 PIN_C6
#define LCD_DB7 PIN_C7
#define LCD_E PIN_A6
#define LCD_RS PIN_A7
#define LCD_RW 0
// If you only want a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line.
//#define USE_LCD_RW 1
--------------------
//Connect the R/W line on the LCD to ground, and use the following main:
#include "18F2520.h"
#fuses HS, NOPROTECT, INTRC_IO
#use delay(clock=4000000)
#include <string.h> //Put other includes after the clock/fuses, or some
//functions will not work correctly
#include "flex_lcd.c"
char msg[20];
void main(void) {
int8 ctr=0;
//As a comment on the removed code, you are saying above you are
//using a 4MHz crystal, then selecting the internal oscillator. Duh....
delay_ms(100);
lcd_init();
do {
printf(lcd_putc,"\fHello %d",ctr++);
delay_ms(1000);
} while (TRUE);
}
|
That is all you need.
Now, on why your code doesn't work.
Your main one is the sequence of commands does not match what needs to be sent.
The sequence needed to wake up a display in 8bit mode, is:
0x30,0x30,0x30,0x30,0x08,0x1,0x0E
The last byte changes according to the cursor required etc., but 0x30, has to be sent three times before starting. The fourth is then the one 'accepted'.
There has to be a minimum of 4.1uSec pause after the first byte is sent.
There is also some bad/dangerous coding, with you using the same name for the local variable 'msg', in lcd_cmd, that is already used for a global array....
Seriously the flex_lcd driver does work, and is a lot neater to use, if _you_ spend five minutes to get the definitions to match your hardware. Your code needs you to know the command values to control everything, which is messy, and likely to lead to problems later.
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sat Oct 06, 2012 5:23 am |
|
|
I have to agree the flex_lcd.c driver does work fine however
BEFORE you modify it...
Make a COPY, called my_flex_lcd.c or similar name !!
That way you can always refer back to the original driver !!
Yes, it may seem obvious but others have modified the 'one and only' original version of a driver then spent hours trying to figure out what was 'wrong' only to discover they'ed removed a line of code !
hth
jay |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
|
|