PIC LCD Source Hi-Tech
PIC Software - lcd.c for Hi-Tech
<source lang="c"> /* This version is written to use the Hi-Tech lite (free) compiler */
- include <htc.h>
- include "lcd.h"
void lcd_command( char command ) /* Sends the given command to the LCD display. Most of the commands are */ /* defined in the header. This function will wait for the busy flag on the */ /* display to clear before sending the command and returning. */ {
LCD_RS_LINE = 0; PORTC = command; LCD_EN_LINE = 0; _delay( 40 ); LCD_EN_LINE = 1;
if (command == LCD_CLEAR || command == LCD_CUR_HOME) _delay( 1500 );
}
void lcd_character( char character )
/* Sends the given character to the LCD display. ASCII Numbers and letters */
/* are valid, and punctuation below 0x7F. Characters 0x00 to 0x0F are the */
/* Generated Characters, which will be blank initially. Other useful symbols */
/* and Greek characters may be found in the range 0x80 to 0xFF */
{
LCD_RS_LINE = 1; PORTC = character; LCD_EN_LINE = 0; _delay( 40 ); LCD_EN_LINE = 1;
}
void lcd_number( int number )
/* Sends the given number to the LCD display, with up to 2 characters. This */
/* limits number to 100 */
{
int tens = 0; int units = 0;
while( number > 9 ) { tens++; number -= 10; } units = number; lcd_character( '0' + tens ); lcd_character( '0' + units );
}
void lcd_initialise( int size )
/* Initialises the display incase the initialisation at startup failed or the */
/* cursor size is to be changed. 'size' is LCD_SIZE_SMALL or LCD_SIZE_LARGE */
{
LCD_RW_LINE = 0;
lcd_command( size ); lcd_command( LCD_DISP_OFF ); lcd_command( LCD_DISP_ON ); lcd_command( LCD_CUR_INC ); lcd_command( LCD_CLEAR );
} </source>