Pic18f4550 LCD 4x20 not working

jayanthd

Joined Jul 4, 2015
906
Pins used for LCD should have their ADC feature disabled. See if your PIC has ANSELx or ADCON1 register which needs to be configured to make pins used for LCD as digital pins.
 

Thread Starter

Geid D

Joined Jun 28, 2015
36
Pins used for LCD should have their ADC feature disabled. See if your PIC has ANSELx or ADCON1 register which needs to be configured to make pins used for LCD as digital pins.
i have this line: #pragma config PBADEN = OFF // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
or do i need additional config parameters?

also i can control PortB state with LATBbits. this shows i think that port is working as digital?
 

jayanthd

Joined Jul 4, 2015
906
This is my LCD Driver. See if it works for you.

Code:
#define _LCD_FIRST_ROW          0x80     //Move cursor to the 1st row
#define _LCD_SECOND_ROW         0xC0     //Move cursor to the 2nd row
#define _LCD_THIRD_ROW          0x94     //Move cursor to the 3rd row
#define _LCD_FOURTH_ROW         0xD4     //Move cursor to the 4th row
#define _LCD_CLEAR              0x01     //Clear display
#define _LCD_RETURN_HOME        0x02     //Return cursor to home position, returns a 
                                         //shifted display to its original position.
                                         //Display data RAM is unaffected.
#define _LCD_CURSOR_OFF         0x0C     //Turn off cursor
#define _LCD_UNDERLINE_ON       0x0E     //Underline cursor on
#define _LCD_BLINK_CURSOR_ON    0x0F     //Blink cursor on
#define _LCD_MOVE_CURSOR_LEFT   0x10     //Move cursor left without changing 
                                         //display data RAM
#define _LCD_MOVE_CURSOR_RIGHT  0x14     //Move cursor right without changing 
                                         //display data RAM
#define _LCD_TURN_ON            0x0C     //Turn Lcd display on
#define _LCD_TURN_OFF           0x08     //Turn Lcd display off
#define _LCD_SHIFT_LEFT         0x18     //Shift display left without changing 
                                         //display data RAM
#define _LCD_SHIFT_RIGHT        0x1E     //Shift display right without changing 
                                         //display data RAM
                                                                                 
#define LCD_STROBE_DELAY 100

#define LCD_RS LATBbits.LATB0
#define LCD_EN LATBbits.LATB2
#define LCD_D4 LATBbits.LATB3
#define LCD_D5 LATBbits.LATB4
#define LCD_D6 LATBbits.LATB5
#define LCD_D7 LATBbits.LATB6

#define LCD_RS_Direction TRISBbits.TRISB0
#define LCD_EN_Direction TRISBbits.TRISB2
#define LCD_D4_Direction TRISBbits.TRISB3
#define LCD_D5_Direction TRISBbits.TRISB4
#define LCD_D6_Direction TRISBbits.TRISB5
#define LCD_D7_Direction TRISBbits.TRISB6
                                           
void LCD_Strobe(unsigned long strobe_delay);                                           
void LCD_Send_Data(char out_char);                                                                                 
void LCD_Cmd(char out_char);
void LCD_Chr(char row, char column, char out_char);
void LCD_Chr_Cp(char out_char);
void LCD_Init(void);
void LCD_Out(char row, char col, char *text);
void LCD_Out_Cp(char *text);


void LCD_Strobe(unsigned long strobe_delay) {   
    LCD_EN = 1;                                               
    __delay_us(strobe_delay);
    LCD_EN = 0;       
}

void LCD_Send_Data(char out_char) {
    if(out_char & 0x10) LCD_D4 = 1; else LCD_D4 = 0;
    if(out_char & 0x20) LCD_D5 = 1; else LCD_D5 = 0;
    if(out_char & 0x40) LCD_D6 = 1; else LCD_D6 = 0;
    if(out_char & 0x80) LCD_D7 = 1; else LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);

    if(out_char & 0x01) LCD_D4 = 1; else LCD_D4 = 0;
    if(out_char & 0x02) LCD_D5 = 1; else LCD_D5 = 0;
    if(out_char & 0x04) LCD_D6 = 1; else LCD_D6 = 0;
    if(out_char & 0x08) LCD_D7 = 1; else LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);
}

