Operácie

AVR lcd.c: Rozdiel medzi revíziami

Zo stránky SensorWiki

Balogh (diskusia | príspevky)
Nová stránka: #include "lcd.h" // *********************************************************** // ******************** PUBLIC FUNCTIONS ********************* // **********************************...
 
Balogh (diskusia | príspevky)
Bez shrnutí editace
 
(Jedna medziľahlá úprava od rovnakého používateľa nie je zobrazená.)
Riadok 1: Riadok 1:
<source lang="c">
#include "lcd.h"
#include "lcd.h"




// ***********************************************************
// **************************************************************************
// ******************** PUBLIC FUNCTIONS *********************
// *************************** PUBLIC FUNCTIONS *****************************
// ***********************************************************
// **************************************************************************


void lcdInit4(void)
void lcdInit4(void)
{                                         // initialize LCD control & data  
{
    // Following two lines are a must when using BOOTLOADER:
 
    UCSR0B = 0x00;                          // Disable RxD and TxD for UART0
                                            // Disable ALL interrupts (Global)
    SREG = SREG & 0x7F;                    // same as cli(); without Interrupts.h
 
                                            // initialize LCD control & data
    // lines to output
    // lines to output
  PORTD = 0b00000001; // pull-up on unused input
DDRD  = 0b11111110; // set ctrl & data as outputs


PORTD = 0b00000001; // pull-up on unused input
_delay_ms(50);        // -  wait 15ms or more
DDRD  = 0b11111110; // set ctrl & data as outputs
 
delay_ms(50);        // -  wait 15ms or more
// -------------------
// -------------------
CLEARBIT(PORTD, LCD_CTRL_RS); // set RS to "control"
CLEARBIT(PORTD, LCD_CTRL_RS); // set RS to "control"
Riadok 19: Riadok 26:
// 4 bit write
// 4 bit write
SETBIT(PORTD, LCD_CTRL_E);     // set "E" line
SETBIT(PORTD, LCD_CTRL_E);     // set "E" line
// PORTD = (PORTD | 0x30) & 0x3F;          // output data, high 4 bits
PORTD = (PORTD | 0x30) & 0x3F;          // output data, high 4 bits
PORTD = (PORTD | 0x20) & 0x2F;          // output data, high 4 bits
LCD_DELAY;     // wait
LCD_DELAY;     // wait
CLEARBIT(PORTD, LCD_CTRL_E); // clear "E" line
CLEARBIT(PORTD, LCD_CTRL_E); // clear "E" line
// -------------------
// -------------------
delay_ms(5);             // -  wait 4.1ms
_delay_ms(5);             // -  wait 4.1ms
SETBIT(PORTD, LCD_CTRL_E);         // set "E" line
SETBIT(PORTD, LCD_CTRL_E);         // set "E" line
LCD_DELAY; // wait
LCD_DELAY; // wait
CLEARBIT(PORTD, LCD_CTRL_E); // clear "E" line
CLEARBIT(PORTD, LCD_CTRL_E); // clear "E" line
// -------------------
// -------------------
     delay_ms(1);                         // -  wait 0.1ms
     _delay_ms(1);                         // -  wait 0.1ms
SETBIT(PORTD, LCD_CTRL_E);     // set "E" line
SETBIT(PORTD, LCD_CTRL_E);     // set "E" line
LCD_DELAY;         // wait
LCD_DELAY;         // wait
CLEARBIT(PORTD, LCD_CTRL_E); // clear "E" line
CLEARBIT(PORTD, LCD_CTRL_E); // clear "E" line
// -------------------  
// -------------------
while(lcdBusy()) /* wait */ ;           // check for not busy
    _delay_ms(1);                         // -  wait 0.1ms
     // -------------------
     // -------------------
PORTD = (PORTD | 0x20) & 0x2F;         // output data, high 4 bits
PORTD = (PORTD | 0x20) & 0x2F;         // output data, high 4 bits
Riadok 42: Riadok 48:
// -------------------
// -------------------
lcdControlWrite(0x28); // 0x28 - function set (2 rows, 5x8 font)
lcdControlWrite(0x28); // 0x28 - function set (2 rows, 5x8 font)
lcdControlWrite(0x08); // 0x08 - display OFF
    _delay_ms(50);
lcdControlWrite(0x01); // 0x01 - clear display  
lcdControlWrite(0x0C); // 0x0C - display ON, cursor OFF
lcdControlWrite(0x01); // 0x01 - clear display
lcdControlWrite(0x06); // 0x06 - shift right
lcdControlWrite(0x06); // 0x06 - shift right
lcdControlWrite(0x0C); // 0x0C - display ON, cursor OFF
 
}
}


