Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

My LCD 4bit mode program is not working

Status
Not open for further replies.

PA3040

Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Activity points
6,936
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 <htc.h>
#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
 

Attachments

  • lcd4bit.rar
    16.4 KB · Views: 65

LCD Initialization Error,Data out put Format Error.
 

Attachments

  • lcd4bit.rar
    77.4 KB · Views: 63
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
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 <htc.h>
#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);
 

Dear Jestin,

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

Thanks
Again and again
 

LCD16X2 Datasheet
 

Attachments

  • hd44780u.pdf
    279 KB · Views: 69

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

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top