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.

Variables are not displaying on the LCD

Status
Not open for further replies.

ADGAN

Full Member level 5
Full Member level 5
Joined
Oct 9, 2013
Messages
295
Helped
4
Reputation
8
Reaction score
4
Trophy points
18
Visit site
Activity points
1,837
Hi! I have written a code to display date and energy consumption for a project using MPLAB C18. Everything displays perfectly in Proteus but when I tested in real hardware variables such as date, time doesn't display on the LCD. I tried a MikroC example code and it displays everything perfectly. Can somebody explain me what I may have done wrong? I'll post some necessary parts of the code below.

Code:
#include <p18cxxx.h>
#include "LCD.h"
#include "LCD_Config.h"

//#pragma udata
union LCDv8bit LCD_data;         // bitfield variable (bitwise acess)
unsigned short LCD_busy_cnt;

// -------------------- LCD-functions ------------------------------------------
#ifdef LCD_ON

void LCD_On (void)
{
    LCD_ON = 1;
    LCD_ON_DIR = 0;
#warning DO NOT FORGET TO SWITCH ON THE DISPLAY AND TO ADD A POWER UP DELAY !
}
#endif


void LCD_Init (void)
{
    LCD_RW = 0; LCD_RW_DIR = 0;
    LCD_RS = 0; LCD_RS_DIR = 0;
    LCD_E  = 0; LCD_E_DIR  = 0;

    LCD_D4_OUT = 0; LCD_D4_DIR = 0;
    LCD_D5_OUT = 0; LCD_D5_DIR = 0;
    LCD_D6_OUT = 0; LCD_D6_DIR = 0;
    LCD_D7_OUT = 0; LCD_D7_DIR = 0;

    LCD_busy_cnt = 1;		// busy_flag time out counter

    LCD_DELAY_5MS();LCD_DELAY_5MS();LCD_DELAY_5MS();    // wait for 15ms
// display reset procedure
    LCD_Write_Nibble(LCD_RESET);    LCD_DELAY_5MS();
    LCD_Write_Nibble(LCD_RESET);    LCD_DELAY_5MS();
    LCD_Write_Nibble(LCD_RESET);    LCD_DELAY_5MS();
// set 4-bit mode always !!!
    LCD_Write_Nibble(FOUR_BIT);     while (LCD_Busy()) {;} // wait


#if defined EXT_LCD_3_3_V
    LCD_Command(FOUR_BIT_TWO_LINE + EXT_INSTR_TBL_1);
    LCD_Command(EXT1_BIAS_1_5);
    LCD_Command(EXT1_CONTRAST + 0x0C);
    LCD_Command(EXT1_BOOST_ICON_C + BOOST_ON + 1);
    LCD_Command(EXT1_FOLLOWER + FOLLOWER_ON + 5);
#elif defined EXT_LCD_5_V
    LCD_Command(FOUR_BIT_TWO_LINE + EXT_INSTR_TBL_1);
    LCD_Command(EXT1_BIAS_1_4);
    LCD_Command(EXT1_CONTRAST + 0x04);
    LCD_Command(EXT1_BOOST_ICON_C + BOOST_OFF + 2);
    LCD_Command(EXT1_FOLLOWER + FOLLOWER_ON + 1);
#else
    LCD_Command(FOUR_BIT_TWO_LINE);
#endif

    LCD_Command(DISPLAY_CTRL + DISPLAY_ON);// + BLINK_ON);
    LCD_Command(ENTRY_MODE + CURSOR_INC + DSHIFT_OFF);
    LCD_Command(CLEAR_DISPLAY);
    LCD_Command(RETURN_HOME);
}
// --------------------------------------------------------------

void LCD_signalsTest()
{
    LCD_RS_DIR = 0;
    LCD_RW_DIR = 0;
    LCD_E_DIR = 0;
    LCD_D4_DIR = 0;
    LCD_D5_DIR = 0;
    LCD_D6_DIR = 0;
    LCD_D7_DIR = 0;

    LCD_RS = 1;
    LCD_RW = 1;
    LCD_ENABLE();
    LCD_D4_OUT = 1;
    LCD_D5_OUT = 1;
    LCD_D6_OUT = 1;
    LCD_D7_OUT = 1;

    LCD_RS = 0;
    LCD_RW = 0;
    LCD_DISABLE();
    LCD_D4_OUT = 0;
    LCD_D5_OUT = 0;
    LCD_D6_OUT = 0;
    LCD_D7_OUT = 0;
}


void LCD_Write_Nibble(unsigned char value)
{
    LCD_data.all = value;
    LCD_RS = LCD_CMD;
    LCD_RW = LCD_WR;

    LCD_D4_OUT = LCD_data.bit4;
    LCD_D5_OUT = LCD_data.bit5;
    LCD_D6_OUT = LCD_data.bit6;
    LCD_D7_OUT = LCD_data.bit7;
    LCD_STROBE();
}
// --------------------------------------------------------------