void LCD_Cmd(char out_char) {
    LCD_RS = 0;
    LCD_Send_Data(out_char);
   
    if(out_char == 0x01)__delay_ms(2);
}

void LCD_Chr(char row, char column, char out_char) {
    switch(row) {
        case 1:
        LCD_Cmd(0x80 + (column - 1));
        break;
        case 2:
        LCD_Cmd(0xC0 + (column - 1));
        break;
        case 3:
        LCD_Cmd(0x94 + (column - 1));
        break;
        case 4:
        LCD_Cmd(0xD4 + (column - 1));
        break;
    }

    LCD_RS = 1;
    LCD_Send_Data(out_char);           
}

void LCD_Chr_Cp(char out_char) {
    LCD_RS = 1;                       
    LCD_Send_Data(out_char);       
}

void LCD_Init(void) {   
    __delay_ms(200);

    LCD_RS_Direction = 0;             
    LCD_EN_Direction = 0;   
    LCD_D4_Direction = 0;   
    LCD_D5_Direction = 0;   
    LCD_D6_Direction = 0;   
    LCD_D7_Direction = 0;
   
    LCD_RS = 0;             
    LCD_EN = 0;   
    LCD_D4 = 0;   
    LCD_D5 = 0;   
    LCD_D6 = 0;   
    LCD_D7 = 0;   

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);

    __delay_ms(30);

    LCD_D4 = 0;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);

    __delay_ms(30);

    LCD_Cmd(0x28);
    LCD_Cmd(0x06);
}

void LCD_Out(char row, char col, char *text) {
    while(*text)
         LCD_Chr(row, col++, *text++);
}

void LCD_Out_Cp(char *text) {
    while(*text)
         LCD_Chr_Cp(*text++);
}


//Usage
const char txt1[] = "on PIC18F4550";
const char txt2[] = "20 MHz HS Osc";
const char txt3[] = "Is it working?";

char txt[23];

LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
   
LCD_Out(1,1,"LCD 20X4");
LCD_Out(2,1,CopyConst2Ram(txt,txt1));
LCD_Out(3,1,CopyConst2Ram(txt,txt1));
LCD_Out(4,1,CopyConst2Ram(txt,txt1));
 

Attachments

AlbertHall

Joined Jun 4, 2014
11,226
I guess this is wrong.

Code:
#pragma config FOSC = HSPLL_HS
20 MHz Crystal is HS and not HS_PLL. HS_PLL has to be used when you are using say 4 MHz or 8 MHz Crystal with 4x PLL.
No, that's OK. See the lines below. 20MHz crystal divided by 5 to give the necessary 4MHz PLL input.
The problem might be that I think the CPU clock will be 32MHz not the 20MHz stated in the code. This will mean that the delays in the code will be incorrect and they are included in the LCD set up routines.
Code:
#define _XTAL_FREQ 20000000
// CONFIG1L
#pragma config PLLDIV = 5       // PLL Prescaler Selection bits (Divide by 5 (20 MHz oscillator input))
#pragma config CPUDIV = OSC2_PLL3// System Clock Postscaler Selection bits ([Primary Oscillator Src: /2][96 MHz PLL Src: /3])
#pragma config USBDIV = 2       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes from the 96 MHz PLL divided by 2)

// CONFIG1H
#pragma config FOSC = HSPLL_HS  // Oscillator Selection bits (HS oscillator, PLL enabled (HSPLL))
 

ericgibbs

Joined Jan 29, 2010
12,509
hi GD,
When using these alphanumeric LCD's in the past, with a 4Bit Hi or Low Nibble for the LCD data lines, I have sometimes experienced problems when using Data Nibbles made up of 'mixed' Port Bits, as you are using ie: Bits B7,6,5,,,,3

So I now always use a Data Nibble made up of the same Ports Hi or Low Bits, ie: B7,6,5,4 ... etc
This is why I assumed your connections in post #25 image.

I wonder if other users have had similar problems with 'mixed' Port Bits for the LCD Data lines.???

E
 

Thread Starter

Geid D

Joined Jun 28, 2015
36
Have you tried the driver alone?
If so, does it works?
hello all again :) thanks for your help.

attaching code with LCD driver by jayanthd. code minimized to LED blink (also tried only lcd).

