| ??? 12/27/07 02:22 Read: times |
#148758 - As You are using C, why not Responding to: ???'s previous message |
use it properly. Having cryptic hexadecimal codes scattered around is not the best possible effort on code clarity.
Here is an example: // ----------------------------------------------------------------------- // Some commands for LCD module // ----------------------------------------------------------------------- #define LCD_CMD_CLEAR 0x01 #define LCD_CMD_HOME 0x02 #define LCD_CMD_MODE(i,s) (0x04 | ((i)<<1) | (s)) #define LCD_CMD_CONTROL(d,c,b) (0x08 | ((d)<<2) | ((c)<<1) | (b)) #define LCD_CMD_SHIFT(s,d) (0x10 | ((s)<<3) | ((d)<<2) ) #define LCD_CMD_FUNCSET(d,n,f) (0x20 | ((d)<<4) | ((n)<<3) | ((f)<<2) ) #define LCD_CMD_CGASET(a) (0x40 | ((a) & 0x3F)) #define LCD_CMD_DDASET(a) (0x80 | (a) ) Obviously the above example is for 8 bit interface but hopefully You get the idea. The usage of those would be something like:
// -----------------------------------------------------------------------
// Initialize the LCD display.
// -----------------------------------------------------------------------
extern void LcdInit ( void ) {
uint8_t mycount;
// Our first assumption is that we have a LCD module in place
__lib_lcd_exists_flag = 1;
// First, set display interface - do this three times
for ( mycount = 0; mycount < 3; mycount++ ) {
ApplicationLcdDelay( 10 );
LcdCommand( LCD_CMD_FUNCSET(1,1,0) );
}
// Wait until the display is no more busy or we have ran out
// of time which means that we do not have the display
mycount = 0;
while ( (LcdBusy()) && ( mycount < 50 ) ) {
ApplicationLcdDelay( 1 );
}
if ( LcdBusy() ) {
__lib_lcd_exists_flag = 0;
return;
}
// Next step funnily enough is to switch the display on...
// We don't activate cursor or blinking. This is done
// later is the host application wishes to do that.
LcdWait( 5 );
LcdCommand( LCD_CMD_CONTROL(1,0,0) );
// Clear the display. Takes some milliseconds to finish
LcdClear();
// Set LCD entry mode
LcdWait( 5 );
LcdCommand( LCD_CMD_MODE(1,0) );
// So we are good so far. Now, let's write an address
// and try to read it back
// If we get the same address then we propably have a LCD
LcdWait( 5 );
LcdCommand( LCD_CMD_DDASET(5) );
LcdWait( 5 );
if ( LcdGetAddress() != 5 ) {
__lib_lcd_exists_flag = 0;
}
else {
__lib_lcd_exists_flag = 1;
LcdCommand( LCD_CMD_DDASET(0) );
}
}
|
| Topic | Author | Date |
| LCD 8x24 - samsung 0282a | 01/01/70 00:00 | |
| add. info | 01/01/70 00:00 | |
| add. info | 01/01/70 00:00 | |
| What language are you using? | 01/01/70 00:00 | |
| solved! | 01/01/70 00:00 | |
| Binary numbers in 'C' | 01/01/70 00:00 | |
| Wrong operator | 01/01/70 00:00 | |
| As You are using C, why not | 01/01/70 00:00 | |
| Do not use fixed delays - check for LCD busy | 01/01/70 00:00 | |
| I've found the opposite! | 01/01/70 00:00 | |
| Binary numbers in 'C' | 01/01/70 00:00 | |
| Infinite waits | 01/01/70 00:00 | |
| Actually it is time | 01/01/70 00:00 | |
| Another opposite | 01/01/70 00:00 | |
| and .. | 01/01/70 00:00 | |
| Whoaaaaaa..... | 01/01/70 00:00 | |
LCD Timeout | 01/01/70 00:00 | |
| Code formatting - avoid TABs | 01/01/70 00:00 | |
| Oh - sorry about that ... | 01/01/70 00:00 | |
| Did you see this? | 01/01/70 00:00 |



