View previous topic :: View next topic |
Author |
Message |
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
Problem with LCD programming? |
Posted: Wed Oct 24, 2012 5:10 am |
|
|
Please tell me anything wrong with this code? simple program to display a string in LCD. But my LCD doesn't display this data. Please help.
Code: |
#include "18F2520.h"
#fuses HS, NOPROTECT, INTRC_IO
#use delay(clock=4000000)
#define RS PIN_A0
#define EN PIN_A1
void lcd_data(char z)
{
output_b(z);
output_high(EN);
output_high(RS);
delay_ms(5);
output_low(EN);
}
void lcd_cmd()
{
output_high(EN);
output_low(RS);
delay_ms(5);
output_low(EN);
}
void lcd_init()
{
delay_ms(1000);
output_b(0x30); // 8 bit, 1 1ine, 5 x 8 dots
lcd_cmd();
output_b(0x0c); // Restore the display(with cursor hidden)
lcd_cmd();
output_b(0x06); // display shift off, increment address counter
lcd_cmd();
output_b(0x80); // starting address of lcd
lcd_cmd();
output_b(0x01); // clear display
lcd_cmd();
delay_ms(5);
}
void main()
{
setup_oscillator(OSC_4MHZ);
set_tris_b(0x00); // all pins in PORT B are outputs
lcd_init();
lcd_data("LCD");
delay_ms(10);
while(1);
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Wed Oct 24, 2012 5:26 am |
|
|
Without knowing the mfr/make/model of the LCD no one knows the real initialzation requirements especially timing.
Also without seeing the schematic there could be a wiring error.
Simple things like the wrong contrast setting will not allow the LCD to 'work right'.
Have a look at the LCD drivers CCS supplies as well as the 'flex_LCD' driver. They both work, though 4 bit mode, they do show the timing needed for common LCD units.
Actually I'd start there...get it running in 4 bit mode then go to 8 bit mode.That way you _know_ the PIC works and the LCD works!
Honestly we need more info to help.
hth
jay |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Wed Oct 24, 2012 5:33 am |
|
|
Controller : 18F2520
OLED display : Winstar OLED WEH001601ALPP5N00000
OLED Data pins D0 to D7 connected to microcontroller B0 - B7.
RS connected to PIN A0
EN connected to PIN A1
what else information do u need?
thanks in advance . |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Oct 24, 2012 6:13 am |
|
|
Is your PIC working? Can you make it do an LED flasher?
You've got this line in your code
But defined lcd_data() as Quote: | void lcd_data(char z) |
Mike |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 24, 2012 1:20 pm |
|
|
Quote: | You've got this line in your code
lcd_data("LCD"); |
Mike, that's valid code for CCS. The manual says:
Quote: |
A (non-standard) feature has been added to the compiler to help get
around the problems created by the fact that pointers cannot be created
to constant strings. A function that has one CHAR parameter will accept a
constant string where it is called. The compiler will generate a loop that
will call the function once for each character in the string.
Example:
void lcd_putc(char c ) {
...
}
lcd_putc ("Hi There.");
|
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Oct 24, 2012 2:13 pm |
|
|
Sorry PCM programmer, I'd missed that nugget. Probably explains why I don't understand a lot of things |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Wed Oct 24, 2012 9:50 pm |
|
|
my code is correct or wrong? please help why i dont get anything on my oled display. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Thu Oct 25, 2012 3:06 am |
|
|
The standard 'init' required to switch to 8bit mode, and wake up an LCD, is:
0x30 4.1mSec pause
0x30 100uSec pause
0x30
//Only then send the setup stuff
0x30
0x0C
0x01
0x06 //This _must_ follow the first clear to turn display on
//You don't need the 0x80. The write address is set to the start of
//the display by the clear.
You are sending only one 0x30.
Then, EN, should not go high till _after_ RS and RW are set.
You don't show RW, so presumably this is hard wired to GND. It needs to be.
Also, CLS, takes 6.2mSec to execute. You should lengthen the delay in your command write to longer than this (7mSec).
Best Wishes |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Thu Oct 25, 2012 4:12 am |
|
|
if u dont mind. can u please alter my code and repost? so that i ll correct myself in the next program..
thanks |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Oct 25, 2012 8:28 am |
|
|
Quote: | if u dont mind. can u please alter my code and repost? so that i ll correct myself in the next program.. |
We're expecting you to do some work yourself.
Ttelmah has given you instructions on what to do. He's done the hard part, shown where you're going wrong, and suggested corrections.
Mike |
|
|
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
|
Posted: Thu Oct 25, 2012 10:25 am |
|
|
Thank you mike. I'll take your words, and will try to correct the errors. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Oct 27, 2012 1:53 am |
|
|
You've discovered that starting a new thread, on the same subject, gets you nowhere. It's been blocked.
Modify your code, along the indicated lines. If you're still stuck, come back with your new effort and someone will probably try to help.
Mike
EDIT
I've just looked back through old posts.
You were asking about LCD programming three weeks ago.
You were making similar errors then as now.
You were given the same advice then as this time round.
Did you get the LCD to work before?
One other thing to watch out for. The part No. you've quoted looks like a 16 char by 1 line display. Most people are using 2 or 4 line displays. The displays do require slightly different code. If all else fails post the manufacturer's instructions, there may be some subtle differences from the usual devices. |
|
|
|