0

LCD PCD 8544 display issue
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

LCD PCD 8544 display issue

by phetal on Sun Jun 18, 2017 1:04 pm

I have been scratching my head since couple of days to solve a lcd display issue.

Problem-1:
As I read from the datasheet of PCD8544, I can set x, y position to (0, 0) by writing command 0x80 and 0x40.
However upon restart when I write these commands and then display any pattern, it seem to be displaying at different location (almost at x=73, y = 0) when I keep on writing then after it continue to write till last pixel (bottom right corner) and then rolls back to top left. If i write exactly 504 data, it covers whole LCD but the start position is not as expected (0,0). Any clue or pointer what could be going wrong?
PS: If I don't write (0,0) upon restart and directly start writing data, it starts writing from the first pixel of the lcd as expected :(

Problem-2:
If I want to write some data
i.e. write data to first byte of first row, second byte of second row, third byte of third row and so on....

I see that it writes to the first and second row correctly but it does not write anything to third row and instead it writes to forth row twice. Also it does not write anything to 5th and 6th row. Then it rolls back to 1st row and continue writing

Any clue why it does not display any data on 3rd, 5th and 6th row when I explicitly set the y position?

Problem-3:
upon restart if I write data 0x01, it makes two pixel ON. MSB and LSB as if I have written 0x81, any clue?

phetal
 
Posts: 4
Joined: Sun Jun 18, 2017 12:47 pm

Re: LCD PCD 8544 display issue

by adafruit_support_carter on Mon Jun 19, 2017 11:25 am

Without seeing your code, it's hard to say what might be going on. Also, there are libraries you can use to run this display.
Arduino:
https://github.com/adafruit/Adafruit-PC ... CD-library
Python (for Pi, etc.):
https://github.com/adafruit/Adafruit_Nokia_LCD

adafruit_support_carter
 
Posts: 2531
Joined: Tue Nov 29, 2016 2:45 pm

Re: LCD PCD 8544 display issue

by phetal on Mon Jun 19, 2017 12:17 pm

Attaching the code....

============= main.c ========================
Code: Select all | TOGGLE FULL SIZE
#include <pic18f45k40.h>
#include "config.h"
//#include "switch_matrix.h"
//#include "queue.h"
#include "lcd.h"

#define LED1_LATBIT LATAbits.LATA1
#define LED1_PORTBIT PORTAbits.RA1

#define LED2_LATBIT LATAbits.LATA2
#define LED2_PORTBIT PORTAbits.RA2

void main(void) {

   OSCFRQbits.HFFRQ = 0b0011;   //8MHZ clock

    LATDbits.LATD2 = 1;     //LCD_POWER_ON_OFF

    init_lcd_if();

    unsigned char y_pos = 0;
    unsigned char x_pos = 0;

    __delay_ms(100);
    set_xy_pos(0, 0);

    while (1)
    {
        //buf full, read and flush
        proc_lcd_data();
        __delay_ms(100);

        x_pos++;

        if(x_pos > 83) {
            x_pos = 0;
            y_pos++;

            if(y_pos > 5) {
                y_pos = 0;
            }
        }
        set_xy_pos(x_pos, y_pos);
    }
    return;
}


====================== lcd.h =======================
Code: Select all | TOGGLE FULL SIZE
#ifndef LCD_H
#define LCD_H

#ifdef  __cplusplus
extern "C" {
#endif

    typedef enum LCD_STATE
    {
        LCD_INIT = 0,
        LCD_IDLE,
        LCD_DATA_WRITE,
        LCD_CMD_WRITE,
    };


    void init_lcd_if(void);
    void clear_lcd_disp(void);
    void write_lcd_cmd(void);
    void send_lcd_data(unsigned char data);
    void set_display_off();
    void set_display_on();
    void set_xy_pos(unsigned char x, unsigned char y);

    void proc_lcd_data(void);



#ifdef  __cplusplus
}
#endif

#endif  /* LCD_H */


======================== lcd.c =========================
Code: Select all | TOGGLE FULL SIZE
#include <pic18f45k40.h>
#include "config.h"
#include "lcd.h"
//#include "queue.h"

#define LCD_COMMAND LATDbits.LATD1 = 0;
#define LCD_DATA LATDbits.LATD1 = 1;
#define LCD_CS(level) LATAbits.LA5 = level;

#define HIGH 1
#define LOW  0

static void send_lcd_cmd(unsigned char cmd);

