Build succesfull in MPLABX but its displaying the Character in GLCD

Status
Not open for further replies.

thunaivendan

Member level 3
Joined
Apr 19, 2013
Messages
61
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,288
Location
Chennai, Tamil Nadu, India
Activity points
1,728
Code:
/*
 * File:   graphics_LCD.c
 * Author: thunai
 *
 * Created on October 22, 2023, 2:37 PM
 */

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include "glcd.h"
// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 20000000
#endif
#define GlcdDataBus      PORTB
#define GlcdControlBus   PORTD

#define GlcdDataBusDirnReg   TRISB
#define GlcdCtrlBusDirnReg   TRISD

#define RS     0
#define RW     1
#define EN     2
#define CS1    3
#define CS2    4

/* 5x7 Font including 1 space to display HELLO WORLD */
char H[]={0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00};
char E[]={0x7F, 0x49, 0x49, 0x49, 0x41, 0x00};
char L[]={0x7F, 0x40, 0x40, 0x40, 0x40, 0x00};
char O[]={0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00};

char W[]={0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00};
char R[]={0x7F, 0x09, 0x19, 0x29, 0x46, 0x00};
char D[]={0x7F, 0x41, 0x41, 0x22, 0x1C, 0x00};


/* local function to generate delay */
void delay(int cnt)
{
   int i;
    for(i=0;i<cnt;i++);
}


void Glcd_SelectPage0() // CS1=1, CS2=0
{
    GlcdControlBus |= (1<<CS1);
    GlcdControlBus &= ~(1<<CS2);
}

void Glcd_SelectPage1() // CS1=0, CS1=1
{
    GlcdControlBus &= ~(1<<CS1);
    GlcdControlBus |= (1<<CS2);
}

/* Function to send the command to LCD */
void Glcd_CmdWrite(char cmd)
{
    GlcdDataBus = cmd;           //Send the Command nibble
    GlcdControlBus &= ~(1<<RS);  // Send LOW pulse on RS pin for selecting Command register
    GlcdControlBus &= ~(1<<RW);  // Send LOW pulse on RW pin for Write operation
    GlcdControlBus |= (1<<EN);   // Generate a High-to-low pulse on EN pin
    delay(100);
    GlcdControlBus &= ~(1<<EN);

    delay(5000);
}

/* Function to send the Data to LCD */
void Glcd_DataWrite(char dat)
{
    GlcdDataBus = dat;           //Send the data on DataBus nibble
    GlcdControlBus |= (1<<RS);   // Send HIGH pulse on RS pin for selecting data register
    GlcdControlBus &= ~(1<<RW);  // Send LOW pulse on RW pin for Write operation
    GlcdControlBus |= (1<<EN);   // Generate a High-to-low pulse on EN pin
    delay(100);
    GlcdControlBus &= ~(1<<EN);

    delay(5000);
}

void Glcd_DisplayChar(char *ptr_array)
{
    int i;
    for(i=0;i<6;i++) // 5x7 font, 5 chars + 1 blankspace
        Glcd_DataWrite(ptr_array);
}


int main()
{
    GlcdDataBusDirnReg = 0x00;  // Configure all the LCD pins as output
    GlcdCtrlBusDirnReg = 0x00;  // Configure the Ctrl pins as output

    /* Select the Page0/Page1 and Turn on the GLCD */
    Glcd_SelectPage0();
    Glcd_CmdWrite(0x3f);
    Glcd_SelectPage1();
    Glcd_CmdWrite(0x3f);
    delay(1000);

    /* Select the Page0/Page1 and Enable the GLCD */
    Glcd_SelectPage0();
    Glcd_CmdWrite(0xc0);
    Glcd_SelectPage1();
    Glcd_CmdWrite(0xc0);
    delay(1000);

    Glcd_SelectPage0(); // Display HELLO on Page0, Line1
    delay(1000);
    Glcd_CmdWrite(0xb8);
    delay(1000);
    Glcd_DisplayChar(H);
    Glcd_DisplayChar(E);
    Glcd_DisplayChar(L);
    Glcd_DisplayChar(L);
    Glcd_DisplayChar(O);

    Glcd_SelectPage1(); // Display WORLD on Page1, Last line
    delay(1000);
    Glcd_CmdWrite(0xbF);
    delay(1000);
    Glcd_DisplayChar(W);
    Glcd_DisplayChar(O);
    Glcd_DisplayChar(R);
    Glcd_DisplayChar(L);
    Glcd_DisplayChar(D);

    while(1);
}
  
//#include "delay.h"

//#define DELAY_TIME 3