Riadok 58: Riadok 64:
{
{
while(lcdBusy()) /* wait here */ ; // wait until LCD not busy  or timeout
while(lcdBusy()) /* wait here */ ; // wait until LCD not busy  or timeout
 
CLEARBIT(PORTD, LCD_CTRL_RS);     // set RS to "control"
CLEARBIT(PORTD, LCD_CTRL_RS);     // set RS to "control"
CLEARBIT(PORTD, LCD_CTRL_RW);     // set R/W to "write"
CLEARBIT(PORTD, LCD_CTRL_RW);     // set R/W to "write"
 
PORTD = (PORTD&0x0F)|(c_data&0xF0);     // output data, high 4 bits
PORTD = (PORTD&0x0F)|(c_data&0xF0);     // output data, high 4 bits
SETBIT(PORTD, LCD_CTRL_E);         // set "E" line
SETBIT(PORTD, LCD_CTRL_E);         // set "E" line
Riadok 70: Riadok 76:
SETBIT(PORTD, LCD_CTRL_E);         // set "E" line
SETBIT(PORTD, LCD_CTRL_E);         // set "E" line
LCD_DELAY; // wait
LCD_DELAY; // wait
CLEARBIT(PORTD, LCD_CTRL_E);         // clear "E" line
CLEARBIT(PORTD, LCD_CTRL_E);         // clear "E" line
}
}


Riadok 77: Riadok 83:
{
{
while(lcdBusy()) /* wait */ ; // wait until LCD not busy or timeout
while(lcdBusy()) /* wait */ ; // wait until LCD not busy or timeout
 
SETBIT(PORTD, LCD_CTRL_RS);         // set RS to "data"
SETBIT(PORTD, LCD_CTRL_RS);         // set RS to "data"
CLEARBIT(PORTD, LCD_CTRL_RW);     // set R/W to "write"
CLEARBIT(PORTD, LCD_CTRL_RW);     // set R/W to "write"
 
PORTD = (PORTD&0x0F) | (w_data&0xF0); // output data, high 4 bits
PORTD = (PORTD&0x0F) | (w_data&0xF0); // output data, high 4 bits
SETBIT(PORTD, LCD_CTRL_E);             // set "E" line
SETBIT(PORTD, LCD_CTRL_E);             // set "E" line
LCD_DELAY; // wait
LCD_DELAY; // wait
CLEARBIT(PORTD, LCD_CTRL_E);     // clear "E" line
CLEARBIT(PORTD, LCD_CTRL_E);     // clear "E" line
 
PORTD = (PORTD&0x0F) | (w_data<<4);     // output data, low 4 bits
PORTD = (PORTD&0x0F) | (w_data<<4);     // output data, low 4 bits
SETBIT(PORTD, LCD_CTRL_E);         // set "E" line
SETBIT(PORTD, LCD_CTRL_E);         // set "E" line
LCD_DELAY; // wait
LCD_DELAY; // wait
CLEARBIT(PORTD, LCD_CTRL_E);     // clear "E" line
CLEARBIT(PORTD, LCD_CTRL_E);     // clear "E" line
}
}


