Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Build succesfull in MPLABX but its displaying the Character in GLCD

thunaivendan

Member level 3
Joined
Apr 19, 2013
Messages
55
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,288
Location
Chennai, Tamil Nadu, India
Activity points
1,667
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);
//    }
//}
1698128081699.png
 
Last edited by a moderator:
You wrote "its displying the charcter"
Isn't this what you want?

Please give detailed description.
* in simulation / real world?
* test conditions
* what you expect
* what not is like expected

Klaus
 
I can't see the LCD type clearly but are you sure the delays are the correct length. Your delay() function counts instruction execution times rather than real time and with a 20MHz clock they may not be long enough.
Use the debugger to check their real-time delays.

Brian.
 
You wrote "its displying the charcter"
Isn't this what you want?

Please give detailed description.
* in simulation / real world?
* test conditions
* what you expect
* what not is like expected

Klaus

Build succesfull in MPLABX but its not displaying the Character in GLCD​

--- Updated ---

Am
I can't see the LCD type clearly but are you sure the delays are the correct length. Your delay() function counts instruction execution times rather than real time and with a 20MHz clock they may not be long enough.
Use the debugger to check their real-time delays.

Ampire12864
 
Hi,

If you don't even spend the time to state whether you talk about simulation or a real circuit...I also don't spend time..
Why do you make it hard to get good assistance?

Klaus
 
Hi,

If you don't even spend the time to state whether you talk about simulation or a real circuit...I also don't spend time..
Why do you make it hard to get good assistance?

Klaus
I am talking about in the simulation I didn't get the output,I don't have hardware
 
Despite of other possible problems, Glcd_DisplayChar() isn't sendig pixel data. Should be:
Code:
void Glcd_DisplayChar(char *ptr_array)
{
    int i;
    for(i=0;i<6;i++) // 5x7 font, 5 chars + 1 blankspace
        Glcd_DataWrite(*ptr_array++);
}
 
In addition that the standard call for character arguments are supposed to be enclosed within apostrophes ('), not raw as done above:

Code:
Glcd_DisplayChar(W);
Glcd_DisplayChar(O);
Glcd_DisplayChar(R);
Glcd_DisplayChar(L);
Glcd_DisplayChar(D);
 
That's o.k. Argument of Glcd_DisplayChar() is a pixel array, not a char value.

It's an elementary test. The real glcd graphic char print routine isn't yet used.
 
Despite of other possible problems, Glcd_DisplayChar() isn't sendig pixel data. Should be:
Code:
void Glcd_DisplayChar(char *ptr_array)
{
    int i;
    for(i=0;i<6;i++) // 5x7 font, 5 chars + 1 blankspace
        Glcd_DataWrite(*ptr_array++);
}
This code is specified in both the pages right
 
This might work in a simulator (putting aside all of the potential bugs that a simulator will add over and above any real hardware) but you will have real trouble with real hardware.
For a start, the PIC16F877A does not have LAT registers and so you will definitely run into RMW issues with your Glcd_CmdWrite() and Glcd_DataWrite() (and other) functions where you use RMW instructions in successive lines of code.
Secondly, any half-way decent compiler (even with the lowest level of optimisation) will make your 'delay' function one big NOOP and therefore not provide you with any delay at all. You are using the XC8 compiler so use the built-in delay functions. After all you define the _XTAL_FREQ symbol but that is ONLY used in the 'delay' macros - it doers NOT set the oscillator frequency.
Where do you initialise the GLCD - there is something in the commented out 'main()' function but not in the 'working' version.
I can't see where you initialise the TRISx registers. By default they will all be set to digital input and some to analog.
One last thing - if you can I suggest that you use PortC rather than Port B at least for the initial testing on real hardware. the reason is that RB6 and RB7 are used for both programming (not such an issue) and debugging - and I suspect that you will certainly need to debug this code.
Susan
 
In addition that the standard call for character arguments are supposed to be enclosed within apostrophes ('), not raw as done above:

Code:
Glcd_DisplayChar(W);
Glcd_DisplayChar(O);
Glcd_DisplayChar(R);
Glcd_DisplayChar(L);
Glcd_DisplayChar(D);
--- Updated ---

1698475239565.png


I am facing this error while aphostephy used
 
To which code do you refer? As I told, Glcd_DisplayChar() call in post #1 is o.k. Function body however isn't, see post #9.
#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_ms(100);
GlcdControlBus &= ~(1<<EN);

__delay_ms(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_ms(100);
GlcdControlBus &= ~(1<<EN);

__delay_ms(1000);
}

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

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_Init();
Glcd_SelectPage0();
Glcd_CmdWrite(0x3f);
Glcd_SelectPage1();
Glcd_CmdWrite(0x3f);
__delay_ms(5000);

/* Select the Page0/Page1 and Enable the GLCD */

Glcd_SelectPage0();
Glcd_CmdWrite(0xc0);
Glcd_SelectPage1();
Glcd_CmdWrite(0xc0);
__delay_ms(5000);

Glcd_SelectPage0(); // Display HELLO on Page0, Line1
__delay_ms(5000);
Glcd_CmdWrite(0xb8);
__delay_ms(5000);
Glcd_DisplayChar('H');
Glcd_DisplayChar('E');
Glcd_DisplayChar('L');
Glcd_DisplayChar('L');
Glcd_DisplayChar('O');
Glcd_SelectPage1(); // Display WORLD on Page1, Last line
__delay_ms(5000);
Glcd_CmdWrite(0xbF);
__delay_ms(5000);
Glcd_DisplayChar('W');
Glcd_DisplayChar('O');
Glcd_DisplayChar('R');
Glcd_DisplayChar('L');
Glcd_DisplayChar('D');

while(1);
}

--- Updated ---

#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_ms(100);
GlcdControlBus &= ~(1<<EN);

__delay_ms(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_ms(100);
GlcdControlBus &= ~(1<<EN);

__delay_ms(1000);
}

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

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_Init();
Glcd_SelectPage0();
Glcd_CmdWrite(0x3f);
Glcd_SelectPage1();
Glcd_CmdWrite(0x3f);
__delay_ms(5000);

/* Select the Page0/Page1 and Enable the GLCD */

Glcd_SelectPage0();
Glcd_CmdWrite(0xc0);
Glcd_SelectPage1();
Glcd_CmdWrite(0xc0);
__delay_ms(5000);

Glcd_SelectPage0(); // Display HELLO on Page0, Line1
__delay_ms(5000);
Glcd_CmdWrite(0xb8);
__delay_ms(5000);
Glcd_DisplayChar('H');
Glcd_DisplayChar('E');
Glcd_DisplayChar('L');
Glcd_DisplayChar('L');
Glcd_DisplayChar('O');
Glcd_SelectPage1(); // Display WORLD on Page1, Last line
__delay_ms(5000);
Glcd_CmdWrite(0xbF);
__delay_ms(5000);
Glcd_DisplayChar('W');
Glcd_DisplayChar('O');
Glcd_DisplayChar('R');
Glcd_DisplayChar('L');
Glcd_DisplayChar('D');

while(1);
}
1698492870068.png

throw this error while add an function which you shared
 
Last edited:

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top