lcd.h File Reference

LCD routines. More...

Include dependency graph for lcd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define __lcd_h   include
#define LCD_CLEAR_DISP   0b00000001
#define lcd_clear_display()   lcd_write_command(LCD_CLEAR_DISP);
 Clear LCD display.
#define LCD_LINE1   0b10000000
#define LCD_LINE2   0b11000000
#define LCD_LINE3   0b10010100
#define LCD_LINE4   0b11010100
#define lcd_return_home()   lcd_write_command(LCD_RETURN_HOME);
 Return cursor home.
#define LCD_RETURN_HOME   0b00000010
#define LCD_SET_DRAM_ADDR   0b10000000

Functions

void lcd_init ()
 Initialise LCD ready for display.
void lcd_setup ()
 Setup port and pins to talk to LCD.
void lcd_wait_busy ()
 Wait while LCD is busy.
void lcd_write_command (uns8 data)
 Sends a command to the LCD.
void lcd_write_data (uns8 data)
 Send one byte of data to the LCD.
void lcd_write_data_int (uns16 i)
 Print a 16 bit integer the the LCD.
void lcd_write_data_str (char *str)
 Print a string to the LCD.

Detailed Description

This module contains routines to communicate with an LCD via the 4 bit parallel mode. All pins are protected from read-before-write problems with picpack's port latch simulation. Reads ready flag to check LCD isn't busy before sending more data.


Define Documentation

#define __lcd_h   include
#define LCD_CLEAR_DISP   0b00000001

Clear LCD display

 
#define lcd_clear_display (  )     lcd_write_command(LCD_CLEAR_DISP);
#define LCD_LINE1   0b10000000

Move cursor to line 1

#define LCD_LINE2   0b11000000

Move cursor to line 2

#define LCD_LINE3   0b10010100

Move cursor to line 3

#define LCD_LINE4   0b11010100

Move cursor to line 4

 
#define lcd_return_home (  )     lcd_write_command(LCD_RETURN_HOME);
#define LCD_RETURN_HOME   0b00000010

Move cursor to top left position

#define LCD_SET_DRAM_ADDR   0b10000000

Move to DRAM address (cursor position)


Function Documentation

void lcd_init (  ) 

Configures LCD for 4 bit operation and gets ready for displaying text

00084                 {
00085     
00086     delay_ms(16);
00087     lcd_write_nibble(0x03);
00088     lcd_toggle_e();
00089     delay_ms(5);
00090     lcd_write_nibble(0x03);
00091     lcd_toggle_e();
00092     delay_ms(1);
00093     lcd_write_nibble(0x03);
00094     lcd_toggle_e();
00095     lcd_write_nibble(0x02); //0b 0010 1000
00096     lcd_toggle_e();
00097     
00098     // Now we are in 4bit mode
00099 
00100     lcd_write_command(0b00101000); // 0x28 numlines=1 font=0
00101     
00102     lcd_write_command(0b00001000); // disp off, curs off blink off
00103     
00104     lcd_write_command(0b00000110); // cursor move, inc, no shift
00105 
00106     lcd_write_command(0b00001100); // disp on, curs on blink on
00107 
00108     lcd_write_command(LCD_CLEAR_DISP);
00109     lcd_write_command(LCD_RETURN_HOME);
00110 
00111 }

Here is the call graph for this function:

void lcd_setup (  ) 

Call this routine first, to set up tris bits correctly to talk to the LCD

00067                  {
00068     
00069     // Set up tris bits
00070     make_output(lcd_e_port, lcd_e_pin);
00071     make_output(lcd_rs_port, lcd_rs_pin);
00072     make_output(lcd_rw_port, lcd_rw_pin);
00073     make_output(lcd_db7_port, lcd_db7_pin);
00074     make_output(lcd_db6_port, lcd_db6_pin);
00075     make_output(lcd_db5_port, lcd_db5_pin);
00076     make_output(lcd_db4_port, lcd_db4_pin);
00077     
00078     clear_pin(lcd_e_port, lcd_e_pin);
00079     clear_pin(lcd_rs_port, lcd_rs_pin);
00080     clear_pin(lcd_rw_port, lcd_rw_pin);
00081 }