/* ------------------------------------------------------- */
/* Outputs string to a LCD (at current position)          */
/*                                                        */
/* ------------------------------------------------------- */


  void lcdStringWrite(char* String)
  {
    register uint8_t i=0;


// ak vrati 1, OK
// check to make sure we have a good pointer
// ak vrati 0, vyprsal timeout
if (!String) return;


volatile unsigned char t_out_LCD; // timeout displeja (krok 1024 us)  
// print data
// krok 1ms
while (String[i])
{
lcdDataWrite(String[i]);
i++;
}
}
 
 
/* ------------------------------------------------------- */
/*  Read and debounce the LCD AppMod buttons              */
/*                                                        */
/*  Returns 0 if nothing  is pressed                      */
/*  Returns 1 if button A is pressed                      */
/*  Returns 2 if button B is pressed                      */
/*  Returns 4 if button C is pressed                      */
/*  Returns 8 if button D is pressed                      */
/*  Returns combination if more is pressed (e.g. 6 for B+C)*/
/*                                                        */
/* ------------------------------------------------------- */
 
unsigned char ReadButtons()
{
  DDRD  = 0b00001110;                // make LCD bus inputs
  unsigned char state = 0xFF;          // assume nothing pressed
 
  for(int scan = 1; scan<=10; scan++)
  {
  state = state & ((PIND&0xF0)>>4); // make sure button held
  _delay_ms(5);                    // debounce 10 x 5 ms
  }
 
  DDRD  = 0b11111110; // return bus to outputs
 
  return(state);
}
 
 
/* ------------------------------------------------------- */
/* Test whether LCD is BUSY or READY for next command      */
/*                                                        */
/* At the moment it is replaced by the fixed time delay    */
/*                                                        */
/* Return values: 1 - OK                                  */
/*                0 - timeout                              */
/* ------------------------------------------------------- */
 
volatile unsigned char t_out_LCD; // timeout displeja (krok 1024 us)
                                  // krok 1ms
