+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Advanced Member level 3
    Points: 4,748, Level: 16
    Achievements:
    7 years registered
    PA3040's Avatar
    Join Date
    Aug 2011
    Posts
    841
    Helped
    43 / 43
    Points
    4,748
    Level
    16

    My LCD 4bit mode program is not working

    Dear All
    My LCD 4bit mode program is not working. Can any one please advice me what are the errors with my codes. No compile errors,
    Please find the attachment for DSN file for Proteus
    Code:
    #include 
    #define _XTAL_FREQ 4000000 // 4 MHz clock 
    
    __CONFIG(0X3F39);
    #define LCD_EN RB3
    #define	LCD_RS RB5
    #define	LCD_RW RB4
    #define LCD_DATA	PORTD
    #define	LCD_STROBE()	((LCD_EN = 1)|(LCD_EN=0))
    unsigned char time [5] = {'T','i','m','e',':'};
    
    void lcddata(unsigned char value)
    	{
    LCD_RS = 1; 
    LCD_DATA= (value >> 4);
    LCD_STROBE();
    LCD_DATA = (value);
    LCD_STROBE();
    	}
    
    void lcdcmd(unsigned char value)
    	{
    LCD_RS = 0;
    LCD_DATA= (value >> 4);
    LCD_STROBE();
    LCD_DATA = (value);
    LCD_STROBE();
    	}
    
    void display (){
    	lcdcmd(0x80);
    		for (char i=0;i<5;i++){
    			lcddata(time[i]);
    					}
    		}
    
    void lcd_init(){
    
    TRISD	= 0;
    TRISB	= 0;
    TRISC7  = 0;
    TRISC6  = 0;
    LCD_EN =0;
    __delay_ms(175);
    lcdcmd(0x38);
    __delay_ms(175);
    lcdcmd(0x28);
    __delay_ms(15);
    lcdcmd(0x01);
    __delay_ms(10);
    lcdcmd(0x06);
    __delay_ms(10);
    lcdcmd(0x80);
    __delay_ms(10);
    lcdcmd(0x0c);
    __delay_ms(10);
    				}
    
    void main(){        
            lcd_init();       
    			while(1){	
    				display();
    		
    			}
    }
    Thanks in Advance

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 1
    Points: 3,016, Level: 12
    Jestin_cubetech's Avatar
    Join Date
    Jun 2012
    Posts
    499
    Helped
    74 / 74
    Points
    3,016
    Level
    12
    Blog Entries
    6

    Re: My LCD 4bit mode program is not working

    LCD Initialization Error,Data out put Format Error.
    ----------------------------------------------
    One man's fault is other man's lesson...
    ----------------------------------------------


    1 members found this post helpful.

  3. #3
    Advanced Member level 3
    Points: 4,748, Level: 16
    Achievements:
    7 years registered
    PA3040's Avatar
    Join Date
    Aug 2011
    Posts
    841
    Helped
    43 / 43
    Points
    4,748
    Level
    16

    Re: My LCD 4bit mode program is not working

    Dear Justin,
    Thank you so much for reply and help. I got the points where the error of my codes
    I would like share the codes here that was corrected by jestin for others
    Code:
    #include 
    #define _XTAL_FREQ 4000000 // 4 MHz clock 
    
    __CONFIG(0X3F39);
    #define LCD_EN RB3
    #define	LCD_RS RB5
    #define	LCD_RW RB4
    #define LCD_DATA	PORTD
    #define	LCD_STROBE  LCD_EN = 1; __delay_ms(1); LCD_EN=0;
    
    unsigned char time [6] = {"Time:"};
    
    void lcddata(unsigned char value)
    	{
    LCD_RS = 1; 
    LCD_DATA= (value&0xf0);
    LCD_STROBE;
    LCD_DATA = ((value<<4)&0xf0);
    LCD_STROBE;
    __delay_ms(10);
    	}
    
    void lcdcmd(unsigned char value)
    	{
    LCD_RS = 0;
    LCD_DATA= (value&0xf0);
    LCD_STROBE;
    LCD_DATA = ((value<<4)&0xf0);
    LCD_STROBE;
    __delay_ms(10);
    	}
    
    void display (){
    	lcdcmd(0x80);
    		for (char i=0;i<5;i++){
    			lcddata(time[i]);
    			
    					}
    		}
    
    void lcd_init(){
    
    TRISD	= 0;
    TRISB	= 0;
    TRISC7  = 0;
    TRISC6  = 0;
    LCD_EN =0;
     __delay_us(10);  
    	LCD_DATA =0X30;
         	LCD_STROBE;
           	__delay_ms(2);
    
           LCD_RS=0;
           __delay_us(10);  
    	LCD_DATA =0X30;
         	LCD_STROBE;
    	__delay_ms(2);
    
            LCD_RS=0;
           __delay_us(10);  
    	LCD_DATA =0X30;
           	LCD_STROBE;
    	__delay_ms(2);
    
           LCD_RS=0;
           __delay_us(10);  
    	LCD_DATA =0X20;
         	LCD_STROBE;
    	__delay_ms(2);
    
    lcdcmd(0x28);
    __delay_ms(15);
    lcdcmd(0x01);
    __delay_ms(10);
    lcdcmd(0x06);
    __delay_ms(10);
    lcdcmd(0x80);
    __delay_ms(10);
    lcdcmd(0x0c);
    __delay_ms(10);
    				}
    
    void main(){        
            lcd_init();       
    			while(1){	
    				display();
    		
    			}
    }
    Dear Justin I have a another Small thing to verify. As per the bellow codes you have sent three time (0x30) value directly to LCD without go through lcdcmd();. can you please explain it more for me.
    Thanks in advance

    Code:
    _delay_us(10);  
    	LCD_DATA =0X30;
         	LCD_STROBE;
           	__delay_ms(2);
    
           LCD_RS=0;
           __delay_us(10);  
    	LCD_DATA =0X30;
         	LCD_STROBE;
    	__delay_ms(2);
    
            LCD_RS=0;
           __delay_us(10);  
    	LCD_DATA =0X30;
           	LCD_STROBE;
    	__delay_ms(2);
    
           LCD_RS=0;
           __delay_us(10);  
    	LCD_DATA =0X20;
         	LCD_STROBE;
    	__delay_ms(2);



    •   AltAdvertisment

        
       

  4. #4
    Advanced Member level 1
    Points: 3,016, Level: 12
    Jestin_cubetech's Avatar
    Join Date
    Jun 2012
    Posts
    499
    Helped
    74 / 74
    Points
    3,016
    Level
    12
    Blog Entries
    6

    Re: My LCD 4bit mode program is not working

    as per the LCD datasheet...
    ----------------------------------------------
    One man's fault is other man's lesson...
    ----------------------------------------------


    1 members found this post helpful.

  5. #5
    Advanced Member level 3
    Points: 4,748, Level: 16
    Achievements:
    7 years registered
    PA3040's Avatar
    Join Date
    Aug 2011
    Posts
    841
    Helped
    43 / 43
    Points
    4,748
    Level
    16

    Re: My LCD 4bit mode program is not working

    Dear Jestin,

    It would be much appreciated,if you can attached a such datasheet

    Thanks
    Again and again



    •   AltAdvertisment

        
       

  6. #6
    Advanced Member level 1
    Points: 3,016, Level: 12
    Jestin_cubetech's Avatar
    Join Date
    Jun 2012
    Posts
    499
    Helped
    74 / 74
    Points
    3,016
    Level
    12
    Blog Entries
    6

    Re: My LCD 4bit mode program is not working

    LCD16X2 Datasheet
    ----------------------------------------------
    One man's fault is other man's lesson...
    ----------------------------------------------



  7. #7
    Advanced Member level 1
    Points: 3,527, Level: 13

    Join Date
    May 2012
    Posts
    482
    Helped
    112 / 112
    Points
    3,527
    Level
    13

    Re: My LCD 4bit mode program is not working

    You send the code 30H three times to the LCD to initialize it.



--[[ ]]--