all the same :) when i comment LCD_Out(1,1,"TEST"); Led blinks, if line active nothing happens.
also set _XTAL_FREQ 48000000, because with this option i see my led has correct blinking with __delay_ms(1000) (but i dont think that delay timing matters here, program has no reason to halt because of this...!?)
and tried to configure PORTD instead of B.... all the same.

also this:

//ADCON0bits.ADON = 0;

//ADCON1bits.PCFG0 = 1;
//ADCON1bits.PCFG1 = 1;
//ADCON1bits.PCFG2 = 1;
//ADCON1bits.PCFG3 = 1;

now it is commented, but it seems theese lines has no effect aso

indeed a mystery...

Code:
#define _XTAL_FREQ 48000000
// CONFIG1L
#pragma config PLLDIV = 5       // PLL Prescaler Selection bits (Divide by 5 (20 MHz oscillator input))
#pragma config CPUDIV = OSC2_PLL3// System Clock Postscaler Selection bits ([Primary Oscillator Src: /2][96 MHz PLL Src: /3])
#pragma config USBDIV = 2       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes from the 96 MHz PLL divided by 2)

// CONFIG1H
#pragma config FOSC = HSPLL_HS  // Oscillator Selection bits (HS oscillator, PLL enabled (HSPLL))
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = OFF        // Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (Minimum setting 2.05V)
#pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)

// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = ON      // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = OFF      // MCLR Pin Enable bit (RE3 input pin enabled; MCLR pin disabled)

// CONFIG4L
#pragma config STVREN = OFF     // Stack Full/Underflow Reset Enable bit (Stack full/underflow will not cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config ICPRT = OFF      // Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit (ICPORT disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.


#include <xc.h>

#define _LCD_FIRST_ROW          0x80     //Move cursor to the 1st row
#define _LCD_SECOND_ROW         0xC0     //Move cursor to the 2nd row
#define _LCD_THIRD_ROW          0x94     //Move cursor to the 3rd row
#define _LCD_FOURTH_ROW         0xD4     //Move cursor to the 4th row
#define _LCD_CLEAR              0x01     //Clear display
#define _LCD_RETURN_HOME        0x02     //Return cursor to home position, returns a
                                         //shifted display to its original position.
                                         //Display data RAM is unaffected.
#define _LCD_CURSOR_OFF         0x0C     //Turn off cursor
#define _LCD_UNDERLINE_ON       0x0E     //Underline cursor on
#define _LCD_BLINK_CURSOR_ON    0x0F     //Blink cursor on
#define _LCD_MOVE_CURSOR_LEFT   0x10     //Move cursor left without changing
                                         //display data RAM
#define _LCD_MOVE_CURSOR_RIGHT  0x14     //Move cursor right without changing
                                         //display data RAM
#define _LCD_TURN_ON            0x0C     //Turn Lcd display on
#define _LCD_TURN_OFF           0x08     //Turn Lcd display off
#define _LCD_SHIFT_LEFT         0x18     //Shift display left without changing
                                         //display data RAM
#define _LCD_SHIFT_RIGHT        0x1E     //Shift display right without changing
                                         //display data RAM
                                                                               
#define LCD_STROBE_DELAY 100

#define LCD_RS LATBbits.LATB0
#define LCD_EN LATBbits.LATB2
#define LCD_D4 LATBbits.LATB3
#define LCD_D5 LATBbits.LATB5
#define LCD_D6 LATBbits.LATB6
#define LCD_D7 LATBbits.LATB7

#define LCD_RS_Direction TRISBbits.TRISB0
#define LCD_EN_Direction TRISBbits.TRISB2
#define LCD_D4_Direction TRISBbits.TRISB3
#define LCD_D5_Direction TRISBbits.TRISB5
#define LCD_D6_Direction TRISBbits.TRISB6
#define LCD_D7_Direction TRISBbits.TRISB7
                                          
void LCD_Strobe(unsigned long strobe_delay);                                          
void LCD_Send_Data(char out_char);                                                                               
void LCD_Cmd(char out_char);
void LCD_Chr(char row, char column, char out_char);
void LCD_Chr_Cp(char out_char);
void LCD_Init(void);
void LCD_Out(char row, char col, char *text);
void LCD_Out_Cp(char *text);

void main(void)