//void main() 
//{
//    int num = 1234;
//    GLCD_Init();
//
//    while (1) 
//    {
//        GLCD_Clear();
//        GLCD_DisplayLogo(LogoBitMap);
//        //DELAY_sec(DELAY_TIME);
//        __delay_ms(5000);
//        GLCD_Clear();
//        GLCD_Printf("Dec:%d \nHex:%x \nBin:%b \nFloat:%f", num, num, num, 4567.89);
//        //DELAY_sec(DELAY_TIME);
//
//        GLCD_Clear();
//        GLCD_HorizontalGraph(0, 45);
//        GLCD_HorizontalGraph(1, 50);
//        GLCD_HorizontalGraph(2, 82);
//        GLCD_HorizontalGraph(3, 74);
//        //DELAY_sec(DELAY_TIME);
//        __delay_ms(5000);
//        GLCD_Clear();
//        GLCD_VerticalGraph(0, 45);
//        GLCD_VerticalGraph(1, 50);
//        GLCD_VerticalGraph(2, 82);
//        GLCD_VerticalGraph(3, 74);
//       // DELAY_sec(DELAY_TIME);
//        __delay_ms(5000);
//    }
//}
 
Last edited by a moderator:
Hello!

If it's a simulator, why not sharing the simulator itself? I guess some experienced users could
make it work in no time.
Beside this, there are a few fishy things.
It's a graphic LCD, so this intstruction: glcd_display_char('H') is not right as stated above.
This function expects a character array. In other word you give it the memory location of some
data used to write your character. Someone explained above how this works.
In this instruction if you give 'H' as the address, the system will try to locate address 0x48
which is 'H' and use this location as the beginning of an array. Even if the compiler didn't detect
an error, you would get garbage.
When done properly, it will look like this, for example.
When you send the array H : char H[]={0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00};
When you send 0x7F, you will get:










When you send 0x08 3 times, you will get:




****




And when you send the last 0c7F, you will get:

*   *
*   *
*   *
*****
*   *
*   *
*   *

The last character (0) will create a space.

About your code
- It would be nice to write ONLY the code you need. FOSC is never used. Remove it or at least comment it out.
Same for _XTAL_FREQ, etc...

- Usually the #define statements like ports are in capital letters. Use for instance DATA_PORT or
LCD_DATA_PORT instead of GlcdDataBus which looks like a function. You can #define in lower case
letters if it's indeed used as a function. Example:
#define SetCmdMode() CTRL_PORT |= (1<<RS)

- By the way, why not defining RS like this:
#define RS 0x01
#define RW 0x02
#define EN 0x04
etc...
instead of dragging shifts all the time?
The (1 << RS) becomse simply RS

- You might be confused regarding what a nibble is. A nibble is half of a byte. In your code, you simply
set a byte, not only a nibble.

- You write 2 functions that are exactly the same (Glcd_CmdWrite and Glcd_DataWrite) except one line
for register select (data or cmd). This takes space for nothing. Why not:
// For writing a command
SetCmdMode();
LCDWriteByte(cmd)
// For writing data
SetDataMode();
LCDWriteByte(data)

- Are you really using the RW bit? If not, you can set it to 0 once for all and never use it in the whole
program.

- You use a 100 ms strobe pulse. That's what I call a conservative value. You need about 500 ns.
A few _nop() would do it.

- You should not use a 5 second delay in a write function. If it's a delay allowing to watch what
happens, it should be outside of the write function. Do for example:
LCD_Write(some value)
Delay(5000);

You might be interested in having a look at the hardware driver you are using.

Have fun!

Dora
 

Hi,

again the picture is so small we can even detect the text.
This way it´s rater useless.

Klaus
 

Help me out in this GLCD interface,I didnot get the output in proteus
 

Attachments

  • Screenshot 2023-11-05 144147.jpg
    191.8 KB · Views: 68
  • delay.txt
    4.4 KB · Views: 84
  • GLCD.txt
    39.6 KB · Views: 85
  • graphics_LCD_text.txt
    4.5 KB · Views: 88

I don't use Proteus but if it observes timings accurately, the delay routines probably wont work. I doubt an instruction delay is 1uS when the clock is specified as 20MHz (in Graphics_LCD_text.txt).

Except for the shortest delays I suggest using timer interrupts.

Brian.
 

Hello!
No hurt intended, but.... you have been on this for more than 2 weeks, and there is not much happening
in your source code. And your LCD might be incompletely initialized. From what I found by searching for
some source code for AMPIRE12864, your initilaization is not complete. That said, I'm not sure a simulator
needs an initialization.
But beside this, your code is not commented out. Are you expecting the readers to do the code for you?
To check the datasheet for you?
For example, what is the command Glcd_CmdWrite(0x3F) doing? What is the command C0? Etc, etc
Most of the LCDs I have played with have a full init code in their docs.
I will not check, anyway. Come back when you have done something.

Dora.
 

I got the code from below site:

please helpme out the attached code is correct
 

I woudl certainly NOT call the code in that web page you link to 'correct'. It is open to so many RWM errors that it is not funny.
Also if you look at the comments towards the bottom there are others that say they do not get anything displayed. They also mention that the \RST\ pin is not connected and neither is yours. You might try holginh it high but personally I would connect it to a pin, take it low on power-on and then take it high to ensure that the deisplay is correctly reset.
Susan
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…