0
\$\begingroup\$

This is my PIC circuit connection in Proteus to the LCD display and everything work fine in simulation. However, in practice, my LCD does not display even the very first line "AC Wattmeter" in the "void main()".
Since the code is very long, I only pasted a portion of the code relevant to it.
I tried the same circuit design as below with other code and the LCD display working fine. Have tried to tune the potentiometer for contrast yet not showing anything. Trying to debug for quite sometime yet have no idea where the problem is. Have tested changing the delay ms to 5ms in the LCD set and command method yet same issue.

enter image description here

    #pragma config FOSC = HS        // Oscillator Selection bits (XT 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)

    #include <xc.h>
    #include <stdlib.h>
    #include <stdbool.h>
    #include <math.h>
    #include <string.h>
    #include <stdio.h>
    #define rs RB0
    #define rw RB1
    #define e RB2
    #define _XTAL_FREQ 20000000

    volatile bool CountWaveFormEnable=false;
    void LCD_set(unsigned char initialize);
    void LCD_command(unsigned char Var);
    void initialize();
    void Write();
    void CharToString(const char *character,unsigned char number);
    char* floattostr(float num);
    void lCD_command();
  
    void init()
    {
       TRISA = 0xFF;
       TRISD = 0x00; 
       TRISB = 0b11000000;
       T1CON = 0x01;
       ADCON0 = 0b01001001;
       ADCON1 = 0b11000000;
       INTCONbits.PEIE = 1;
       INTCONbits.GIE = 1; 
       PIE1bits.CCP1IE = 1;         
       CCP1CON = 0x05;
       OPTION_REG = 0x07;
       TMR0 = 0;

       a = 0;
       b = 0;
    }

    void main()
    {
       init();
       initialize();
       CharToString("  AC Wattmeter",14);
       __delay_ms(500);
       LCD_set(0x01);
       while(1)  
       {
          //Do something
       }
    }

    void initialize()
    { 
       LCD_set(0x0c);
       LCD_set(0x38);   
       LCD_set(0x80);
    }

    void LCD_command(unsigned char Var)
    {
       PORTD = Var;
       rs = 1;
       rw = 0;
       e = 0;
       __delay_ms(0.1);
       e = 1;
    }

    void LCD_set(unsigned char initialize)
    {
       PORTD=initialize;
       rs = 0;
       rw = 0;
       e = 0;
       __delay_ms(0.1);
       e = 1;
    }

    void CharToString(const char *character,unsigned char number)
    {
       for(int i=0; i<number; i++)
       {
          LCD_command(character[i]);
       }
    }

    char string[3];
    char* floattostr(float num)
    {
       sprintf(string, "%d.%02u", (int)(num), ((int)(num*100)%100));
       return string;
    }
\$\endgroup\$
4
  • 1
    \$\begingroup\$ The code does not operate the bus signals in a way that it would work with real world LCDs. If it works with Proteus simulated LCD, it also means the simulated LCD does not work like a real word LCD. Which document you used to write the code? Have you read any LCD data sheets how to make it work? \$\endgroup\$
    – Justme
    Commented May 30, 2022 at 19:40
  • 2
    \$\begingroup\$ Are you sure that your __delay_ms() function accepts non-integer values? I'm almost certain that it doesn't, and as a result all your delays are zero-length. \$\endgroup\$
    – brhans
    Commented May 31, 2022 at 1:18
  • \$\begingroup\$ And most character LCDs have an active-high Enable signal. Why are you driving yours as active-low? \$\endgroup\$
    – brhans
    Commented May 31, 2022 at 1:20
  • \$\begingroup\$ Thank for pointing out the Ms delay only read integer number. I also made a mistake by driving the LCD character by active low, have corrected it. \$\endgroup\$
    – chuackt
    Commented May 31, 2022 at 4:30

1 Answer 1

1
\$\begingroup\$

As mentioned by brhans, the Ms delay only reading integer number. After I change the delay to integer number, the display working correctly.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.