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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/18/06 13:40
Read: times


 
#129675 - "delay.h" & "4bit_lcd.h"
Responding to: ???'s previous message
void delay_16us(unsigned int j)
{ 
  unsigned int i;
  for(i=0;i<j;i++);
}

void delay_ms(unsigned int j)
{
unsigned int i;
for(i=0;i<j;i++)
delay_16us(60);
}

4bit_lcd routine

//-------------------------------------------------------------------------------------------
#define lcd_delay 400	// the delay has been choosen in approximation. please tell me how to calculate delay
#define clear_disp 0x01 
 bit sel_reg=0;		// for data write/command write used in void lcd_cmdw(unsigned char a) 
//-------------------------------------------------------------------------------------------
void lcd_init_write(unsigned char a) // write into LCD port (used for both control and data pins)
{
	RS=0;
	RW=0;
	LCDport=a;
	EN=1;
	delay_16us(lcd_delay);
	EN=0;
}
//-------------------------------------------------------------------------------------------
void lcd_cmdw(unsigned char a)	 // choose between command/data write
{
	unsigned char temp;
	if(sel_reg)		 //	sel_reg=1 => data write
	{
		sel_reg=0;
		goto sel_data;
	}
	RS=0;

sel_data:
	RW=0;			 // Data/control WRITE
	temp=a;
	temp&=0xf0;		 // consider higher nible first
	LCDport&=0x0f;		 // consider only data pins
	LCDport|=temp;		 // write into data pins
	EN=1;
	delay_16us(lcd_delay);
	EN=0;
	temp=a<<4;		 // now consider lower nibble
	temp&=0xf0;
	LCDport&=0x0f;
	LCDport|=temp;
	EN=1;
	delay_16us(lcd_delay);
	EN=0;
}
//-------------------------------------------------------------------------------------------
void lcd_datw(unsigned char a)	 // data write
{
	sel_reg=1;		 // sel_reg=1 => data write, sel_reg=0 => command write
	RS=1;
	lcd_cmdw(a);
}

//-------------------------------------------------------------------------------------------
void lcd4_initialize(void)	 // hitachi compatible lcd initialization
{
	delay_16us(lcd_delay);
	lcd_init_write(0x30);
	delay_16us(lcd_delay);
	lcd_init_write(0x30);
	delay_16us(lcd_delay);
	lcd_init_write(0x30);
	delay_16us(lcd_delay);
	lcd_init_write(0x20);
	delay_16us(lcd_delay);
	lcd_cmdw(0x28);
	delay_16us(lcd_delay);
	lcd_cmdw(4);
	delay_16us(lcd_delay);
	lcd_cmdw(0x85);
	delay_16us(lcd_delay);
	lcd_cmdw(6);
	delay_16us(lcd_delay);
	lcd_cmdw(1);
	delay_16us(lcd_delay);
	lcd_cmdw(15);
}
//-------------------------------------------------------------------------------------------
void lcd_puts(char *aaa)	 // output a string of characters
{
	unsigned int i=0;
	for(;aaa[i]!=0;i++)
	 lcd_datw(aaa[i]);
}

//-------------------------------------------------------------------------------------------
void lcd_clr_line1(void)	// clear line1
{
	lcd_cmdw(0x80);
	lcd_puts("                ");
}
//-------------------------------------------------------------------------------------------
void lcd_clr_line2(void)	// clear line2
{
	lcd_cmdw(0xc0);
	lcd_puts("                ");
}
//-------------------------------------------------------------------------------------------


List of 4 messages in thread
TopicAuthorDate
Key scanning in C51            01/01/70 00:00      
   Post delay.h, 4bit:_lcd.h,            01/01/70 00:00      
      "delay.h" & "4bit_lcd.h"            01/01/70 00:00      
         Header files            01/01/70 00:00      

Back to Subject List