Page 1 of 2

LCD Unable to display with SK40C

PostPosted: Fri Jan 12, 2018 3:45 pm
by aru
I can get the LCD display working properly when connecting LCD externally instead of using the port provided in SK40C.
Used PORTD for DATA and PORTA for LCD control. No issues.

When I connected the LCD to the LCD port provided in SK40C, it is unable to work. LCD powering and contrast adjust ok.
I changed the control port setting to PORTB.
I also made the changes to the XCLD.h library to reflect the correct port pins.

It is just a simple program showing "Hello World".

Using 18F4550 device.

Need help.

Re: LCD Unable to display with SK40C

PostPosted: Fri Jan 12, 2018 4:53 pm
by Idris
Hi aru,

A few clear photos of your hardware setup can help others to verify the problem.

Thanks.

Re: LCD Unable to display with SK40C

PostPosted: Mon Jan 15, 2018 9:00 am
by aru
Capture.JPG
Capture.JPG (41.16 KiB) Viewed 7006 times

Hi, Idris
I have posted the picture of the hardware connection as above. Thanks for your response.

Following is the code:

#include <P18F4550.h>
#include<xlcd.h> //built-in LCD library
#include<delays.h>
#pragma config FOSC = XT_XT, PWRT = ON, MCLRE = ON
#pragma config WDT = OFF, PBADEN = OFF, LVP = OFF
//The built library for using LCD requires that we provide 3 types of
//delays - 15mS, 18Cycles, 5mS.
void DelayPORXLCD(void) //15mS delay
{
Delay1KTCYx(15);
}
void DelayFor18TCY(void) //18 cycle delay
{
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
Nop(); Nop();
}
void DelayXLCD(void) //5mS delay
{
Delay1KTCYx(5);
}
void main(void)
{
ADCON1=0x0F; //PORTB digital
TRISD=0; //outputs
TRISB=0;

OpenXLCD(EIGHT_BIT & LINES_5X7); //LCD set-up

while(BusyXLCD( ));
WriteCmdXLCD(0x0C); //on display, off cursor

while(BusyXLCD( ));
SetDDRamAddr(0x82); //character start position

while(BusyXLCD( ));
WriteCmdXLCD(SHIFT_DISP_LEFT); //cursor moves right
//for each character

putrsXLCD("Hello World!"); //string placed in ROM

while(1);
}

Following is the Project Set up:

Re: LCD Unable to display with SK40C

PostPosted: Mon Jan 15, 2018 9:14 am
by aru
Following are the modifications made to xlcd.h library file to comply with the hardware connections.

/* Interface type 8-bit or 4-bit
* For 8-bit operation uncomment the #define BIT8
*/
#define BIT8

/* When in 4-bit interface define if the data is in the upper
* or lower nibble. For lower nibble, comment the #define UPPER
*/
/* #define UPPER */

/* DATA_PORT defines the port to which the LCD data lines are connected */
#define DATA_PORT PORTD
#define TRIS_DATA_PORT TRISD

/* CTRL_PORT defines the port where the control lines are connected.
* These are just samples, change to match your application.
*/
#define RW_PIN LATBbits.LATB3 /* PORT for RW */
#define TRIS_RW TRISBbits.TRISB3 /* TRIS for RW */

#define RS_PIN LATBbits.LATB4 /* PORT for RS */
#define TRIS_RS TRISBbits.TRISB4 /* TRIS for RS */

#define E_PIN LATBbits.LATB5 /* PORT for D */
#define TRIS_E TRISBbits.TRISB5 /* TRIS for E */

Re: LCD Unable to display with SK40C

PostPosted: Mon Jan 15, 2018 6:59 pm
by Idris
Hi aru,

Thanks for the photo and coding. It takes sometimes for me to verify with the coding. Anyway, for now my advise is try to clean up a bit at the soldering area - LCD pin (top and bottom).

IMG_6441.jpg

IMG_6442.jpg

Re: LCD Unable to display with SK40C

PostPosted: Tue Jan 16, 2018 5:59 am
by ober
I don think setting Tris is sufficient. TRIS is just direction bit, but where is the actual port bit for RB4 and RB5? And of course whole PORTD.

Re: LCD Unable to display with SK40C

PostPosted: Tue Jan 16, 2018 11:21 am
by bengchet
Hi,

CODE: SELECT_ALL_CODE
#define DATA_PORT PORTD


CODE: SELECT_ALL_CODE
#define RW_PIN LATBbits.LATB3 /* PORT for RW */
#define E_PIN LATBbits.LATB5 /* PORT for D */


These 2 seems contradict in the way you control your port register status. You might need to check either using PORT or LAT to write status to the registers.

**PS: If you confirmed previously PORTD is working, then you might need to troubleshoot RW_PIN and E_PIN (you are using LAT to control pin status). You can write a simple LED blinking program using either 2 of those pins something like below.