{
//ADCON0bits.ADON = 0; 

//ADCON1bits.PCFG0 = 1;
//ADCON1bits.PCFG1 = 1;
//ADCON1bits.PCFG2 = 1;
//ADCON1bits.PCFG3 = 1;
  
TRISA = 0x00;

LATAbits.LATA5 = 1; // led on


LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
  
LCD_Out(1,1,"TEST");

while(1) {

    LATAbits.LATA5 = 0;
    __delay_ms(1000);
    LATAbits.LATA5 = 1;
    __delay_ms(1000);
  
                                                                    
}

}

// FUNCTIONS

void LCD_Strobe(unsigned long strobe_delay) {  
    LCD_EN = 1;                                              
    __delay_us(100);
    LCD_EN = 0;      
}

void LCD_Send_Data(char out_char) {
    if(out_char & 0x10) LCD_D4 = 1; else LCD_D4 = 0;
    if(out_char & 0x20) LCD_D5 = 1; else LCD_D5 = 0;
    if(out_char & 0x40) LCD_D6 = 1; else LCD_D6 = 0;
    if(out_char & 0x80) LCD_D7 = 1; else LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);

    if(out_char & 0x01) LCD_D4 = 1; else LCD_D4 = 0;
    if(out_char & 0x02) LCD_D5 = 1; else LCD_D5 = 0;
    if(out_char & 0x04) LCD_D6 = 1; else LCD_D6 = 0;
    if(out_char & 0x08) LCD_D7 = 1; else LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);
}

void LCD_Cmd(char out_char) {
    LCD_RS = 0;
    LCD_Send_Data(out_char);
  
    if(out_char == 0x01)__delay_ms(2);
}

void LCD_Chr(char row, char column, char out_char) {
    switch(row) {
        case 1:
        LCD_Cmd(0x80 + (column - 1));
        break;
        case 2:
        LCD_Cmd(0xC0 + (column - 1));
        break;
        case 3:
        LCD_Cmd(0x94 + (column - 1));
        break;
        case 4:
        LCD_Cmd(0xD4 + (column - 1));
        break;
    }

    LCD_RS = 1;
    LCD_Send_Data(out_char);          
}

void LCD_Chr_Cp(char out_char) {
    LCD_RS = 1;                      
    LCD_Send_Data(out_char);      
}

void LCD_Init(void) {  
    __delay_ms(200);

    LCD_RS_Direction = 0;           
    LCD_EN_Direction = 0;  
    LCD_D4_Direction = 0;  
    LCD_D5_Direction = 0;  
    LCD_D6_Direction = 0;  
    LCD_D7_Direction = 0;
  
    LCD_RS = 0;           
    LCD_EN = 0;  
    LCD_D4 = 0;  
    LCD_D5 = 0;  
    LCD_D6 = 0;  
    LCD_D7 = 0;  

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);

    __delay_ms(30);

    LCD_D4 = 0;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe(LCD_STROBE_DELAY);

    __delay_ms(30);

    LCD_Cmd(0x28);
    LCD_Cmd(0x06);
}

void LCD_Out(char row, char col, char *text) {
    while(*text)
         LCD_Chr(row, col++, *text++);
}

void LCD_Out_Cp(char *text) {
    while(*text)
         LCD_Chr_Cp(*text++);
}
 

jayanthd

Joined Jul 4, 2015
906
I got it working.

See my Oscillator settings. Refer datasheet Oscillator section for properly configuring the Oscillator.

Led test gives correct delays.

mikroC PRO PIC code

Code:
// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections

sbit LED at LATD0_bit;

void main() {
    ADCON1 = 0x0F;
  
    TRISB = 0x00;
    TRISD = 0x00;
  
    PORTB = 0x00;
    PORTD = 0x00;
  
    LATB = 0x00;
    LATD = 0x00;
  
    //Delay_ms(200);
  
    Lcd_Init();
    Lcd_Cmd(_LCD_CURSOR_OFF);
    Lcd_Cmd(_LCD_CLEAR);
  
    Lcd_Out(1,1,"LCD 20x4 test");
    Lcd_Out(2,1,"on PIC18F4550");
    Lcd_Out(3,1,"20 MHz HSPLL");
    Lcd_Out(4,1,"Is it working?");
  
    while(1) {
          LED = ~LED;
          Delay_ms(500);
    }
}
MPLAB XC8 Code