unsigned char lcdBusy(void)
unsigned char lcdBusy(void)
{
{
  _delay_ms(1);
  return 0;


  delay_ms(10);
  return 0;
/*
/*
unsigned char pom;
unsigned char pom;
t_out_LCD=4; // pockam cca 4ms
t_out_LCD=4; // pockam cca 4ms
// wait until LCD busy bit goes to zero
// wait until LCD busy bit goes to zero
// do a read from control register
// do a read from control register
CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_RS); // set RS to "control"
 
  CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_RS); // set RS to "control"
LCD_DATA_PORT |=  0xF0; // set pull-ups to on (4bit)
 
LCD_DATA_DDR  &=  0x0F; // set data I/O lines to input (4bit)
  LCD_DATA_PORT |=  0xF0; // set pull-ups to on (4bit)
  LCD_DATA_DDR  &=  0x0F; // set data I/O lines to input (4bit)
SETBIT(LCD_CTRL_PORT, LCD_CTRL_RW); // set R/W to "read"
 
SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
  SETBIT(LCD_CTRL_PORT, LCD_CTRL_RW); // set R/W to "read"
LCD_DELAY; // wait
  SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
pom= LCD_DATA_PIN&0xF0; // input data, high 4 bits
  LCD_DELAY; // wait
CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
  pom= LCD_DATA_PIN&0xF0; // input data, high 4 bits
LCD_DELAY; // wait
  CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
  LCD_DELAY; // wait
LCD_DELAY; // wait
  SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
pom|=(LCD_DATA_PIN>>4)&0x0F; // input data, low 4 bits
  LCD_DELAY; // wait
CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
  pom|=(LCD_DATA_PIN>>4)&0x0F; // input data, low 4 bits
  CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
while ((pom & (1<<LCD_BUSY))  && t_out_LCD )
 
{
  while ((pom & (1<<LCD_BUSY))  && t_out_LCD )
SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
  {
LCD_DELAY; // wait
    SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
pom=LCD_DATA_PIN&0xF0; // input data, high 4 bits
    LCD_DELAY; // wait
CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
    pom=LCD_DATA_PIN&0xF0; // input data, high 4 bits
LCD_DELAY; // wait
    CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
    LCD_DELAY; // wait
LCD_DELAY; // wait
    SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
pom|=(LCD_DATA_PIN>>4)&0x0F; // input data, low 4 bits
    LCD_DELAY; // wait
CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
    pom|=(LCD_DATA_PIN>>4)&0x0F; // input data, low 4 bits
}
    CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
  }
// leave data lines in input mode so they can be most easily used for other purposes
 
// leave data lines in input mode so they can be most easily used for other purposes
if(t_out_LCD)
if(t_out_LCD)
return 1; // ak vrati 1 timeout OK  
return 1; // ak vrati 1 timeout OK
else  
else
return 0; // ak vrati 0 timeout notOK
return 0; // ak vrati 0 timeout notOK
*/
*/
Riadok 156: Riadok 219:


if(lcdBusyWait()) // wait until LCD not busy or time out
if(lcdBusyWait()) // wait until LCD not busy or time out
{
{
outb(LCD_DATA_PORT, inb(LCD_DATA_PORT)|0xF0); // set pull-ups to on (4bit)
outb(LCD_DATA_PORT, inb(LCD_DATA_PORT)|0xF0); // set pull-ups to on (4bit)
outb(LCD_DATA_DDR, inb(LCD_DATA_DDR)&0x0F); // set data I/O lines to input (4bit)
outb(LCD_DATA_DDR, inb(LCD_DATA_DDR)&0x0F); // set data I/O lines to input (4bit)
CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_RS); // set RS to "control"
CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_RS); // set RS to "control"
SETBIT(LCD_CTRL_PORT, LCD_CTRL_RW); // set R/W to "read"
SETBIT(LCD_CTRL_PORT, LCD_CTRL_RW); // set R/W to "read"
 
SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
LCD_DELAY; // wait
LCD_DELAY; // wait
Riadok 171: Riadok 234:
r_data |= inb(LCD_DATA_PIN)>>4; // input data, low 4 bits
r_data |= inb(LCD_DATA_PIN)>>4; // input data, low 4 bits
CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
 
// leave data lines in input mode so they can be most easily used for other purposes
// leave data lines in input mode so they can be most easily used for other purposes
}
}
return r_data;
return r_data;
}
}
Riadok 183: Riadok 246:


if(lcdBusyWait()) // wait until LCD not busy or time out
if(lcdBusyWait()) // wait until LCD not busy or time out
{
{
outb(LCD_DATA_PORT, inb(LCD_DATA_PORT)|0xF0); // set pull-ups to on (4bit)
outb(LCD_DATA_PORT, inb(LCD_DATA_PORT)|0xF0); // set pull-ups to on (4bit)
outb(LCD_DATA_DDR, inb(LCD_DATA_DDR)&0x0F); // set data I/O lines to input (4bit)
outb(LCD_DATA_DDR, inb(LCD_DATA_DDR)&0x0F); // set data I/O lines to input (4bit)
SETBIT(LCD_CTRL_PORT, LCD_CTRL_RS); // set RS to "data"
SETBIT(LCD_CTRL_PORT, LCD_CTRL_RS); // set RS to "data"
SETBIT(LCD_CTRL_PORT, LCD_CTRL_RW); // set R/W to "read"
SETBIT(LCD_CTRL_PORT, LCD_CTRL_RW); // set R/W to "read"
 
SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
SETBIT(LCD_CTRL_PORT, LCD_CTRL_E); // set "E" line
LCD_DELAY; // wait
LCD_DELAY; // wait
Riadok 198: Riadok 261:
r_data |= inb(LCD_DATA_PIN)>>4; // input data, low 4 bits
r_data |= inb(LCD_DATA_PIN)>>4; // input data, low 4 bits
CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E); // clear "E" line
 
}
}
// leave data lines in input mode so they can be most easily used for other purposes
// leave data lines in input mode so they can be most easily used for other purposes
return r_data;
return r_data;
Riadok 210: Riadok 273:
*/
*/