CODE: SELECT_ALL_CODE
while(1){
   RW_PIN = 1;
   delay --> you delay function;
   RW_PIN = 0;
   delay ;
}

Re: LCD Unable to display with SK40C

PostPosted: Wed Jan 17, 2018 10:43 am
by aru
display.JPG
Ober and bengchet,

Thanks for quickly helping me with this.

Ober,

I used the same code given above, except changing TRISB=0 to TRISA=0.
and changed the control PORTS to
RS - RA0
RW - RA1
E - RA2

The xlcd.h library file was changed as below;

#define RW_PIN LATAbits.LATA1 /* PORT for RW */
#define TRIS_RW TRISAbits.TRISA1 /* TRIS for RW */

#define RS_PIN LATAbits.LATA0 /* PORT for RS */
#define TRIS_RS TRISAbits.TRISA0 /* TRIS for RS */

#define E_PIN LATAbits.LATA2 /* PORT for E */
#define TRIS_E TRISAbits.TRISA2 /* TRIS for E */

Connected the LCD externally instead of using the SK40C LCD port.

The program worked fine and display shows correctly as picture above.

Based on the microchip datasheet, LATx is required only for Read-Modify-Write operations. I have been using TRISx for writing into ports for long and have not seen any problems.

bengchet,

Your input was great.

I corrected the setting in the xlcd.h library as below;
#define RS_PIN LATBbits.LATB4 /* PORT for RS */
#define TRIS_RS TRISBbits.TRISB4 /* TRIS for RS */

#define E_PIN LATBbits.LATB5 /* PORT for E */
#define TRIS_E TRISBbits.TRISB5 /* TRIS for E */

Tested the pins RB5 and RB4 with this library included. The pins flashed the externally connected LEDs correctly as expected. So the pins seem to work fine.

But the LCD will not display when connected to SK40C LCD port, with above changes to xlcd.h library.
In the main code, the only change I did was to change TRISA to TRISB.

I am still not sure what else is causing the problem.
Looking forward to your help.

Re: LCD Unable to display with SK40C

PostPosted: Wed Jan 17, 2018 7:48 pm
by bengchet
Hi,

Mind share the library and coding here for easier troubleshooting? Thanks.

Re: LCD Unable to display with SK40C

PostPosted: Thu Jan 18, 2018 7:42 am
by aru
Hi bengchet,

Here is the C18 code:. Using C18 built-in libraries

#include <P18F4550.h>
#include<xlcd.h> //built-in LCD library
#include<delays.h>
#pragma config FOSC = XT_XT, PWRT = ON, MCLRE = ON
#pragma config WDT = OFF, PBADEN = OFF, LVP = OFF
//The built library for using LCD requires that we provide 3 types of
//delays - 15mS, 18Cycles, 5mS.
void DelayPORXLCD(void) //15mS delay
{
Delay1KTCYx(15);
}
void DelayFor18TCY(void) //18 cycle delay
{
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
Nop(); Nop();
}
void DelayXLCD(void) //5mS delay
{
Delay1KTCYx(5);
}
void main(void)
{
ADCON1=0x0F; //PORTB digital
TRISD=0; //outputs
TRISB=0;

OpenXLCD(EIGHT_BIT & LINES_5X7); //LCD set-up

while(BusyXLCD( ));
WriteCmdXLCD(0x0C); //on display, off cursor

while(BusyXLCD( ));
SetDDRamAddr(0x82); //character start position

while(BusyXLCD( ));
WriteCmdXLCD(SHIFT_DISP_LEFT); //cursor moves right
//for each character

putrsXLCD("Hello World!"); //string placed in ROM

while(1);
}

Here is the Project Set up;

Project Set up.JPG
Project Set up.JPG (23.48 KiB) Viewed 6960 times


Here are the changes made to xlcd.h library

#define BIT8

/* When in 4-bit interface define if the data is in the upper
* or lower nibble. For lower nibble, comment the #define UPPER
*/
/* #define UPPER */

/* DATA_PORT defines the port to which the LCD data lines are connected */
#define DATA_PORT PORTD
#define TRIS_DATA_PORT TRISD

/* CTRL_PORT defines the port where the control lines are connected.
* These are just samples, change to match your application.
*/
#define RW_PIN LATBbits.LATB3 /* PORT for RW */
#define TRIS_RW TRISBbits.TRISB3 /* TRIS for RW */

#define RS_PIN LATBbits.LATB4 /* PORT for RS */
#define TRIS_RS TRISBbits.TRISB4 /* TRIS for RS */

#define E_PIN LATBbits.LATB5 /* PORT for E */
#define TRIS_E TRISBbits.TRISB5 /* TRIS for E */


Thanks for your help.