• AVR Freaks

Hot!JHD162A 659M10 LCD 16X2

Page: 123 > Showing page 1 of 3
Author
Djsarkar
Senior Member
  • Total Posts : 149
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: offline
2020/09/29 07:54:37 (permalink)
0

JHD162A 659M10 LCD 16X2

Hi
I have PIC18F45K80. I am using MPLABX 5.40 and XC8 2.30. I am having trouble to  initialized port pins of PIC18F45K80
How to configure RW pin ? PORT or LAT

 
 
 
#define _XTAL_FREQ 8000000
#include <xc.h>
// PIC18F45K80 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1L
#pragma config RETEN = OFF      // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
#pragma config SOSCSEL = HIGH   // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
#pragma config XINST = OFF       // Extended Instruction Set (Enabled)
// CONFIG1H
#pragma config FOSC = INTIO2    // Oscillator (Internal RC oscillator)
#pragma config PLLCFG = OFF     // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF       // Internal External Oscillator Switch Over Mode (Disabled)
// CONFIG2L
#pragma config PWRTEN = OFF     // Power Up Timer (Disabled)
#pragma config BOREN = SBORDIS  // Brown Out Detect (Enabled in hardware, SBOREN disabled)
#pragma config BORV = 3         // Brown-out Reset Voltage bits (1.8V)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is selected)
// CONFIG2H
#pragma config WDTEN = OFF      // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1048576  // Watchdog Postscaler (1:1048576)
// CONFIG3H
#pragma config CANMX = PORTB    // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
#pragma config MSSPMSK = MSK7   // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = ON       // Master Clear Enable (MCLR Enabled, RE3 Disabled)
// CONFIG4L
#pragma config STVREN = ON      // Stack Overflow Reset (Enabled)
#pragma config BBSIZ = BB2K     // Boot Block Size (2K word Boot Block size)
// CONFIG5L
#pragma config CP0 = OFF        // Code Protect 00800-01FFF (Disabled)
#pragma config CP1 = OFF        // Code Protect 02000-03FFF (Disabled)
#pragma config CP2 = OFF        // Code Protect 04000-05FFF (Disabled)
#pragma config CP3 = OFF        // Code Protect 06000-07FFF (Disabled)
// CONFIG5H
#pragma config CPB = OFF        // Code Protect Boot (Disabled)
#pragma config CPD = OFF        // Data EE Read Protect (Disabled)
// CONFIG6L
#pragma config WRT0 = OFF       // Table Write Protect 00800-01FFF (Disabled)
#pragma config WRT1 = OFF       // Table Write Protect 02000-03FFF (Disabled)
#pragma config WRT2 = OFF       // Table Write Protect 04000-05FFF (Disabled)
#pragma config WRT3 = OFF       // Table Write Protect 06000-07FFF (Disabled)
// CONFIG6H
#pragma config WRTC = OFF       // Config. Write Protect (Disabled)
#pragma config WRTB = OFF       // Table Write Protect Boot (Disabled)
#pragma config WRTD = OFF       // Data EE Write Protect (Disabled)
// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protect 00800-01FFF (Disabled)
#pragma config EBTR1 = OFF      // Table Read Protect 02000-03FFF (Disabled)
#pragma config EBTR2 = OFF      // Table Read Protect 04000-05FFF (Disabled)
#pragma config EBTR3 = OFF      // Table Read Protect 06000-07FFF (Disabled)
// CONFIG7H
#pragma config EBTRB = OFF      // Table Read Protect Boot (Disabled)

 
 
 
#define RS            LATCbits.LATC4
#define RW            PORTCbits.RC5
#define EN            LATCbits.LATC6
#define LCD_Port      LATD

 
 
 
 

 
 
 
void main(void)
{
    LATA = LATB = LATC = LATD = LATE =  0;
  
    TRISA = 0b0000000;// RA0 as input,  Switch connected
    TRISB = 0b0000000;// all are output, Unused
    TRISC = 0b0000000;// All are output, Unused RC2 LED connected
    TRISD = 0b0000000;//  All are output,
    TRISE = 0b0000000;// All are output, Unused
  
    ANCON0 = 0; // digital port
    ANCON1 = 0; // digital port
    CM1CON = 0; // Comparator off
    CM2CON = 0; // Comparator off
    ADCON0 = 0; // A/D conversion Disabled
   
    while (1)
    {
    }
}

 
 
 