void delay_ms(unsigned int ms)
{
  unsigned int index;
  while (ms)
  {
  index = F_CPU / 5000;    // vypocitajte, kolko treba, aby sme dostali 1ms!!
       
  while (index)
  {
    asm volatile ("nop");
    index--;
  }


  ms--;
</source>
  }
}

Aktuálna revízia z 07:58, 28. október 2011

#include "lcd.h"


// **************************************************************************
// *************************** PUBLIC FUNCTIONS *****************************
// **************************************************************************

void lcdInit4(void)
{ 	
    // Following two lines are a must when using BOOTLOADER:

    UCSR0B = 0x00;                          // Disable RxD and TxD for UART0
                                            // Disable ALL interrupts (Global)
    SREG = SREG & 0x7F;                     // same as cli(); without Interrupts.h

                                            // initialize LCD control & data
										    // lines to output
   	PORTD = 0b00000001;						// pull-up on unused input
	DDRD  = 0b11111110;						// set ctrl & data as outputs

	_delay_ms(50);        					// -  wait 15ms or more
											// -------------------
	CLEARBIT(PORTD, LCD_CTRL_RS);			// set RS to "control"
	CLEARBIT(PORTD, LCD_CTRL_RW);			// set R/W to "write"
											// 4 bit write
	SETBIT(PORTD, LCD_CTRL_E);			    // set "E" line
	PORTD = (PORTD | 0x30) & 0x3F;          // output data, high 4 bits
	LCD_DELAY;							    // wait
	CLEARBIT(PORTD, LCD_CTRL_E);			// clear "E" line
											// -------------------
	_delay_ms(5); 				            // -  wait 4.1ms
	SETBIT(PORTD, LCD_CTRL_E);	 	        // set "E" line
	LCD_DELAY;								// wait
	CLEARBIT(PORTD, LCD_CTRL_E);			// clear "E" line
											// -------------------
    _delay_ms(1);	                        // -  wait 0.1ms
	SETBIT(PORTD, LCD_CTRL_E);			    // set "E" line
	LCD_DELAY;						        // wait
	CLEARBIT(PORTD, LCD_CTRL_E);			// clear "E" line
											// -------------------
    _delay_ms(1);	                        // -  wait 0.1ms
    										// -------------------
	PORTD = (PORTD | 0x20) & 0x2F;	        // output data, high 4 bits
	SETBIT(PORTD, LCD_CTRL_E);		        // set "E" line
	LCD_DELAY;								// wait
	CLEARBIT(PORTD, LCD_CTRL_E);		    // clear "E" line
											// -------------------
	lcdControlWrite(0x28);					// 0x28	- function set (2 rows, 5x8 font)
     _delay_ms(50);
	lcdControlWrite(0x0C);					// 0x0C - display ON, cursor OFF
	lcdControlWrite(0x01);					// 0x01 - clear display
	lcdControlWrite(0x06); 					// 0x06 - shift right

}


// ************************************************************
// ********************** LOCAL FUNCTIONS *********************
// ************************************************************


void lcdControlWrite(unsigned char c_data)  // write the CONTROL byte to the display controller
{
	while(lcdBusy()) /* wait here */ ;		// wait until LCD not busy  or timeout

	CLEARBIT(PORTD, LCD_CTRL_RS);		    // set RS to "control"
	CLEARBIT(PORTD, LCD_CTRL_RW);	    	// set R/W to "write"

	PORTD = (PORTD&0x0F)|(c_data&0xF0);	    // output data, high 4 bits
	SETBIT(PORTD, LCD_CTRL_E);		        // set "E" line
	LCD_DELAY;								// wait
	CLEARBIT(PORTD, LCD_CTRL_E);	        // clear "E" line

	PORTD = (PORTD&0x0F) | (c_data<<4);	    // output data, low 4 bits
	SETBIT(PORTD, LCD_CTRL_E);		        // set "E" line
	LCD_DELAY;								// wait
	CLEARBIT(PORTD, LCD_CTRL_E);	        // clear "E" line
}