void LCD_Write(unsigned char value) // command or data
{
    LCD_data.all = value;
    LCD_RW = LCD_WR;

    LCD_D7_OUT = LCD_data.bit7;
    LCD_D6_OUT = LCD_data.bit6;
    LCD_D5_OUT = LCD_data.bit5;
    LCD_D4_OUT = LCD_data.bit4;
    LCD_STROBE();

    LCD_D7_OUT = LCD_data.bit3;
    LCD_D6_OUT = LCD_data.bit2;
    LCD_D5_OUT = LCD_data.bit1;
    LCD_D4_OUT = LCD_data.bit0;
    LCD_STROBE();
}
// --------------------------------------------------------------


void LCD_ConstTextOut(unsigned char row, unsigned char col, const char *text)
{
   unsigned char data;
   switch(row){
   case 0: data = ROW_0 + col; break;
   case 1: data = ROW_1 + col; break;
   case 2: data = ROW_2 + col; break;
   case 3: data = ROW_3 + col; break;
   default: break;}

    LCD_Command(CURSOR_ADDR + data);
    while (*text) {
        LCD_CharOut(*text++);
    }
}
// --------------------------------------------------------------

// --------------------------------------------------------------

void LCD_TextOut(unsigned char row, unsigned char col, unsigned char text[])
{
   unsigned char data,i = 0;
   switch(row){
   case 0: data = ROW_0 + col; break;
   case 1: data = ROW_1 + col; break;
   case 2: data = ROW_2 + col; break;
   case 3: data = ROW_3 + col; break;
   default: break;}
    LCD_Command(CURSOR_ADDR + data);
    while (text[i]) {
    LCD_CharOut(text[i++]);
    }
}
//----------------------------------------------------------------

unsigned char LCD_Busy(void)
{
    if (LCD_busy_cnt >= LCD_TIMEOUT){
        LCD_busy_cnt = 1;
        return 0;                   // return -1 for time out ???????????????
    }

    LCD_RW = LCD_RD;
    LCD_RS = LCD_CMD;
    LCD_D4_DIR = 1; LCD_D5_DIR = 1; LCD_D6_DIR = 1; LCD_D7_DIR = 1;

    LCD_ENABLE(); LCD_DELAY_1US();
    LCD_data.bit7 = LCD_D7_IN;
    LCD_DISABLE();
    LCD_ENABLE(); LCD_DELAY_1US();
    LCD_data.bit3 = LCD_D7_IN;
    LCD_DISABLE();

    LCD_D4_DIR = 0; LCD_D5_DIR = 0; LCD_D6_DIR = 0; LCD_D7_DIR = 0;
    LCD_RW = LCD_WR;

    if (LCD_data.bit7 == LCD_BUSY) {
        LCD_busy_cnt++;
        return 1;
    } else {
        LCD_busy_cnt = 1;
        return 0;
    }
}
// -------------------- END LCD-functions ---------------------------

For example to display date on the LCD:
Code:
tnum[0] = day1/10 + 48;
tnum[1] = day1%10 + 48;
tnum[2] = '\0';
LCD_TextOut(2,7,tnum);

To display the energy consumption:
Code:
ultoa(ENERGY_ACT,txt7);
LCD_TextOut(3,3,txt7);
 

Thanks for the reply. I tried it now but still it didn't work.
 

I'm using a 4MHz crystal with PLL enabled.

The original one was:
Code:
#define LCD_DELAY_5MS() Delay10KTCYx(1) 
#define LCD_DELAY_1US() Nop(); Nop(); Nop(); Nop(); Nop();

I modified it to this:
Code:
#define LCD_DELAY_5MS() Delay10KTCYx(28) 
#define LCD_DELAY_1US() Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop();Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop();Nop(); Nop(); Nop(); Nop(); Nop();Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop();Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop();Nop(); Nop(); Nop(); Nop(); Nop();
I really don't know how to calculate these delays.
 

I can't open the link. It says " Error: The requested page could not be found ".
 

Ok I found the pdf. But how do I know the TCY of my PIC? Is it 1/16us? I changed the delays assuming its 1/16us, but still it didn't work.

- - - Updated - - -

I even gave large delays, but still not working. I feel like something else is wrong.:-(
 

Hey Jayanth were you able to find the problem with my code?
 

I told you to include device header file in the source file. If you want me to compile and test then zip and post the whole project file. I don't have patience to create a new project just for testing.
 

I'm really sorry I thought you said to include it here

- - - Updated - - -

I tried it too but didn't work
 

Attachments

  • AEBS.rar
    644.8 KB · Views: 108
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top