post edited by Djsarkar - 2020/09/29 09:10:42
#1

41 Replies Related Threads

    1and0
    Access is Denied
    • Total Posts : 11324
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/29 08:06:23 (permalink)
    +3 (3)
    Djsarkar
    I have PIC18F45K80. I am using MPLABX 5.40 and XC8 2.30. I am having trouble to  initialized port pins of PIC18F45K80
    How to configure RW pin ? PORT or LAT

    #define RS            LATCbits.LATC4
    #define RW            PORTCbits.RC5
    #define EN            LATCbits.LATC6
    #define LCD_Port      LATD



    Always use PORTx for inputs and LATx for outputs.
     
    #2
    Djsarkar
    Senior Member
    • Total Posts : 149
    • Reward points : 0
    • Joined: 2020/07/27 01:14:06
    • Location: 0
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/29 09:02:35 (permalink)
    0 (2)
    I am looking for the datasheet of JHD162A 659M10 LCD 16X2. I don't find the datasheet for my LCD
     
    Can anyone help me to find correct datasheet  
    #3
    Mysil
    Super Member
    • Total Posts : 3796
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/29 10:27:00 (permalink)
    +1 (1)
    Hi,
    Many character  LCD display modules from many different manufacturers use the same controller chip, 
    or a compatible clone of that controller.
    There is a reasonably good description on Wikipedia:
    https://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller
    also with a link to datasheet for the display controller, which is what you need the most.
     
    I suggest using LAT  register bits for output to control lines: 
    #define RS            LATCbits.LATC4
    #define RW            LATCbits.LATC5
    #define EN            LATCbits.LATC6
    #define LCD_Port      LATD 

    Only when you want to check Busy signal, use a separate macro definition to read Data line 7
    #define BUSY       PORTDbits.RD7   

     
        Mysil
     
    #4
    Djsarkar
    Senior Member
    • Total Posts : 149
    • Reward points : 0
    • Joined: 2020/07/27 01:14:06
    • Location: 0
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/29 12:35:41 (permalink)
    0
    Mysil
    Hi,Many character  LCD display modules from many different manufacturers use the same controller chip, or a compatible clone of that controller.There is a reasonably good description on Wikipedia:https://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller also with a link to datasheet for the display controller,   Mysil 


    I have come across datasheet
    www.sparkfun.com › LCDPDF

    HD44780 - SparkFun Electronics

    Figure 24 page 45 describe initliztion in 4 bit mode. There is no information for EN signal

    EN RS and R/W are control signal.

    What the use of Enable signal? When does the EN signal become low or high?
    post edited by Djsarkar - 2020/09/29 12:39:05
    #5
    1and0
    Access is Denied
    • Total Posts : 11324
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/29 12:52:57 (permalink)
    0
    Djsarkar
    Figure 24 page 45 describe initliztion in 4 bit mode. There is no information for EN signal

    EN RS and R/W are control signal.

    What the use of Enable signal? When does the EN signal become low or high?

    Look at the timing diagrams on pages 14 and 15 of this  https://datasheetspdf.com...nstar/WH1602A-NYG-CT/1
    post edited by 1and0 - 2020/09/29 12:56:31
    #6
    1and0
    Access is Denied
    • Total Posts : 11324
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/29 13:00:00 (permalink)
    +1 (1)
    Here is the datasheet for your JHD16A:  https://datasheetspdf.com...e/512991/ETC/JHD162A/1
    #7
    Djsarkar
    Senior Member
    • Total Posts : 149
    • Reward points : 0
    • Joined: 2020/07/27 01:14:06
    • Location: 0
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/29 21:16:36 (permalink)
    0
    getting error message
     
    Edit : I am trying to understand timing diagram but I don't understand information given in diagram 
     
    How do you find required information from the timing diagram?
     
    post edited by Djsarkar - 2020/09/29 21:26:56

    Attached Image(s)

    #8
    ric
    Super Member
    • Total Posts : 28660
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: LCD PORT Pin initialization 2020/09/29 21:17:53 (permalink)
    0
    What error message?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    Djsarkar
    Senior Member
    • Total Posts : 149
    • Reward points : 0
    • Joined: 2020/07/27 01:14:06
    • Location: 0
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/29 21:27:57 (permalink)
    0
    ric
    What error message?
     

    I was trying to reply from long time but I was getting message  You don't have permission to access" http:www.microchip.com/forums.post.aspx?" on this server 
     
    #10
    davea
    Super Member
    • Total Posts : 384
    • Reward points : 0
    • Joined: 2016/01/28 13:12:13
    • Location: Tampa Bay FL USA
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/29 21:55:58 (permalink)
    0
    look when data valid is active
    write on the rising edge
    read just before the falling edge
    of clock EN
    all exchanges are made on falling edge
    post edited by davea - 2020/09/29 21:57:22
    #11
    Mysil
    Super Member
    • Total Posts : 3796
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/29 23:48:05 (permalink)
    0
    Hi,
    You did ask in message #5, what to do with the Enable signal.
    You must control the signal on the EN pin, it may also be called a Strobe signal.
    It is used by the LCD control chip to synchronize interpretation of all the other control and data signals.
     
    You must set the EN signal High to enable the controller to communicate.
    When you next toggle the EN signal Low, controller will latch in data signals and update the display.
     
    Timing diagrams show what signal sequence is expected and allowed,
    study the timing diagrams carefully.
    Notes in the timing diagram refer to timing specifications in the datasheet.
     
        Mysil
    #12
    Djsarkar
    Senior Member
    • Total Posts : 149
    • Reward points : 0
    • Joined: 2020/07/27 01:14:06
    • Location: 0
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/30 03:00:37 (permalink)
    0
    The timing diagram shows that we should set the RS and R/W pins to appropriate values. 
     
    The R/W pin specifies whether we are writing to the LCD (R/W=0) or reading from it (R/W=1). 
     
    The RS pin is the Register Selector pin for the LCD. The LCD has two registers: an Instruction Register  and a Data Register. The RS pin is a control pin that specifies whether Instruction Register  and a Data Register. should
     
    Then, the EN signal should have a high-to-low which starts a write operation. high-to-low transition on EN starts data  write but there are certain timing conditions that I do not understand. How much time we should wait before to EN and after to EN ? 
    #13
    ric
    Super Member
    • Total Posts : 28660
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: LCD PORT Pin initialization 2020/09/30 03:20:32 (permalink)
    0
    Djsarkar
    Then, the EN signal should have a high-to-low which starts a write operation.

    It also starts a "read" operation, so the word "write" in your statement is redundant.

    high-to-low transition on EN starts data  write but there are certain timing conditions that I do not understand. How much time we should wait before to EN and after to EN ?

    All the required times are documented in the datasheet.
    Which one don't you understand?

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #14
    Djsarkar
    Senior Member
    • Total Posts : 149
    • Reward points : 0
    • Joined: 2020/07/27 01:14:06
    • Location: 0
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/30 03:39:46 (permalink)
    0
    ricWhich one don't you understand?

    How much time EN takes to complete transition high to low ?
    #15
    ric
    Super Member
    • Total Posts : 28660
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: LCD PORT Pin initialization 2020/09/30 03:52:08 (permalink)
    0
    Djsarkar
    ricWhich one don't you understand?

    How much time EN takes to complete transition high to low ?

    That will be almost instant, as quickly as the output driver can switch it.
    It is marked as "tF" in that diagram (i.e. "fall time"), and the spec is "maximum 25 nanoseconds."
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #16
    Djsarkar
    Senior Member
    • Total Posts : 149
    • Reward points : 0
    • Joined: 2020/07/27 01:14:06
    • Location: 0
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/30 04:14:23 (permalink)
    0
    ric
    That will be almost instant, as quickly as the output driver can switch it.
    It is marked as "tF" in that diagram (i.e. "fall time"), and the spec is "maximum 25 nanoseconds."

    so we have three control signal RS, R/W and EN to send command or data to LCD  
     
    For sending  instruction to LCD
    RS = Low // select instruction register 
    R/W = Low // write mode operation 
    EN = High 
    Wait 
    EN = Low
     
    For sending Data to LCD
    RS = Low // select Data register 
    R/W = Low // write mode operation 
    EN = High 
    Wait 
    EN = Low 
     
    What should be wait time between High to low transition ? Is it 25 nanoseconds?
    post edited by Djsarkar - 2020/09/30 04:15:49
    #17
    ric
    Super Member
    • Total Posts : 28660
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: LCD PORT Pin initialization 2020/09/30 04:25:35 (permalink)
    0
    You stated the wrong state for RS when writing data
    Djsarkar
    For sending Data to LCD
    RS = HIGH // select Data register 
    R/W = Low // write mode operation 
    EN = High 
    Wait 
    EN = Low

     

    What should be wait time between High to low transition ? Is it 25 nanoseconds?

    You are using bad terminology here.
    The "high to low transition" specifies the transition from the high state, to the low state.
    i.e. ONLY the falling edge of the signal.
    THAT is what must be less than 25ns.
     
    I think you are asking how long the signal should stay high.
    i.e. the time from the rising edge (low to high) to the falling edge (high to low).
    The specification for that is "PW", which has a MINIMUM of 140ns.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #18
    Djsarkar
    Senior Member
    • Total Posts : 149
    • Reward points : 0
    • Joined: 2020/07/27 01:14:06
    • Location: 0
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/30 04:50:03 (permalink)
    0
    ric 
    I think you are asking how long the signal should stay high.
    i.e. the time from the rising edge (low to high) to the falling edge (high to low).
    The specification for that is "PW", which has a MINIMUM of 140ns.

     my idea for sending instruction and data to LCD 

     
    /* Function to send instruction to LCD */
    void LCD_Instruction(unsigned char Command)
    {
        RS = Low; // select instruction register
        RW = Low ; // write mode
       
       // falling edge
        EN = High_State;
        __delay_ms(1);
        EN = Low_State;
       
    }

     
    /*Function to send message to LCD */
    void LCD_Data(unsigned char Message)
    {
       RS = High;  // select Data register
       RW = Low ;  // write mode
       
       // falling edge
        EN = High_State;
        __delay_ms(1);
        EN = Low_State;

    }

     

     
     I will make function to initialize LCD 
    post edited by Djsarkar - 2020/09/30 04:52:04
    #19
    Mysil
    Super Member
    • Total Posts : 3796
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: LCD PORT Pin initialization 2020/09/30 05:21:42 (permalink)
    +1 (1)
    Hi,
    You may take care to distinguish between milliseconds (ms), microseconds (us) and nanoseconds(ns)
    they are very different units of time.
    For delay between Enable signal rising edge, and enable signal falling edge,
    1 microsecond is more than enough
       // Enable signal strobe
        EN = High_State;    // Rising edge
        __delay_us(1);
        EN = Low_State;    // Falling edge.



    Also somewhere you will need to transfer Command argument to Data pins:
        LCD_Port = Command;  

     
        Mysil
    #20
    Page: 123 > Showing page 1 of 3
    Jump to:
    © 2020 APG vNext Commercial Version 4.5