void lcdDataWrite(unsigned char w_data)     // write a DATA byte to the display
{
	while(lcdBusy())	 /* wait */ ;		// wait until LCD not busy or timeout

	SETBIT(PORTD, LCD_CTRL_RS);		        // set RS to "data"
	CLEARBIT(PORTD, LCD_CTRL_RW);		    // set R/W to "write"

	PORTD = (PORTD&0x0F) | (w_data&0xF0);	// output data, high 4 bits
	SETBIT(PORTD, LCD_CTRL_E);	            // set "E" line
	LCD_DELAY;								// wait
	CLEARBIT(PORTD, LCD_CTRL_E);		    // clear "E" line

	PORTD = (PORTD&0x0F) | (w_data<<4);	    // output data, low 4 bits
	SETBIT(PORTD, LCD_CTRL_E);		        // set "E" line
	LCD_DELAY;								// wait
	CLEARBIT(PORTD, LCD_CTRL_E);		    // clear "E" line
}

/* ------------------------------------------------------- */
/* Outputs string to a LCD (at current position)           */
/*                                                         */
/* ------------------------------------------------------- */

  void lcdStringWrite(char* String)
   {
     register uint8_t i=0;

	// check to make sure we have a good pointer
	if (!String) return;

	// print data
	while (String[i])
	{
		lcdDataWrite(String[i]);
		i++;
	}
}


/* ------------------------------------------------------- */
/*  Read and debounce the LCD AppMod buttons               */
/*                                                         */
/*  Returns 0 if nothing  is pressed                       */
/*  Returns 1 if button A is pressed                       */
/*  Returns 2 if button B is pressed                       */
/*  Returns 4 if button C is pressed                       */
/*  Returns 8 if button D is pressed                       */
/*  Returns combination if more is pressed (e.g. 6 for B+C)*/
/*                                                         */
/* ------------------------------------------------------- */

unsigned char ReadButtons()
{
  DDRD  = 0b00001110;                // make LCD bus inputs
  unsigned char state = 0xFF;           // assume nothing pressed
  
  for(int scan = 1; scan<=10; scan++)
  {
   state = state & ((PIND&0xF0)>>4); // make sure button held
   _delay_ms(5);                     // debounce 10 x 5 ms
  }

  DDRD  = 0b11111110;				 // return bus to outputs
  
  return(state);
}


/* ------------------------------------------------------- */
/* Test whether LCD is BUSY or READY for next command      */
/*                                                         */
/* At the moment it is replaced by the fixed time delay    */
/*                                                         */
/* Return values: 1 - OK                                   */
/*                0 - timeout                              */
/* ------------------------------------------------------- */

volatile unsigned char t_out_LCD;  // timeout displeja (krok 1024 us)
                                   // krok 1ms
