Interfacing LCD(16X2) with PIC18F46K80

Discussion in 'General Electronics Chat' started by nacoolp, Nov 29, 2013.

  1. nacoolp

    Thread Starter New Member

    Jan 2, 2013
    14
    0
    Hello everyone,

    I am trying to create a simple program to print "Hello" on LCD using PIC18F46K80 in mikroC. The circuit board on which I am working works perfectly with PIC16F887. But with 46k80, the LCD remains blank only. I guess I have configured everything properly in the hardware. Is LCD interfacing with PIC18F46K80 different with PIC16F887..?? Are there some special instructions that I should follow while using LCD with the former?? Or is there any special provision required to be done in the configuration file?

    If so, please guide me the needful as I am going out blank with the current situation.

    I am attaching my C file along with this topic for your reference. Do let me know if I am making a mistake. In this file, the outputs L1, L2 and L3 are working perfectly but nothing is occurring with LCD.

    Thanks in advance.

    Code ( (Unknown Language)):
    1.  
    2. sbit LCD_RS at RA3_bit;
    3. sbit LCD_RW at RA2_bit;
    4. sbit LCD_EN at RB4_bit;
    5. sbit LCD_D4 at RD4_bit;
    6. sbit LCD_D5 at RD5_bit;
    7. sbit LCD_D6 at RE1_bit;
    8. sbit LCD_D7 at RE2_bit;
    9.  
    10. sbit LCD_RS_Direction at TRISA3_bit;
    11. sbit LCD_RW_Direction at TRISA2_bit;
    12. sbit LCD_EN_Direction at TRISB4_bit;
    13. sbit LCD_D4_Direction at TRISD4_bit;
    14. sbit LCD_D5_Direction at TRISD5_bit;
    15. sbit LCD_D6_Direction at TRISE1_bit;
    16. sbit LCD_D7_Direction at TRISE2_bit;
    17.  
    18. #define L1 PORTC.B3
    19. #define L2 PORTD.B6
    20. #define L3 PORTD.B7
    21.  
    22.   void main()
    23.   {
    24.    OSCCON = 0b01110000;
    25.  
    26.    ANCON0=0x00;
    27.    ANCON1=0x00;
    28.    ADCON1=0x7F;
    29.    ADCON0.ADON = 0;
    30.    TRISA=0X00;
    31.    TRISB=0X00;
    32.    TRISC=0X00;
    33.    TRISD=0X00;
    34.    TRISE=0X00;
    35.  
    36.    LCD_Init();                        // Initialize LCD
    37.    Lcd_Cmd(_LCD_CLEAR);               // Clear display
    38.    Lcd_Cmd(_LCD_CURSOR_OFF);
    39.    
    40.    while(1){
    41.             LCD_Out(1,2,"LLS101");
    42.             L1 = 1;
    43.             delay_ms(1000);
    44.             L1 = 0;
    45.             L2 = 1;
    46.             delay_ms(1000);
    47.             L2 = 0;
    48.             L3 = 1;
    49.             delay_ms(1000);
    50.             L3 = 0;
    51.  
    52.             }
    53.    }
    54.  
     
  2. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
  3. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,061
    3,823
  4. nacoolp

    Thread Starter New Member

    Jan 2, 2013
    14
    0
    Thank you takao21203 and GopherT for your kind reply.

    I had already tried to declare the LATX registers for the same but of no use.
    And yes, only 4 bits are used.

    With your suggestions and some deep surfing over the datasheet and internet, I have tried a code through which my LCD is getting data but that too some garbage data (image file attached). I am sharing the code to you. Kindly go through it and guide me where I am getting all wrong.


    Code ( (Unknown Language)):
    1.  
    2. sbit LCD_RS at LATA3_bit;
    3. sbit LCD_RW at LATA2_bit;
    4. sbit LCD_EN at LATB4_bit;
    5. sbit LCD_D4 at LATD4_bit;
    6. sbit LCD_D5 at LATD5_bit;
    7. sbit LCD_D6 at LATE1_bit;
    8. sbit LCD_D7 at LATE2_bit;
    9.  
    10. sbit LCD_RS_Direction at TRISA3_bit;
    11. sbit LCD_RW_Direction at TRISA2_bit;
    12. sbit LCD_EN_Direction at TRISB4_bit;
    13. sbit LCD_D4_Direction at TRISD4_bit;
    14. sbit LCD_D5_Direction at TRISD5_bit;
    15. sbit LCD_D6_Direction at TRISE1_bit;
    16. sbit LCD_D7_Direction at TRISE2_bit;
    17.  
    18. #define L1 PORTC.B3
    19. #define L2 PORTD.B6
    20. #define L3 PORTD.B7
    21.  
    22.   void main()
    23.   {
    24.    delay_ms(100);
    25.    OSCCON = 0b01110011;
    26.  
    27.    ANCON0=0x00;
    28.    ANCON1=0x00;
    29.    ADCON1=0x7F;
    30.    ADCON0.ADON = 0;
    31.    TRISA=0X00;
    32.    TRISB=0X00;
    33.    TRISC=0X00;
    34.    TRISD=0X00;
    35.    TRISE=0X00;
    36.    PMD2 = 0xFF;
    37.   PMD1 = 0xFF;
    38.   PMD0 = 0xFF;
    39.  
    40.    LCD_Init();  
    41.    Lcd_Cmd(_LCD_CLEAR);               // Clear display
    42.    Lcd_Cmd(_LCD_CURSOR_OFF);
    43.  
    44.     while(1){
    45.              LCD_Out(1,2,"hello");
    46.              delay_ms(1000);
    47.              }
    48.  
    49. }
    50.  
    Thanks & Regards,

    Nakul Pitolwala
     
Loading...