void init_lcd_if(void)
{
    ANSELDbits.ANSELD1 = 0;     //MODE Select, 0:Cmd, 1:Data
    TRISDbits.TRISD1 = 0;

    ANSELDbits.ANSELD2 = 0;     //LCD_ON_OFF
    TRISDbits.TRISD2 = 0;

    ANSELDbits.ANSELD3 = 0;     //RESET, Active low
    TRISDbits.TRISD3 = 0;
 //   LATDbits.LATD3 = 1;

    ANSELCbits.ANSELC3 = 0;     //CLK
    TRISCbits.TRISC3 = 0;

    ANSELCbits.ANSELC5 = 0;     //MOSI
    TRISCbits.TRISC5 = 0;

    ANSELAbits.ANSELA5 = 0;     //CS, Active low
    TRISAbits.TRISA5 = 0;

    //MOSI
    RC5PPS = 0b10000;
    //CLK
    RC3PPS = 0b01111;

    //config SPI registers

    SSP1STATbits.SMP = 1;
    SSP1CON1bits.WCOL = 0;  //no collision
    SSP1CON1bits.SSPOV = 0; //no overflow

    SSP1CON1bits.CKP = 0;   //idle state for the clock is a low level
    SSP1CON1bits.SSPM = 0b0010;  //clock = FOSC/64


    SSP1CON1bits.SSPEN = 1;

    PIE3bits.SSP1IE = 0;       //SPI int enabled

    //SS bit always on, SP_DEBUG
    LCD_CS(HIGH);
    __delay_ms(10);
    LCD_CS(LOW);        //Keep the CS enabled always

    LATDbits.LATD3 = 0;     //LCD_RESET
    __delay_ms(10);
    LATDbits.LATD3 = 1;     //LCD_RESET

    LCD_COMMAND;
    SSP1BUF = 0x00;

    send_lcd_cmd(0x21);
    send_lcd_cmd(0x13);
    send_lcd_cmd(0x07);
    send_lcd_cmd(0x80);
    send_lcd_cmd(0x20);
    send_lcd_cmd(0x0C);     //Normal mode

    clear_lcd_disp();
}

static void send_lcd_cmd(unsigned char cmd)
{
    while(!(SSP1STAT & 0x01));
    unsigned char temp = SSP1BUF;


    LCD_COMMAND;
    LCD_CS(LOW);
    SSP1BUF = cmd;

//    LCD_CS(HIGH);
}

void send_lcd_data(unsigned char data)
{
    while(!(SSP1STAT & 0x01));
    unsigned char temp = SSP1BUF;

    LCD_DATA;
    LCD_CS(LOW);
    SSP1BUF = data;
//    LCD_CS(HIGH);
}

void set_display_off()
{
    send_lcd_cmd(0x08);     //Normal mode
}

void set_display_on()
{
    send_lcd_cmd(0x0C);     //Normal mode
}
void clear_lcd_disp(void)
{

    for(int i = 0; i < 504; i++) {
        while(!(SSP1STAT & 0x01));
        unsigned char temp = SSP1BUF;
        LCD_DATA;
        LCD_CS(LOW);
        SSP1BUF = 0x00;
//        LCD_CS(HIGH);
    }
//    LCD_CS(HIGH);
}

void proc_lcd_data(void)
{
    while(!(SSP1STAT & 0x01));
    unsigned char temp = SSP1BUF;

    LCD_DATA;
//    LCD_CS(LOW);
    SSP1BUF = 0xFC;
}

void set_xy_pos(unsigned char x, unsigned char y)
{
    send_lcd_cmd(0x40 | y);
//    send_lcd_cmd(0x80 | x);
}

phetal
 
Posts: 4
Joined: Sun Jun 18, 2017 12:47 pm

Re: LCD PCD 8544 display issue

by adafruit_support_carter on Mon Jun 19, 2017 12:26 pm

Appears to be Arduino. Does the example sketch work normally?
https://github.com/adafruit/Adafruit-PC ... cdtest.ino

EDIT: Wait. No it's just straight C. Do you have an Arduino you could test with?

adafruit_support_carter
 
Posts: 2531
Joined: Tue Nov 29, 2016 2:45 pm

Re: LCD PCD 8544 display issue

by phetal on Mon Jun 19, 2017 12:41 pm

Hey,

I dont have Arduino else I would have tested with the lib available.
I am using PIC controller.

Appreciate any pointers!

/HP

phetal
 
Posts: 4
Joined: Sun Jun 18, 2017 12:47 pm

Re: LCD PCD 8544 display issue

by phetal on Mon Jun 19, 2017 12:51 pm

Little more explanation about scenarios in which I am facing issues.....

Scenario-1:
If I don't set x,y position at start up and during the while loop,
- comment both the set_xy_pos(0, 0); and set_xy_pos(x_pos, y_pos); in the main.c

It works fine!!! It starts displaying from the first pixel till end.

Please see Scenario1 image

Scenario-2:
If I just set the x,y position to zero at start up only it starts from the pixel appx. at (x=73, y=0).
However it rolls back to the first line and completes the loop but
as per my understanding it should start from the first pixel itself.
Pls see the image scenario2_1 and Scenario2_2

Scenario-3:
If I dont set the x,y position at start up (first set_xy_pos(0,0)) and only set the Y position within while loop.

I see that it starts to display from first pixel but does not display all the rows.
It just displays 1st, 2nd and 4th rows only rest remains blank

Pls see Scenario3 image

Scenario-4:
I dont set x,y position in the code by commenting both the set_xy_pos.
Write 0x01 data instead of 0xFC (function proc_lcd_data()), it shows as if data was written as 0x81 and shows the MSB and LSB pixel ON.
I am expecting only LSB pixel to be ON.

pls see Scenario4 image
Attachments
Scenario2_3.jpeg
Scenario2_3.jpeg (44.94 KiB) Viewed 75 times
Scenario2_1.jpeg
Scenario2_1.jpeg (40.51 KiB) Viewed 75 times
Scenario1.jpeg
Scenario1.jpeg (39.67 KiB) Viewed 75 times

phetal
 
Posts: 4
Joined: Sun Jun 18, 2017 12:47 pm

Re: LCD PCD 8544 display issue

by adafruit_support_carter on Mon Jun 19, 2017 1:04 pm

You could use the Arduino library as a reference:
https://github.com/adafruit/Adafruit-PC ... CD8544.cpp

adafruit_support_carter
 
Posts: 2531
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.