Code:
/*
* File:   main.c
* Author: Jayanth D
*
* Created on 24 August, 2019, 11:15 AM
*/

#define _XTAL_FREQ 20000000UL

// PIC18F4550 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1L
#pragma config PLLDIV = 5       // PLL Prescaler Selection bits (Divide by 5 (20 MHz oscillator input))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 2       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes from the 96 MHz PLL divided by 2)

// CONFIG1H
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator (HS))
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = ON        // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOR = ON         // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 2         // Brown-out Reset Voltage bits (Setting 1 2.79V)
#pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)

// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = ON      // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = OFF      // MCLR Pin Enable bit (RE3 input pin enabled; MCLR pin disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config ICPRT = OFF      // Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit (ICPORT disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <pic18f4550.h>
#include <stdio.h>
#include <stdlib.h>

#define _LCD_FIRST_ROW          0x80     //Move cursor to the 1st row
#define _LCD_SECOND_ROW         0xC0     //Move cursor to the 2nd row
#define _LCD_THIRD_ROW          0x94     //Move cursor to the 3rd row
#define _LCD_FOURTH_ROW         0xD4     //Move cursor to the 4th row
#define _LCD_CLEAR              0x01     //Clear display
#define _LCD_RETURN_HOME        0x02     //Return cursor to home position, returns a
                                         //shifted display to its original position.
                                         //Display data RAM is unaffected.
#define _LCD_CURSOR_OFF         0x0C     //Turn off cursor
#define _LCD_UNDERLINE_ON       0x0E     //Underline cursor on
#define _LCD_BLINK_CURSOR_ON    0x0F     //Blink cursor on
#define _LCD_MOVE_CURSOR_LEFT   0x10     //Move cursor left without changing
                                         //display data RAM
#define _LCD_MOVE_CURSOR_RIGHT  0x14     //Move cursor right without changing
                                         //display data RAM
#define _LCD_TURN_ON            0x0C     //Turn Lcd display on
#define _LCD_TURN_OFF           0x08     //Turn Lcd display off
#define _LCD_SHIFT_LEFT         0x18     //Shift display left without changing
                                         //display data RAM
#define _LCD_SHIFT_RIGHT        0x1E     //Shift display right without changing
                                         //display data RAM

#define LCD_RS LATBbits.LATB0
#define LCD_EN LATBbits.LATB2
#define LCD_D4 LATBbits.LATB4
#define LCD_D5 LATBbits.LATB5
#define LCD_D6 LATBbits.LATB6
#define LCD_D7 LATBbits.LATB7

#define LCD_RS_Direction TRISBbits.TRISB0
#define LCD_EN_Direction TRISBbits.TRISB2
#define LCD_D4_Direction TRISBbits.TRISB4
#define LCD_D5_Direction TRISBbits.TRISB5
#define LCD_D6_Direction TRISBbits.TRISB6
#define LCD_D7_Direction TRISBbits.TRISB7

#define LED LATDbits.LATD0

void LCD_Strobe();                                        
void LCD_Send_Data(char out_char);                                                                            
void LCD_Cmd(char out_char);
void LCD_Chr(char row, char column, char out_char);
void LCD_Chr_Cp(char out_char);
void LCD_Init(void);
void LCD_Out(char row, char col, char *text);
void LCD_Out_Cp(char *text);

char *CopyConst2Ram(char * dest, const char *src);

//Usage
const char txt1[] = "on PIC18F4550";
const char txt2[] = "20 MHz HS Osc";
const char txt3[] = "Is it working?";

char txt[23];

void LCD_Strobe() {
    LCD_EN = 1;                                            
    __delay_us(100);
    LCD_EN = 0;    
}

void LCD_Send_Data(char out_char) {
    if(out_char & 0x10) LCD_D4 = 1; else LCD_D4 = 0;
    if(out_char & 0x20) LCD_D5 = 1; else LCD_D5 = 0;
    if(out_char & 0x40) LCD_D6 = 1; else LCD_D6 = 0;
    if(out_char & 0x80) LCD_D7 = 1; else LCD_D7 = 0;

    LCD_Strobe();

    if(out_char & 0x01) LCD_D4 = 1; else LCD_D4 = 0;
    if(out_char & 0x02) LCD_D5 = 1; else LCD_D5 = 0;
    if(out_char & 0x04) LCD_D6 = 1; else LCD_D6 = 0;
    if(out_char & 0x08) LCD_D7 = 1; else LCD_D7 = 0;

    LCD_Strobe();
}

