Functions | |
void | lcd_cursor_home () |
void | lcd_init () |
Initialise LCD ready for display. | |
void | lcd_set_cgram_pos (uns8 x) |
void | lcd_set_ddram_pos (uns8 x) |
void | lcd_setup () |
Setup port and pins to talk to LCD. | |
void | lcd_toggle_e () |
void | lcd_wait_busy () |
Wait while LCD is busy. | |
void | lcd_write_byte (uns8 data) |
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. | |
void | lcd_write_nibble (uns8 data) |
void lcd_cursor_home | ( | ) |
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 }
void lcd_set_cgram_pos | ( | uns8 | x | ) |
00198 { 00199 x.7 = 0; // indicate we are setting cgram 00200 x.6 = 1; 00201 lcd_write_command(x); 00202 }
void lcd_set_ddram_pos | ( | uns8 | x | ) |
00193 { 00194 x.7 = 1; // Set MSB bit, which indicates we are setting the RAM address 00195 lcd_write_command(x); 00196 }
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_toggle_e | ( | ) |
00040 { 00041 set_pin(lcd_e_port, lcd_e_pin); 00042 delay_us(50); // Despite the datasheet, 50us seems to be the right number... 00043 clear_pin(lcd_e_port, lcd_e_pin); 00044 delay_us(50); // Despite the datasheet, 50us seems to be the right number... 00045 }
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 }
void lcd_write_byte | ( | uns8 | data | ) |
00058 { 00059 00060 lcd_write_nibble(data >> 4); // Write upper nibble 00061 lcd_toggle_e(); 00062 lcd_write_nibble(data); // Write lower nibble 00063 lcd_toggle_e(); 00064 }
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 }
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 }
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 }
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 }
void lcd_write_nibble | ( | uns8 | data | ) |
00047 { 00048 // There would be a more efficient way to do this if all the pins 00049 // were on the same port - but we can't guarantee that. At least 00050 // this way all pins are protected from read before write problems. 00051 00052 change_pin(lcd_db4_port, lcd_db4_pin, data.0); 00053 change_pin(lcd_db5_port, lcd_db5_pin, data.1); 00054 change_pin(lcd_db6_port, lcd_db6_pin, data.2); 00055 change_pin(lcd_db7_port, lcd_db7_pin, data.3); 00056 }