??? 04/06/04 03:28 Read: times |
#67990 - RE: dont ban me! :) Responding to: ???'s previous message |
Here is come C code for LCD testing.
No main routine only functions you can use to set up and control the lcd. The Delay function is for a 24 MHz crystal. For a more readable code copy and past into a new text file. All of the code except display_alphabet has been tested and seems for work without any problems. #include "your_header_file" /* Rename Port 1 pin 7 BF (busy flag) for the LCD */ sbit BF = P1_7; /* Rename Port 3 pins Control lines for LCD */ sbit RW = P3_5; sbit RS = P3_6; sbit E = P3_7; void waste (unsigned char wastetime) { while (wastetime > 0) { unsigned char number = 0x00; for (number = 0; number < 0x01; ++number) { ++number; --number; } --wastetime; } } /* iDelayTime of 0xff gives an approximate .255 sec delay */ /* iDelayTime of 0x01 gives and approximate 1 ms delay */ void Delay (unsigned char iDelayTime) { while (iDelayTime > 0) { waste (0x63); --iDelayTime; } } void wait_LCD (void) /* used to check the check the status of the LCD */ { RS = 0; RW = 1; E = 1; BF = 1; /* configure BF to read its value */ while (BF) { waste (0x0F); /* delay while LCD is busy */ } E = 0; /* not busy so end the wait */ RW = 0; } } void command_LCD (char byte2send) /* used to send a commands to LCD */ { RS = 0; RW = 0; E = 1; P1 = byte2send; E = 0; } void display (char char2display) /* used to Display a character on the LCD */ { RS = 1; RW = 0; E = 1; P1 = char2display; E = 0; wait_LCD (); } void clear_display (void) /* clear the display of all characters and return cursor to row 1, column 1 */ { command_LCD (0x01); wait_LCD (); } void return_home (void) /* return cursor to row 1, column 1 (doesn't clear display) */ { command_LCD (0x02); wait_LCD; } void line_return (void) { command_LCD (0x0C0); wait_LCD; } void init_LCD (void) /* initialization by instruction */ { Delay (0x0ff); /* Delay at least 15ms */ command_LCD (0x30); /* Function set - 8 bit data bus */ Delay (0x05); /* Delay at least 4.1ms */ command_LCD (0x30); /* Function set - 8 bit data bus */ Delay (0x01); /* Delay at least 100us */ command_LCD (0x30); /* Function set - 8 bit data bus */ wait_LCD (); /* BF is now avaible for checking */ command_LCD (0x38); /* N=1 (2 rows) and F=0 (5x8 resolution) */ wait_LCD (); /* Wait for command to be sent */ command_LCD (0x08); /* Display off */ clear_display (): /* clear display */ command_LCD (0x06); /* increment DDRAM address by 1 after read or written to DDRAM I/D=1 S=0 */ wait_LCD (): /* Wait for command to be sent */ clear_display (); command_LCD (0x0E); /* D=1 (display on) C=1 (cursor on) B=0 (blinking off) */ wait_LCD (); /* Wait for command to be sent */ } void display_alphabet (void) /* all caps char A - Z */ { char alpha_ptr = 0x41; /* A */ unsigned char x = 0x00; for (x = 0; x < 0x10; x++) { display (alpha_ptr); alpha_ptr++; } line_return (); for (x = 0x10; x < 0x1A; x++) { display (alpha_ptr) alpha_ptr++; } } |
Topic | Author | Date |
dont ban me! :) | 01/01/70 00:00 | |
RE: dont ban me! :) | 01/01/70 00:00 | |
RE: dont ban me! :) | 01/01/70 00:00 | |
RE: dont ban me! :) | 01/01/70 00:00 | |
RE: Raghu | 01/01/70 00:00 | |
RE: dont ban me! :) | 01/01/70 00:00 | |
RE: dont ban me! :) | 01/01/70 00:00 | |
RE: dont ban me! :) | 01/01/70 00:00 | |
RE: dont ban me! :) | 01/01/70 00:00 | |
RE: dont ban me! :) | 01/01/70 00:00 | |
RE: dont ban me! :) | 01/01/70 00:00 | |
Application of mind- Steve | 01/01/70 00:00 | |
RE: Application of mind- Steve | 01/01/70 00:00 | |
RE: Application of mind- Steve | 01/01/70 00:00 | |
RE: Application of mind- Steve | 01/01/70 00:00 | |
RE: Application of mind- Eric![]() | 01/01/70 00:00 |