void LCD_Cmd(char out_char) {
    LCD_RS = 0;
    LCD_Send_Data(out_char);
  
    if(out_char == 0x01)__delay_ms(2);
}

void LCD_Chr(char row, char column, char out_char) {
    switch(row) {
        case 1:
        LCD_Cmd(0x80 + (column - 1));
        break;
        case 2:
        LCD_Cmd(0xC0 + (column - 1));
        break;
        case 3:
        LCD_Cmd(0x94 + (column - 1));
        break;
        case 4:
        LCD_Cmd(0xD4 + (column - 1));
        break;
    }

    LCD_RS = 1;
    LCD_Send_Data(out_char);        
}

void LCD_Chr_Cp(char out_char) {
    LCD_RS = 1;                    
    LCD_Send_Data(out_char);    
}

void LCD_Init(void) {
    __delay_ms(200);

    LCD_RS_Direction = 0;          
    LCD_EN_Direction = 0;
    LCD_D4_Direction = 0;
    LCD_D5_Direction = 0;
    LCD_D6_Direction = 0;
    LCD_D7_Direction = 0;
  
    LCD_RS = 0;          
    LCD_EN = 0;
    LCD_D4 = 0;
    LCD_D5 = 0;
    LCD_D6 = 0;
    LCD_D7 = 0;

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe();

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe();

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe();

    __delay_ms(30);

    LCD_D4 = 0;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe();

    __delay_ms(30);

    LCD_Cmd(0x28);
    LCD_Cmd(0x06);
}

void LCD_Out(char row, char col, char *text) {
    while(*text)
         LCD_Chr(row, col++, *text++);
}

void LCD_Out_Cp(char *text) {
    while(*text)
         LCD_Chr_Cp(*text++);
}

// copy const to ram string
char *CopyConst2Ram(char * dest, const char *src) {
        char *d;
  
        d = dest;
  
        for(;*dest++ = *src++;);
          
        return d;
}

int main(int argc, char** argv) {

    ADCON1 = 0x0F;
  
    TRISB = 0x00;
    TRISD = 0x00;
  
    PORTB = 0x00;
    PORTD = 0x00;
  
    LATB = 0x00;
    LATD = 0x00;
  
    LCD_Init();
    LCD_Cmd(_LCD_CURSOR_OFF);
    LCD_Cmd(_LCD_CLEAR);
  
    LCD_Out(1,1,"LCD 20X4");
    LCD_Out(2,1,CopyConst2Ram(txt,txt1));
    LCD_Out(3,1,CopyConst2Ram(txt,txt2));
    LCD_Out(4,1,CopyConst2Ram(txt,txt3));

    while(1) {
        LED = ~LED;
        __delay_ms(500);      
    }
  
    return (EXIT_SUCCESS);
}
LCD_Driver-SS-1.png


Jayanth D
 

Attachments

Last edited:

jayanthd

Joined Jul 4, 2015
906
Tested in Proteus with actual OP's LCD connections.

difference is

my code

Code:
#define _XTAL_FREQ 20000000UL

#pragma config CPUDIV = OSC1_PLL2
Yours

Code:
#define _XTAL_FREQ 48000000UL

#pragma config CPUDIV = OSC1_PLL3
mikroC PRO PIC Code

Code:
// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections

sbit LED at LATD0_bit;

void main() {
    ADCON1 = 0x0F;

    TRISB = 0x00;
    TRISD = 0x00;

    PORTB = 0x00;
    PORTD = 0x00;

    LATB = 0x00;
    LATD = 0x00;

    //Delay_ms(200);

    Lcd_Init();
    Lcd_Cmd(_LCD_CURSOR_OFF);
    Lcd_Cmd(_LCD_CLEAR);

    Lcd_Out(1,1,"LCD 20x4 test");
    Lcd_Out(2,1,"on PIC18F4550");
    Lcd_Out(3,1,"20 MHz HSPLL");
    Lcd_Out(4,1,"Is it working?");

    while(1) {
          LED = ~LED;
          Delay_ms(500);
    }
}