void lcd_wait_busy (  ) 

Internal routine to wait while the LCD is busy and unable to accept more data

00154                      {
00155 
00156         
00157     set_bit(tris_array[lcd_db7_port - PORTA], lcd_db7_pin); // db7 input
00158     set_bit(tris_array[lcd_db6_port - PORTA], lcd_db6_pin); // db6 input
00159     set_bit(tris_array[lcd_db5_port - PORTA], lcd_db5_pin); // db5 input
00160     set_bit(tris_array[lcd_db4_port - PORTA], lcd_db4_pin); // db4 input
00161 
00162 
00163     clear_pin(lcd_rs_port, lcd_rs_pin);
00164     set_pin(lcd_rw_port, lcd_rw_pin);
00165 
00166     char counter = 0;
00167     
00168     set_pin(lcd_e_port, lcd_e_pin);
00169     // Wait for completion of the operation, with a timeout of ~.5 seconds
00170     // LCD d7 is high if the operation is complete.
00171     while ((test_pin(lcd_db7_port, lcd_db7_pin) == 1) && counter < 0xF0){
00172         clear_pin(lcd_e_port, lcd_e_pin);
00173         set_pin(lcd_e_port, lcd_e_pin);
00174         delay_us(100);
00175         clear_pin(lcd_e_port, lcd_e_pin);
00176         //delay_us(100);
00177         counter++;
00178     }
00179 
00180 
00181     // Check if the previous loop timed out     
00182     if (counter == 0xF0) {
00183     }
00184     
00185     clear_bit(tris_array[lcd_db7_port - PORTA], lcd_db7_pin); // db7 output
00186     clear_bit(tris_array[lcd_db6_port - PORTA], lcd_db6_pin); // db6 output
00187     clear_bit(tris_array[lcd_db5_port - PORTA], lcd_db5_pin); // db5 output
00188     clear_bit(tris_array[lcd_db4_port - PORTA], lcd_db4_pin); // db4 output
00189 
00190     return;
00191 }   

Here is the caller graph for this function:

void lcd_write_command ( uns8  data  ) 

Use this to send commands to the LCD, eg, changing cursor position

00113                                   {
00114 
00115     lcd_wait_busy();    
00116 
00117     clear_pin(lcd_rs_port, lcd_rs_pin);
00118     clear_pin(lcd_rw_port, lcd_rw_pin);
00119 
00120     lcd_write_byte(data);
00121 }

Here is the call graph for this function:

Here is the caller graph for this function:

void lcd_write_data ( uns8  data  ) 

00123                                {
00124     lcd_wait_busy();    
00125 
00126     set_pin(lcd_rs_port, lcd_rs_pin);
00127     clear_pin(lcd_rw_port, lcd_rw_pin);
00128     
00129     lcd_write_byte(data);
00130 }

Here is the call graph for this function:

void lcd_write_data_int ( uns16  i  ) 

Displays an unsigned 16 bit integer on the LCD

00145                                  {
00146 
00147 char buffer[6];
00148 
00149     itoa( i, buffer, 10 );
00150     lcd_write_data_str(buffer);
00151 }

Here is the call graph for this function:

void lcd_write_data_str ( char *  str  ) 

Display the string on the LCD from the current cursor position

00132                                    {
00133 
00134     lcd_wait_busy();    
00135 
00136     set_pin(lcd_rs_port, lcd_rs_pin);
00137     clear_pin(lcd_rw_port, lcd_rw_pin);
00138 
00139     
00140     while (*str) {
00141         lcd_write_byte(*str++);
00142     }   
00143 }       

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Fri Aug 19 09:06:51 2011 for Pic Pack Library by  doxygen 1.6.1