unsigned char lcdBusy(void)
{
   _delay_ms(1);
   return 0;

/*
unsigned char pom;
	t_out_LCD=4; // pockam cca 4ms
	
	// wait until LCD busy bit goes to zero

	// do a read from control register

   CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_RS);				// set RS to "control"

   LCD_DATA_PORT |=  0xF0;	// set pull-ups to on (4bit)
   LCD_DATA_DDR  &=  0x0F;	// set data I/O lines to input (4bit)

   SETBIT(LCD_CTRL_PORT, LCD_CTRL_RW);				// set R/W to "read"
   SETBIT(LCD_CTRL_PORT, LCD_CTRL_E);				// set "E" line
   LCD_DELAY;										// wait
   pom= LCD_DATA_PIN&0xF0;		// input data, high 4 bits
   CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E);		// clear "E" line
   LCD_DELAY;										// wait
   SETBIT(LCD_CTRL_PORT, LCD_CTRL_E);				// set "E" line
   LCD_DELAY;										// wait
   pom|=(LCD_DATA_PIN>>4)&0x0F;		// input data, low 4 bits
   CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E);		// clear "E" line

   while ((pom & (1<<LCD_BUSY))  && t_out_LCD )
   {
    SETBIT(LCD_CTRL_PORT, LCD_CTRL_E);				// set "E" line
    LCD_DELAY;										// wait
    pom=LCD_DATA_PIN&0xF0;		// input data, high 4 bits
    CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E);		// clear "E" line
    LCD_DELAY;										// wait
    SETBIT(LCD_CTRL_PORT, LCD_CTRL_E);				// set "E" line
    LCD_DELAY;										// wait
    pom|=(LCD_DATA_PIN>>4)&0x0F;		// input data, low 4 bits
    CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E);		// clear "E" line
   }

	//	leave data lines in input mode so they can be most easily used for other purposes
	if(t_out_LCD)
		return 1;	// ak vrati 1 timeout OK
	else
		return 0;		// ak vrati 0 timeout notOK
*/

}



/*
unsigned char lcdControlRead(void)
{
	// read the control byte from the display controller
	register unsigned char r_data=0;

	if(lcdBusyWait())	// wait until LCD not busy or time out
	{
		outb(LCD_DATA_PORT, inb(LCD_DATA_PORT)|0xF0);	// set pull-ups to on (4bit)
		outb(LCD_DATA_DDR, inb(LCD_DATA_DDR)&0x0F);	// set data I/O lines to input (4bit)
		CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_RS);				// set RS to "control"
		SETBIT(LCD_CTRL_PORT, LCD_CTRL_RW);				// set R/W to "read"

		SETBIT(LCD_CTRL_PORT, LCD_CTRL_E);	// set "E" line
		LCD_DELAY;							// wait
		r_data = inb(LCD_DATA_PIN)&0xF0;		// input data, high 4 bits
		CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E);	// clear "E" line
		LCD_DELAY;							// wait
		SETBIT(LCD_CTRL_PORT, LCD_CTRL_E);	// set "E" line
		LCD_DELAY;							// wait
		r_data |= inb(LCD_DATA_PIN)>>4;		// input data, low 4 bits
		CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E);	// clear "E" line

		//	leave data lines in input mode so they can be most easily used for other purposes
	}
	return r_data;
}

unsigned char lcdDataRead(void)
{
// read a data byte from the display
	register unsigned char r_data =0;

	if(lcdBusyWait())				// wait until LCD not busy or time out
	{
		outb(LCD_DATA_PORT, inb(LCD_DATA_PORT)|0xF0);	// set pull-ups to on (4bit)
		outb(LCD_DATA_DDR, inb(LCD_DATA_DDR)&0x0F);	// set data I/O lines to input (4bit)
		SETBIT(LCD_CTRL_PORT, LCD_CTRL_RS);				// set RS to "data"
		SETBIT(LCD_CTRL_PORT, LCD_CTRL_RW);				// set R/W to "read"

		SETBIT(LCD_CTRL_PORT, LCD_CTRL_E);	// set "E" line
		LCD_DELAY;							// wait
		r_data = inb(LCD_DATA_PIN)&0xF0;		// input data, high 4 bits
		CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E);	// clear "E" line
		LCD_DELAY;							// wait
		SETBIT(LCD_CTRL_PORT, LCD_CTRL_E);	// set "E" line
		LCD_DELAY;							// wait
		r_data |= inb(LCD_DATA_PIN)>>4;		// input data, low 4 bits
		CLEARBIT(LCD_CTRL_PORT, LCD_CTRL_E);	// clear "E" line

	}
	//	leave data lines in input mode so they can be most easily used for other purposes
	return r_data;
}





*/