MPLAB XC8 Code

Code:
/*
* File:   main.c
* Author: Jayanth D
*
* Created on 24 August, 2019, 11:15 AM
*/

#define _XTAL_FREQ 20000000UL

// PIC18F4550 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1L
#pragma config PLLDIV = 5       // PLL Prescaler Selection bits (Divide by 5 (20 MHz oscillator input))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 2       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes from the 96 MHz PLL divided by 2)

// CONFIG1H
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator (HS))
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = ON        // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOR = ON         // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 2         // Brown-out Reset Voltage bits (Setting 1 2.79V)
#pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)

// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = ON      // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = OFF      // MCLR Pin Enable bit (RE3 input pin enabled; MCLR pin disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config ICPRT = OFF      // Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit (ICPORT disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include <pic18f4550.h>
#include <stdio.h>
#include <stdlib.h>

#define _LCD_FIRST_ROW          0x80     //Move cursor to the 1st row
#define _LCD_SECOND_ROW         0xC0     //Move cursor to the 2nd row
#define _LCD_THIRD_ROW          0x94     //Move cursor to the 3rd row
#define _LCD_FOURTH_ROW         0xD4     //Move cursor to the 4th row
#define _LCD_CLEAR              0x01     //Clear display
#define _LCD_RETURN_HOME        0x02     //Return cursor to home position, returns a
                                         //shifted display to its original position.
                                         //Display data RAM is unaffected.
#define _LCD_CURSOR_OFF         0x0C     //Turn off cursor
#define _LCD_UNDERLINE_ON       0x0E     //Underline cursor on
#define _LCD_BLINK_CURSOR_ON    0x0F     //Blink cursor on
#define _LCD_MOVE_CURSOR_LEFT   0x10     //Move cursor left without changing
                                         //display data RAM
#define _LCD_MOVE_CURSOR_RIGHT  0x14     //Move cursor right without changing
                                         //display data RAM
#define _LCD_TURN_ON            0x0C     //Turn Lcd display on
#define _LCD_TURN_OFF           0x08     //Turn Lcd display off
#define _LCD_SHIFT_LEFT         0x18     //Shift display left without changing
                                         //display data RAM
#define _LCD_SHIFT_RIGHT        0x1E     //Shift display right without changing
                                         //display data RAM

#define LCD_RS LATBbits.LATB0
#define LCD_EN LATBbits.LATB2
#define LCD_D4 LATBbits.LATB3
#define LCD_D5 LATBbits.LATB5
#define LCD_D6 LATBbits.LATB6
#define LCD_D7 LATBbits.LATB7

#define LCD_RS_Direction TRISBbits.TRISB0
#define LCD_EN_Direction TRISBbits.TRISB2
#define LCD_D4_Direction TRISBbits.TRISB3
#define LCD_D5_Direction TRISBbits.TRISB5
#define LCD_D6_Direction TRISBbits.TRISB6
#define LCD_D7_Direction TRISBbits.TRISB7

#define LED LATDbits.LATD0

void LCD_Strobe();                                     
void LCD_Send_Data(char out_char);                                                                         
void LCD_Cmd(char out_char);
void LCD_Chr(char row, char column, char out_char);
void LCD_Chr_Cp(char out_char);
void LCD_Init(void);
void LCD_Out(char row, char col, char *text);
void LCD_Out_Cp(char *text);

char *CopyConst2Ram(char * dest, const char *src);

//Usage
const char txt1[] = "on PIC18F4550";
const char txt2[] = "20 MHz HS Osc";
const char txt3[] = "Is it working?";

char txt[23];

void LCD_Strobe() {
    LCD_EN = 1;                                         
    __delay_us(100);
    LCD_EN = 0; 
}

void LCD_Send_Data(char out_char) {
    if(out_char & 0x10) LCD_D4 = 1; else LCD_D4 = 0;
    if(out_char & 0x20) LCD_D5 = 1; else LCD_D5 = 0;
    if(out_char & 0x40) LCD_D6 = 1; else LCD_D6 = 0;
    if(out_char & 0x80) LCD_D7 = 1; else LCD_D7 = 0;

    LCD_Strobe();

    if(out_char & 0x01) LCD_D4 = 1; else LCD_D4 = 0;
    if(out_char & 0x02) LCD_D5 = 1; else LCD_D5 = 0;
    if(out_char & 0x04) LCD_D6 = 1; else LCD_D6 = 0;
    if(out_char & 0x08) LCD_D7 = 1; else LCD_D7 = 0;

    LCD_Strobe();
}

