/***************************************************************************/
/* */
/* LcdTest.c */
/* LCD interface implementation */
/* */
/* */
/* Version Date Comments */
/*-------------------------------------------------------------------------*/
/* 1.3 19/07/1999 Original release. */
/* 1.4 11/12/1999 Added WriteLCDString(const char *) */
/* */
/* */
/*-------------------------------------------------------------------------*/
/* */
/* */
/* By: J. Winpenny */
/* */
/* */
/* */
/* */
/*-------------------------------------------------------------------------*/
/* Mode : HD44780 type LCD */
/* */
/* Interface : SEL = Port B bit 3 */
/* WR = Port B bit 2 */
/* RS = Port B bit 1 */
/* */
/* Data_7 = Port A bit 3 */
/* Data_6 = Port A bit 2 */
/* Data_5 = Port A bit 1 */
/* Data_4 = Port A bit 0 */
/* */
/* */
/* This version is for 4 bit mode */
/* */
/* */
/* Add notes: PIC16F84A, 4Mhz, LCD 16x2 */
/* */
/***************************************************************************/
#include "LCDTest.h"
void delayM1(void)
{
delay_ms(1);
}
void delayMS5(void)
{
delay_ms(5);
}
void delayMS2(void)
{
delay_ms(2);
}
/***********************************/
/* Setup the lcd device */
/***********************************/
void LCD_Setup(void)
{
/* Reset the LCD */
/* Power up delay */
delay_ms(30);
LCD_FunctionMode();
/* This sequence resets the LCD */
LCD_Write_8_Bit( system_set_4_bit );
delayMS5();
LCD_Write_8_Bit( system_set_4_bit );
delayMS5();
LCD_Write_8_Bit( system_set_4_bit );
delayMS5();
LCD_Write_4_Bit( system_set_4_bit );
delayMS2();
LCD_Write_4_Bit( display_off );
delayMS2();
LCD_Write_4_Bit( entry_mode );
delayMS2();
LCD_Write_4_Bit( display_on );
delayMS2();
LCD_Write_4_Bit( set_dd_ram );
delayMS2();
LCD_DataMode();
}
/***********************************/
/* Put LCD in Function Mode */
/***********************************/
void LCD_FunctionMode(void)
{
output_low_port_b( LCD_RS );
delayM1();
}
/***********************************/
/* Put LCD in Data Mode */
/***********************************/
void LCD_DataMode(void)
{
output_high_port_b( LCD_RS );
delayM1();
}
/***********************************/
/* Write a single byte to the LCD */
/* 8 Bit Mode */
/***********************************/
void LCD_Write_8_Bit(char d )
{
/* Write Mode */
output_low_port_b( LCD_WR );
delayM1();
/* Setup data */
if ( d & 0x80 )
output_high_port_a( LCD_DATA_7 );
else output_low_port_a( LCD_DATA_7 );
if ( d & 0x40 )
output_high_port_a( LCD_DATA_6 );
else output_low_port_a( LCD_DATA_6 );
if ( d & 0x20 )
output_high_port_a( LCD_DATA_5 );
else output_low_port_a( LCD_DATA_5 );
if ( d & 0x10 )
output_high_port_a( LCD_DATA_4 );
else output_low_port_a( LCD_DATA_4 );
delayM1();
/* Select LCD */
output_high_port_b( LCD_SEL );
delayM1();
/* De-select LCD */
output_low_port_b( LCD_SEL );
}
/***********************************/
/* Write a single byte to the LCD */
/* 4 Bit Mode */
/***********************************/
void LCD_Write_4_Bit(char d )
{
/* Write Mode */
output_low_port_b( LCD_WR );
delayM1();
/* Output Higher 4 bits */
if ( d & 0x80 )
output_high_port_a( LCD_DATA_7 );
else output_low_port_a( LCD_DATA_7 );
if ( d & 0x40 )
output_high_port_a( LCD_DATA_6 );
else output_low_port_a( LCD_DATA_6 );
if ( d & 0x20 )
output_high_port_a( LCD_DATA_5 );
else output_low_port_a( LCD_DATA_5 );
if ( d & 0x10 )
output_high_port_a( LCD_DATA_4 );
else output_low_port_a( LCD_DATA_4 );
delayM1();
output_high_port_b( LCD_SEL );
delayM1();
/* Clock in the data */
output_low_port_b( LCD_SEL );
delayM1();
/* Output Lower 4 bits */
d <<= 4;
if ( d & 0x80 )
output_high_port_a( LCD_DATA_7 );
else output_low_port_a( LCD_DATA_7 );
if ( d & 0x40 )
output_high_port_a( LCD_DATA_6 );
else output_low_port_a( LCD_DATA_6 );
if ( d & 0x20 )
output_high_port_a( LCD_DATA_5 );
else output_low_port_a( LCD_DATA_5 );
if ( d & 0x10 )
output_high_port_a( LCD_DATA_4 );
else output_low_port_a( LCD_DATA_4 );
delayM1();
output_high_port_b( LCD_SEL );
/* Clock in the data */
delayM1();
output_low_port_b( LCD_SEL );
}
/*******************************************/
/* Write a const string to the LCD */
/*******************************************/
void WriteLCDString( const char *lcdptr )
{
char pi;
pi = 0;
// Check for end of string
while( lcdptr[pi] != 0 )
{
// Display on LCD
LCD_Write_4_Bit( lcdptr[pi++] );
}
}
/*******************************************/
/* Write a const string to the LCD */
/*******************************************/
void WriteVaribleString( void )
{
char i;
for (i=0;i<=15;i++)
{
LCD_Write_4_Bit( texto[i] );
}
}
Copyright © 2002-2006 SourceBoost Technologies