Interfacing 16*2 LCD JHD162A with xmc4500 micro controller series

Discussion in 'Embedded Systems and Microcontrollers' started by A nusha Anu, Dec 10, 2016.

  1. A nusha Anu

    Thread Starter New Member

    Dec 10, 2016
    1
    0
    I am trying to interface 16*2 lcd with xmc4500 with 4 bit operation. But it's displaying garbage value and second line characters are not getting displayed. Below is the code, please tell me what modifications have to be done in
    the code. P0--> data lines, P1.0 --RS, P1.1--> RW, P3.0--> E.




    Code (C):
    1.  
    2. /*
    3. * main.c
    4. *
    5. * Created on: 2016 Dec 09 19:23:38
    6. * Author: DELL
    7. */
    8.  
    9.  
    10.  
    11.  
    12. #include <DAVE.h> //Declarations from DAVE Code Generation (includes SFR declaration)
    13. void LCD_init(void);
    14. void DelayMs(int Ms);
    15. void LCD_cmd4(unsigned char cmd);
    16. void LCD_dat4(unsigned char byte);
    17.  
    18. /**
    19.  
    20. * @brief main() - Application entry point
    21. *
    22. * <b>Details of function</b><br>
    23. * This routine is the application entry point. It is invoked by the device startup code. It is responsible for
    24. * invoking the APP initialization dispatcher routine - DAVE_Init() and hosting the place-holder for user application
    25. * code.
    26. */
    27.  
    28. void main(void)
    29. {
    30. DAVE_STATUS_t status;
    31.  
    32. status = DAVE_Init(); /* Initialization of DAVE APPs */
    33.  
    34. if(status == DAVE_STATUS_FAILURE)
    35. {
    36. /* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
    37. XMC_DEBUG("DAVE APPs initialization failed\n");
    38.  
    39. while(1U)
    40. {
    41.  
    42. }
    43. }
    44. unsigned int i;
    45. const unsigned char Msg1[] = "WELCOME TO XMC";
    46. const unsigned char Msg2[] = "LCD INTERFACING";
    47.  
    48. PORT0->IOCR4 = 0x80808080; //Defines P0.4 to P0.7 as output pins for data lines
    49. PORT1->IOCR0 = 0x8080; //Defines P1.0 and P1.1 as output pins for control lines
    50. PORT3->IOCR0 = 0x80; //Defines P3.0 as output pin for enable
    51. DelayMs(100);
    52. LCD_init();
    53. DelayMs(50);
    54.  
    55. while(1U)
    56. {
    57. LCD_cmd4(0x80);
    58. for(i=0;i<16;i++)
    59. {
    60. LCD_dat4(Msg1[I]);
    61. DelayMs(5);
    62. }
    63. LCD_cmd4(0xC0);
    64. for(i=0;i<16;i++)
    65. {
    66. LCD_dat4(Msg2[I]);
    67. DelayMs(5);
    68. }
    69. }
    70. }
    71.  
    72. void LCD_init(void) {
    73. LCD_cmd4(0x33);
    74. LCD_cmd4(0x22);
    75. LCD_cmd4(0x22);
    76. LCD_cmd4(0x22);
    77. LCD_cmd4(0x28); // 28 for four bit mode
    78. LCD_cmd4(0x0c);
    79. LCD_cmd4(0x06);
    80. LCD_cmd4(0x01);
    81. }
    82.  
    83. void LCD_cmd4(unsigned char cmd) {
    84. PORT1->OUT = 0x00; // RW=0,RS=0
    85. PORT0->OUT = cmd;
    86. PORT3->OUT = 0x01; // En = 1;
    87. PORT3->OUT = 0x00; // En = 0;
    88. cmd = (cmd<<4) & 0xF0;
    89. PORT0->OUT = cmd;
    90. PORT3->OUT = 0x01; // En = 1;
    91. PORT3->OUT = 0x00; // En = 0;
    92. DelayMs(3);
    93. }
    94.  
    95. void LCD_dat4(unsigned char byte) {
    96. PORT1->OUT = 0x01; // RW=0,RS=1
    97. PORT0->OUT = byte;
    98. PORT3->OUT = 0x01; // En = 1;
    99. PORT3->OUT = 0x00; // En = 0;
    100. byte = (byte<<4) & 0xF0;
    101. PORT0->OUT = byte;
    102. PORT3->OUT = 0x01; // En = 1;
    103. PORT3->OUT = 0x00; // En = 0;
    104. DelayMs(3);
    105. }
    106. void DelayMs(int Ms) {
    107. long int k;
    108. while(Ms>0) {
    109. for(k=0;k<108*1200;k++);
    110. Ms--;
    111. }
    112. }
    113.  
    MOD note: Addded code tags.
     
    Last edited by a moderator: Dec 10, 2016
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    4,667
    745
    Your LCD_init looks wrong. When I was taught how to make uC talk to LCD, we were told to follow LCD manufacturer's initialization instructions, in those instructions there were delays between the commands. I see a list of commands. I don't see any delays between them. So I think your LCD initialization is failing.
     
  3. dannyf

    Well-Known Member

    Sep 13, 2015
    2,196
    422
    that DELL or DAVE guy knows something about what's wrong.
     
Loading...