View previous topic :: View next topic |
Author |
Message |
sahu77
Joined: 08 Sep 2011 Posts: 202
|
lcd_driver |
Posted: Wed Jan 04, 2012 12:29 pm |
|
|
what say about this lcd_driver.....
Code: | #define LCD_D4 PIN_C0
#define LCD_D5 PIN_C1
#define LCD_D6 PIN_C2
#define LCD_D7 PIN_C3
#define LCD_EN PIN_C4
#define LCD_RS PIN_C5
/**************************
LCD
**************************/
void LCD_Init ( void );
void LCD_SetPosition ( unsigned int cX );
void LCD_PutChar ( unsigned int cX );
void LCD_PutCmd ( unsigned int cX );
void LCD_PulseEnable ( void );
void LCD_SetData ( unsigned int cX );
///////////////////////////////////////////
// LCD FUNCTIONS =================================
void LCD_Init ( void )
{
LCD_SetData ( 0x00 );
delay_ms ( 200 ); // wait enough time after Vdd rise
output_low ( LCD_RS );
LCD_SetData ( 0x03 ); // init with specific nibbles to start 4-bit mode
LCD_PulseEnable();
LCD_PulseEnable();
LCD_PulseEnable();
LCD_SetData ( 0x02 ); // set 4-bit interface
LCD_PulseEnable(); // send dual nibbles hereafter, MSN first
LCD_PutCmd ( 0x2C ); // function set (all lines, 5x7 characters)
LCD_PutCmd ( 0x0C ); // display ON, cursor off, no blink
LCD_PutCmd ( 0x01 ); // clear display
LCD_PutCmd ( 0x06 ); // entry mode set, increment
}
void LCD_SetPosition ( unsigned int cX )
{
// this subroutine works specifically for 4-bit Port A
LCD_SetData ( swap ( cX ) | 0x08 );
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) );
LCD_PulseEnable();
}
void LCD_PutChar ( unsigned int cX )
{
// this subroutine works specifically for 4-bit Port A
output_high ( LCD_RS );
LCD_SetData ( swap ( cX ) ); // send high nibble
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) ); // send low nibble
LCD_PulseEnable();
output_low ( LCD_RS );
}
void LCD_PutCmd ( unsigned int cX )
{
// this subroutine works specifically for 4-bit Port A
LCD_SetData ( swap ( cX ) ); // send high nibble
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) ); // send low nibble
LCD_PulseEnable();
}
void LCD_PulseEnable ( void )
{
output_high ( LCD_EN );
delay_us ( 10 );
output_low ( LCD_EN );
delay_ms ( 5 );
}
void LCD_SetData ( unsigned int cX )
{
output_bit ( LCD_D4, cX & 0x01 );
output_bit ( LCD_D5, cX & 0x02 );
output_bit ( LCD_D6, cX & 0x04 );
output_bit ( LCD_D7, cX & 0x08 );
}
|
pl give comments _________________ sahu |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Jan 04, 2012 1:39 pm |
|
|
1- not sure why you don't use Flex LCD
2- this code ties up port C PIN functions for DIO - yet those c port pins are often used for more productive stuff than LCD driving
3- does it work for you or not? |
|
![](templates/subSilver/images/spacer.gif) |
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Wed Jan 04, 2012 1:45 pm |
|
|
this driver save up to 17% ROM. _________________ sahu |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9178 Location: Greensville,Ontario
|
|
Posted: Wed Jan 04, 2012 2:54 pm |
|
|
Ok but...
You can save 100% ROM if you use the LCD in 8 bit mode. Yes, it'll cost you 4 more I/O pins but saves you space.
Or you can save 100% ROM if you use a serial LCD module,This will also save you 6 I/O pins but cost you another PIC to make the serial LCD interface( $1 ?).
Like everything else.. there's a tradeoff. It's up to you to decide which is better. |
|
![](templates/subSilver/images/spacer.gif) |
|