Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/10/03 09:14
Read: times


 
#38694 - RE: interfacing lcd in c (4bit) init
Responding to: ???'s previous message
Here is the codeI've wrote for 68hc11 many years ago for 4 bit inititialization.

Regards
Stephane

/* PIA_ORA bits */
#ifndef PIA_ORA

#define RS		bit(1)
#define RW		bit(2)
#define E		bit(3)

#endif

/*-------------------------------------------------------------------
LCD Initialization
	HLCD_LcdInit(void)
--------------------------------------------------------------------*/
void HLCD_LcdInit(void)
{
	Pause ();

	
	PIA_ORA=0x38;
        Pause ();
        PIA_ORA=0x30;
        Pause ();
       
        PIA_ORA=0x38;
        Pause ();
        PIA_ORA=0x30;
        Pause ();
      
        PIA_ORA=0x38;
        Pause ();
        PIA_ORA=0x30;
        Pause ();
      
        PIA_ORA=0x28;
        Pause ();
        PIA_ORA=0x20;
        Pause ();
        
        
        LcdWrite(2,"x28"); /* Function set : 4 bits interface, no shift */
        LcdWrite(2,"x0C"); /* Display control : display on, cursor off, blink off */
        LcdWrite(2,"x06"); /* Entry mode set : increment mode, no display shift */
        LcdWrite(2,"x02"); /* return home */
        LcdWrite(2,"x01"); /* clear display */
                
	Pause ();                
}

/*-------------------------------------------------------------------
Send datas or instructions to the LCD display
	LcdWrite(U8 func,U8 *txt)
		u8Function = 1 : *txt contains datas
		u8Function = 2 : *txt contains instructions 
--------------------------------------------------------------------*/
void LcdWrite(U8 u8Function,U8 *au8String)
{	
	U8 u8InstData,u8Upper,u8Lower;
	
	/* datas */
	if (u8Function == 1) 
		{
		u8InstData = 0 | RS & ~RW;
		}
		
	/* instructions */	
	if (u8Function == 2) 			
		{
		u8InstData = 0 & ~RS & ~RW;
      		}
		
	/* Send the chain to the LCD display */		
	while (*au8String !=0)
		{
			u8Upper = *au8String & 0xF0 | u8InstData; /* RS=1 */
			u8Lower = (*au8String << 4) & 0xF0 | u8InstData; /* RS=1 */
			
			PIA_ORA = u8Upper | E; 
  			Pause ();
  			PIA_ORA = u8Upper & E;
  			Pause ();
  			PIA_ORA = u8Lower | E;
  			Pause ();
  			PIA_ORA = u8Lower & E;
  			Pause ();
  		
  			au8String++; /* next character */
		}
}




List of 12 messages in thread
TopicAuthorDate
interfacing lcd in c (4bit) init            01/01/70 00:00      
   RE: interfacing lcd in c (4bit) init            01/01/70 00:00      
      RE: interfacing lcd in c (4bit) init            01/01/70 00:00      
   RE: interfacing lcd in c (4bit) init            01/01/70 00:00      
      RE: interfacing lcd in c (4bit) init            01/01/70 00:00      
         RE: interfacing lcd in c (4bit) init            01/01/70 00:00      
            RE: interfacing lcd in c (4bit) init            01/01/70 00:00      
               RE: interfacing lcd in c (4bit) init            01/01/70 00:00      
                  RE: interfacing lcd in c (4bit) init            01/01/70 00:00      
                     RE: interfacing lcd in asm (4bit)            01/01/70 00:00      
   RE: interfacing lcd in c (4bit) init            01/01/70 00:00      
      RE: interfacing lcd in c (4bit) init            01/01/70 00:00      

Back to Subject List