void LCD_Cmd(char out_char) {
    LCD_RS = 0;
    LCD_Send_Data(out_char);

    if(out_char == 0x01)__delay_ms(2);
}

void LCD_Chr(char row, char column, char out_char) {
    switch(row) {
        case 1:
        LCD_Cmd(0x80 + (column - 1));
        break;
        case 2:
        LCD_Cmd(0xC0 + (column - 1));
        break;
        case 3:
        LCD_Cmd(0x94 + (column - 1));
        break;
        case 4:
        LCD_Cmd(0xD4 + (column - 1));
        break;
    }

    LCD_RS = 1;
    LCD_Send_Data(out_char);     
}

void LCD_Chr_Cp(char out_char) {
    LCD_RS = 1;                 
    LCD_Send_Data(out_char); 
}

void LCD_Init(void) {
    __delay_ms(200);

    LCD_RS_Direction = 0;       
    LCD_EN_Direction = 0;
    LCD_D4_Direction = 0;
    LCD_D5_Direction = 0;
    LCD_D6_Direction = 0;
    LCD_D7_Direction = 0;

    LCD_RS = 0;       
    LCD_EN = 0;
    LCD_D4 = 0;
    LCD_D5 = 0;
    LCD_D6 = 0;
    LCD_D7 = 0;

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe();

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe();

    __delay_ms(30);

    LCD_D4 = 1;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe();

    __delay_ms(30);

    LCD_D4 = 0;
    LCD_D5 = 1;
    LCD_D6 = 0;
    LCD_D7 = 0;

    LCD_Strobe();

    __delay_ms(30);

    LCD_Cmd(0x28);
    LCD_Cmd(0x06);
}

void LCD_Out(char row, char col, char *text) {
    while(*text)
         LCD_Chr(row, col++, *text++);
}

void LCD_Out_Cp(char *text) {
    while(*text)
         LCD_Chr_Cp(*text++);
}

// copy const to ram string
char *CopyConst2Ram(char * dest, const char *src) {
        char *d;

        d = dest;

        for(;*dest++ = *src++;);
       
        return d;
}

int main(int argc, char** argv) {

    ADCON1 = 0x0F;

    TRISB = 0x00;
    TRISD = 0x00;

    PORTB = 0x00;
    PORTD = 0x00;

    LATB = 0x00;
    LATD = 0x00;

    LCD_Init();
    LCD_Cmd(_LCD_CURSOR_OFF);
    LCD_Cmd(_LCD_CLEAR);

    LCD_Out(1,1,"LCD 20X4");
    LCD_Out(2,1,CopyConst2Ram(txt,txt1));
    LCD_Out(3,1,CopyConst2Ram(txt,txt2));
    LCD_Out(4,1,CopyConst2Ram(txt,txt3));

    while(1) {
        LED = ~LED;
        __delay_ms(500);   
    }

    return (EXIT_SUCCESS);
}
LCD_Driver-SS-2.png
 

Attachments

Last edited:

Thread Starter

Geid D

Joined Jun 28, 2015
36
thanks Jayanth D for help, but code dont work

i think my code breaks because of the usage of memory pointers: char* text
can it be somehow related to the fact that i use USB bootloader in my chip?
 

jayanthd

Joined Jul 4, 2015
906
thanks Jayanth D for help, but code dont work

i think my code breaks because of the usage of memory pointers: char* text
can it be somehow related to the fact that i use USB bootloader in my chip?

USB Bootloader has nothing to do with it.

Show your circuit.

Did you test by burning my .hex file to PIC without Compiling it. Try that.

Maybe you have PRO version of XC8 and with optimizations turned on and they are eliminating small delays in LCD_Init()?
 

Thread Starter

Geid D

Joined Jun 28, 2015
36
not at my work computer now, but will post circuit later.

but the fact is if i remove char* text from LCD function, code don't stop and led blinks.
im assuming that LCD code should not stop whole program even if I completely disconnect LCD from Pic.
 
Top