LCD Unable to display with SK40C

Programmer, In-Circuit Debugger, PIC Start-Up Kit, Memory Interface...

LCD Unable to display with SK40C

Postby aru » Fri Jan 12, 2018 3:45 pm

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.
aru
Newbie
 
Posts: 15
Joined: Fri Jan 05, 2018 2:53 pm

Re: LCD Unable to display with SK40C

Postby Idris » Fri Jan 12, 2018 4:53 pm

Hi aru,

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

Thanks.
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 328
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

Re: LCD Unable to display with SK40C

Postby aru » Mon Jan 15, 2018 9:00 am

Capture.JPG
Capture.JPG (41.16 KiB) Viewed 119 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:
Attachments
Setup.JPG
Setup.JPG (24.26 KiB) Viewed 118 times
aru
Newbie
 
Posts: 15
Joined: Fri Jan 05, 2018 2:53 pm

Re: LCD Unable to display with SK40C

Postby aru » Mon Jan 15, 2018 9:14 am

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 */
aru
Newbie
 
Posts: 15
Joined: Fri Jan 05, 2018 2:53 pm

Re: LCD Unable to display with SK40C

Postby Idris » Mon Jan 15, 2018 6:59 pm

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
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 328
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

Re: LCD Unable to display with SK40C

Postby ober » Tue Jan 16, 2018 5:59 am

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.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1346
Joined: Wed Apr 15, 2009 1:03 pm

Re: LCD Unable to display with SK40C

Postby bengchet » Tue Jan 16, 2018 11:21 am

Hi,

Code: Select all
#define DATA_PORT PORTD


Code: Select all
#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
while(1){
   RW_PIN = 1;
   delay --> you delay function;
   RW_PIN = 0;
   delay ;
}
bengchet
Moderator
 
Posts: 221
Joined: Tue Aug 25, 2015 8:29 am

Re: LCD Unable to display with SK40C

Postby aru » Wed Jan 17, 2018 10:43 am

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.
aru
Newbie
 
Posts: 15
Joined: Fri Jan 05, 2018 2:53 pm

Re: LCD Unable to display with SK40C

Postby bengchet » Wed Jan 17, 2018 7:48 pm

Hi,

Mind share the library and coding here for easier troubleshooting? Thanks.
bengchet
Moderator
 
Posts: 221
Joined: Tue Aug 25, 2015 8:29 am

Re: LCD Unable to display with SK40C

Postby aru » Thu Jan 18, 2018 7:42 am

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 73 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.
aru
Newbie
 
Posts: 15
Joined: Fri Jan 05, 2018 2:53 pm

Next

Return to PIC Development Tool

Who is online

Users browsing this forum: No registered users and 1 guest