|
|
View previous topic :: View next topic |
Author |
Message |
e-learner
Joined: 20 May 2014 Posts: 21
|
how the LCD connections to be done,if i include LCD.c in CCS |
Posted: Thu Jun 12, 2014 11:49 pm |
|
|
how the LCD connections to be done,if i include LCD.c in CCs compiler for write or display function.
i connected as,
Code: |
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_E PIN_E0
#define LCD_RS PIN_E1
#define LCD_RW PIN_E2
#include <lcd.c>
void main()
{ While(1)
{
lcd_init();
printf(lcd_putc,"/f welcome to ETPL");
delay_ms(1500);
Printf(lcd_putc,"/n LCD interface");
delay_ms(1500);
}
{
output_high(PIN_B1);
}
} |
but the lcd not displays anything,wat is the correction to be made. _________________ e-learner |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Jun 13, 2014 12:47 am |
|
|
First, the defines you have are for the flex_LCD driver, from the code library, not the 'lcd.c' driver supplied with the compiler. Major problem.....
Get the flexLCD driver.
This is probably the main problem.
Then the init, only wants to be called once:
Code: |
void main()
{
//delay before trying to start the LCD. Most need about 0.5 seconds
//before they will accept data.
lcd_init();
While(TRUE)
{
printf(lcd_putc,"/f welcome to ETPL");
delay_ms(1500);
Printf(lcd_putc,"/n LCD interface");
delay_ms(1500);
}
//Er. You never get here....
{
output_high(PIN_B1);
}
}
|
Then big question. What have you got connected to Vo on the LCD?. This is the 'contrast control' pin. Unless it is connected to the right voltage, you won't see anything on the LCD. The voltage needed depends on the exact model of your LCD. Some traditional LCD's require a -ve voltage on this (-0.4v typically). Many modern LCD's will display with a small positive voltage on here. Some will work with 0v. You need to get this right.
Then have you verified your processor is actually running?. |
|
|
e-learner
Joined: 20 May 2014 Posts: 21
|
RE |
Posted: Fri Jun 13, 2014 1:02 am |
|
|
Dear telmah ,
i don't have flex_lcd driver in my compiler,i only have lcd.c,so took this.
I have connected the V0 Pin of LCD to 5K pot .Even by adjusting it i couldn't see anything.
The LCD iam using is JHD 162a. _________________ e-learner |
|
|
e-learner
Joined: 20 May 2014 Posts: 21
|
RE: |
Posted: Fri Jun 13, 2014 1:09 am |
|
|
i have changed my code in this format for ur suggestion,moreover i confirmed that my controller is running by making the LED high.
Even after changing i could not see anything.
Code: |
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_E PIN_D0
#define LCD_RS PIN_D1
#define LCD_RW PIN_D2
#include <lcd.c>
void main()
{
While(1)
{
delay_ms(50);
lcd_init();
printf(lcd_putc,"/f welcome to ETPL");
delay_ms(50);
Printf(lcd_putc,"/n LCD interface");
delay_ms(50);
output_high(PIN_B1);
}
} |
what should be the defines if i use LCD.c ? _________________ e-learner |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Jun 13, 2014 1:25 am |
|
|
The point is that you can't use the lcd.c driver with 'flexible' defines like this.
Load the flex_lcd driver from the code library.
You can setup lcd.c, is a fairly similar way, but it is more work, and uses different names. The whole point about flex_lcd, is that it is 'flexible'. Allows you to define the pins the way you want. The code library is from the same root as this forum, and contains useful drivers like this. 90% of people using lcd's probably use the flex_lcd driver, not lcd.c. The defines you have are named for the flex_lcd driver, suggesting you have copied them from somewhere in the forum, where the poster is using flex_lcd. So do the same.... |
|
|
e-learner
Joined: 20 May 2014 Posts: 21
|
RE: |
Posted: Fri Jun 13, 2014 1:45 am |
|
|
OK thank you ,i will try and come. _________________ e-learner |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Jun 13, 2014 2:09 am |
|
|
and, once you have the driver, if you look at the first dozen lines, you will see the corresponding defines already setup for the PicDem2 board. Just change these to yours. |
|
|
e-learner
Joined: 20 May 2014 Posts: 21
|
still no change,any change needed? |
Posted: Fri Jun 13, 2014 5:53 am |
|
|
i downloaded flex_lcd.c,and made pin changes according to my connection,should i change anything else?
I have one doubt when i measured the VDD voltage of LCD it is about 3.2V,will it drive LCD?
Code: |
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#include <Flex_lcd.c>
void main()
{
While(1)
{
delay_ms(50);
lcd_init();
printf(lcd_putc,"/f welcome to ETPL");
delay_ms(50);
//Printf(lcd_putc,"/n LCD interface");
//delay_ms(50);
output_high(PIN_B1);
}
} |
flex_lcd driver in which i changed pin define
Code: |
// 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_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_E PIN_D0
#define LCD_RS PIN_D1
//#define LCD_RW PIN_D2
// 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
|
_________________ e-learner |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Jun 13, 2014 6:54 am |
|
|
WHY is LCD Vdd only 3 volts?
WHAT is the PICs Vdd ??
That PIC requires a MINIMUM of 4.50 volts to run at 20Mhz.
also
your main loop is faulty
you should
delay_ms(500);
lcd_init();
do
...stuff like blink LED
... more stuff
forever
also
most LCD modules are 5 volts, WHAT does the datasheet say for yours?
hth
jay |
|
|
e-learner
Joined: 20 May 2014 Posts: 21
|
RE: |
Posted: Fri Jun 13, 2014 7:15 am |
|
|
i rewired the circuit guessing any voltage drop such that lcd is given 5V directly,i measured the PIC VCC also 5.6V,and LED is glowing which is connected to 34th pin.LCD displays nothing.
I measured the voltage across all the pins of LCD,0.45V only in LCD enable...I think LCD is not enabled by code,am i right?.
The datasheet says 4.5 to 5V supply max for LCD. _________________ e-learner
Last edited by e-learner on Fri Jun 13, 2014 7:22 am; edited 1 time in total |
|
|
e-learner
Joined: 20 May 2014 Posts: 21
|
re: |
Posted: Fri Jun 13, 2014 7:21 am |
|
|
can anybody confirm that LCD Enable is made high or not in this driver which i copied from code library?
Code: |
// 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_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_E PIN_D0
#define LCD_RS PIN_D1
//#define LCD_RW PIN_D2
// 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
//========================================
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line
int8 const LCD_INIT_STRING[4] =
{
0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots
0xc, // Display on
1, // Clear display
6 // Increment cursor
};
//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
// Note: !! converts an integer expression
// to a boolean (1 or 0).
output_bit(LCD_DB4, !!(nibble & 1));
output_bit(LCD_DB5, !!(nibble & 2));
output_bit(LCD_DB6, !!(nibble & 4));
output_bit(LCD_DB7, !!(nibble & 8));
delay_cycles(1);
output_high(LCD_E);
delay_us(2);
output_low(LCD_E);
}
//-----------------------------------
// This sub-routine is only called by lcd_read_byte().
// It's not a stand-alone routine. For example, the
// R/W signal is set high by lcd_read_byte() before
// this routine is called.
#ifdef USE_LCD_RW
int8 lcd_read_nibble(void)
{
int8 retval;
// Create bit variables so that we can easily set
// individual bits in the retval variable.
#bit retval_0 = retval.0
#bit retval_1 = retval.1
#bit retval_2 = retval.2
#bit retval_3 = retval.3
retval = 0;
output_high(LCD_E);
delay_cycles(1);
retval_0 = input(LCD_DB4);
retval_1 = input(LCD_DB5);
retval_2 = input(LCD_DB6);
retval_3 = input(LCD_DB7);
output_low(LCD_E);
return(retval);
}
#endif
//---------------------------------------
// Read a byte from the LCD and return it.
#ifdef USE_LCD_RW
int8 lcd_read_byte(void)
{
int8 low;
int8 high;
output_high(LCD_RW);
delay_cycles(1);
high = lcd_read_nibble();
low = lcd_read_nibble();
return( (high<<4) | low);
}
#endif
//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);
#ifdef USE_LCD_RW
while(bit_test(lcd_read_byte(),7)) ;
#else
delay_us(60);
#endif
if(address)
output_high(LCD_RS);
else
output_low(LCD_RS);
delay_cycles(1);
#ifdef USE_LCD_RW
output_low(LCD_RW);
delay_cycles(1);
#endif
output_low(LCD_E);
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
//----------------------------
void lcd_init(void)
{
int8 i;
output_low(LCD_RS);
#ifdef USE_LCD_RW
output_low(LCD_RW);
#endif
output_low(LCD_E);
delay_ms(15);
for(i=0 ;i < 3; i++)
{
lcd_send_nibble(0x03);
delay_ms(5);
}
lcd_send_nibble(0x02);
for(i=0; i < sizeof(LCD_INIT_STRING); i++)
{
lcd_send_byte(0, LCD_INIT_STRING[i]);
// If the R/W signal is not used, then
// the busy bit can't be polled. One of
// the init commands takes longer than
// the hard-coded delay of 60 us, so in
// that case, lets just do a 5 ms delay
// after all four of them.
#ifndef USE_LCD_RW
delay_ms(5);
#endif
}
}
//----------------------------
void lcd_gotoxy(int8 x, int8 y)
{
int8 address;
if(y != 1)
address = lcd_line_two;
else
address=0;
address += x-1;
lcd_send_byte(0, 0x80 | address);
}
//-----------------------------
void lcd_putc(char c)
{
switch(c)
{
case '\f':
lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n':
lcd_gotoxy(1,2);
break;
case '\b':
lcd_send_byte(0,0x10);
break;
default:
lcd_send_byte(1,c);
break;
}
}
//------------------------------
#ifdef USE_LCD_RW
char lcd_getc(int8 x, int8 y)
{
char value;
lcd_gotoxy(x,y);
// Wait until busy flag is low.
while(bit_test(lcd_read_byte(),7));
output_high(LCD_RS);
value = lcd_read_byte();
output_low(lcd_RS);
return(value);
}
#endif |
Thanks for all your previous replies,pls help me further to solve my problem. _________________ e-learner |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Jun 13, 2014 8:02 am |
|
|
You need to post a link to the LCD datasheet !
LCD should have 5 V Vcc, same as PIC's Vdd.
hth
jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 13, 2014 1:17 pm |
|
|
Quote: | can anybody confirm that LCD Enable is made high or not in this driver which i copied from code library |
You have these LCD pins defined below. Which one do you think is
most likely to be the Enable pin ?
Code: |
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_E PIN_D0
#define LCD_RS PIN_D1
//#define LCD_RW PIN_D2
|
If you look at the code below with your eyes, what line of code is most
likely to be the one that sets the Enable pin high ?
Code: |
void lcd_send_nibble(int8 nibble)
{
// Note: !! converts an integer expression
// to a boolean (1 or 0).
output_bit(LCD_DB4, !!(nibble & 1));
output_bit(LCD_DB5, !!(nibble & 2));
output_bit(LCD_DB6, !!(nibble & 4));
output_bit(LCD_DB7, !!(nibble & 8));
delay_cycles(1);
output_high(LCD_E);
delay_us(2);
output_low(LCD_E);
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Jun 13, 2014 3:07 pm |
|
|
I can confirm that the flex_lcd.c driver is 100% functional on 8 different PICs and 4 different mfr/makes of 2x16 LCD modules using a wide variety of I/O pins for the control of the LCD modules.
So YES enable does function.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sat Jun 14, 2014 3:08 am |
|
|
Understand though that the enable will only go high for a couple of uSec. It is low 99.9999% of the time, even if you are talking to the LCD quite a lot.
A normal scope won't even see it high, without careful setup of the triggering. A meter will never see it high....
Lets make a simple statement here. flex_lcd, is one of the most reliable bits of software here.
It runs with 99.9999% of standard text mode LCD's.
The only times it doesn't work, are where the person using it has another problem (connections, Vee etc..).
If your PIC is running, and running at the correct speed, and the connections are made correctly, flex_lcd works. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|