HD66717 code (WD-C2401P  24x1 LCD) + Arduino - Page 1
Forum section: electronics / beginners

author: jdev99
author_rank: Regular Contributor
timestamp: January 15, 2021, 06:50:57 pm
content: I have 1 of these 24x1 LCD displays that I would like to use in a project.I followed the advice herehttps://forum.arduino.cc/index.php?topic=78002.msg705823#msg705823and quickly got it going.I now would like to print a custom character but can not figure out how to do it.I attached a datasheet that I found.Can anybody please give me some advice?Thank you for any assistance.

author: jdev99
author_rank: Regular Contributor
timestamp: January 16, 2021, 04:44:30 pm
content: This is the code that I am working with, all works 100% except the custom character part:Code://////////////////////////////////////////////////////////////////////////////////// The WDC2401P class contains the following functions:// WDC2401P Class_Name(RS, EN, D0, D1, D2, D3, D4, D5, D6, D7); define class// The LCD pins to be remapped as listed above when calling the WDC2401P class// Initialize(); initialize the LCD// Clear(); clear the lcd display// CursorPos(position); sets the position for cursor (position is 0 to 23)// PrintChar(string); Prints a character string to the LCD// PrintNum(long); Prints the decimal value of long to LCD///////////////////////////////////////////////////////////////////////////////////unsigned char lock[]= {0x0E,0x11,0x11,0x1F,0x1B,0x1B,0x1F,0x00}; // lockunsigned char smiley[]= {0x00,0x00,0x0A,0x00,0x00,0x11,0x0E,0x00}; // smileyunsigned char sleepy[]= {0x00,0x00,0x0A,0x00,0x00,0x1F,0x00,0x00}; // sleepyunsigned char heart[]= {0x00,0x0a,0x1F,0x1F,0x0E,0x04,0x00,0x00}; // heartclass WDC2401P{private:byte _rs_pin; // define RS Arduino pin #byte _enable_pin; // define enable Arduino pin #byte _data_pin0; // define D0 Arduino pin #byte _data_pin1; // define D1 Arduino pin #byte _data_pin2; // define D2 Arduino pin #byte _data_pin3; // define D3 Arduino pin #byte _data_pin4; // define D4 Arduino pin #byte _data_pin5; // define D5 Arduino pin #byte _data_pin6; // define D6 Arduino pin #byte _data_pin7; // define D7 Arduino pin #WDC2401P& WriteCommand(byte Command = 0x01) // The following code writes a command to the LCD{digitalWrite(_rs_pin, LOW); // set LCD RS pin low for sending commandsdigitalWrite(_data_pin0, Command & 0x01); // set LCD bit d0digitalWrite(_data_pin1, Command & 0x02); // set LCD bit d1digitalWrite(_data_pin2, Command & 0x04); // set LCD bit d2digitalWrite(_data_pin3, Command & 0x08); // set LCD bit d3digitalWrite(_data_pin4, Command & 0x10); // set LCD bit d4digitalWrite(_data_pin5, Command & 0x20); // set LCD bit d5digitalWrite(_data_pin6, Command & 0x40); // set LCD bit d6digitalWrite(_data_pin7, Command & 0x80); // set LCD bit d7digitalWrite(_enable_pin, HIGH); // set LCD Enable Highdelay(2);digitalWrite(_enable_pin, LOW); // set LCD Enable low - This should latch datadelay(20); // A little delay to allow command to implament}WDC2401P& WriteData(byte Data = 0x01) // The following code writes data to the LCD{digitalWrite(_rs_pin, HIGH); // set LCD RS pin low for sending commandsdigitalWrite(_data_pin0, Data & 0x01); // set LCD bit d0digitalWrite(_data_pin1, Data & 0x02); // set LCD bit d1digitalWrite(_data_pin2, Data & 0x04); // set LCD bit d2digitalWrite(_data_pin3, Data & 0x08); // set LCD bit d3digitalWrite(_data_pin4, Data & 0x10); // set LCD bit d4digitalWrite(_data_pin5, Data & 0x20); // set LCD bit d5digitalWrite(_data_pin6, Data & 0x40); // set LCD bit d6digitalWrite(_data_pin7, Data & 0x80); // set LCD bit d7digitalWrite(_enable_pin, HIGH); // set LCD Enable Highdelay(1);digitalWrite(_enable_pin, LOW); // set LCD Enable low - This should latch datadelay(1);}public:WDC2401P(byte _rs=13, byte _en=12,byte _d0=11, byte _d1=10,byte _d2=9, byte _d3=8,byte _d4=7, byte _d5=6,byte _d6=5, byte _d7=4) :_rs_pin(_rs), // define RS Arduino pin #_enable_pin(_en), // define enable Arduino pin #_data_pin0(_d0), // define D0 Arduino pin #_data_pin1(_d1), // define D1 Arduino pin #_data_pin2(_d2), // define D2 Arduino pin #_data_pin3(_d3), // define D3 Arduino pin #_data_pin4(_d4), // define D4 Arduino pin #_data_pin5(_d5), // define D5 Arduino pin #_data_pin6(_d6), // define D6 Arduino pin #_data_pin7(_d7) // define D7 Arduino pin #{}void Initialize(){pinMode(_rs_pin, OUTPUT);pinMode(_enable_pin, OUTPUT);pinMode(_data_pin0, OUTPUT);pinMode(_data_pin1, OUTPUT);pinMode(_data_pin2, OUTPUT);pinMode(_data_pin3, OUTPUT);pinMode(_data_pin4, OUTPUT);pinMode(_data_pin5, OUTPUT);pinMode(_data_pin6, OUTPUT);pinMode(_data_pin7, OUTPUT);digitalWrite(_enable_pin, LOW); // set LCD Enable low to start// The following code turns on the LCD driver powerWriteCommand(0x1C);delay(200); // delay added to allow LCD time to boot up// The following code sets the LCD cursor to non blinkingWriteCommand(0x08);// The following code turns on the LCD character displayWriteCommand(0x14);// The following code sets the LCD display to 1 lineWriteCommand(0x28);// The following code sets the LCD contrast to highWriteCommand(0x4F);}void Clear(){// The following code clears the LCD display and sets DRAM addr 0 in addr counterWriteCommand(0x01);delay(20); // A little delay to allow display to clear}void CursorPos(byte location){// Not sure what happened here, but at 16 and above the address steps backwardsif (location > 15){location=location+4; // This seems messed up but it works}if (location > 23 || location < 0) // check for location outside display range{location = 24; // set location of first char outside display range}location = location + 0xE0; // add LCD cursor location address (0xE0) to locationWriteCommand(location); // Send command to move cursor to selected location}void PrintChar(char *c_Text){char c_Temp; // Temp holder for character to display// The following code prints the characters to LCDfor (int i = 0; i < 23; i++) {c_Temp = *(c_Text+i);if (c_Temp == '\0') {i=24;}else{WriteData(c_Temp);}}}void PrintCharx(byte cData){WriteData(cData);}void PrintCharz(char cData){WriteData(cData);}void CreateCustomCharacter (const char loc, unsigned char *pattern){int i = 0;if(loc<8) //If valid address{WriteCommand(0xA0+(loc*8)); //Write to CGRAMfor(i=0; i<8; i++){WriteData(pattern); //Write the character pattern to CGRAM}WriteCommand(0xE0); // return to sending data into the standard string buffer.}}//**************************************************************};// END OF WDC2401P CLASS //////////////////////////////////////////////// Setup the LCD Class and interface pins as defined below// WDC2401P LCD(RS, EN, D0, D1, D2, D3, D4, D5, D6, D7)WDC2401P LCD(13, 12, 10, 9, 8, 7, 6, 5, 4, 3);void setup(){//********************************************************************LCD.CreateCustomCharacter(0,lock);LCD.CreateCustomCharacter(1,smiley);LCD.CreateCustomCharacter(2,sleepy);LCD.CreateCustomCharacter(3,heart);//**********************************************************************LCD.Initialize();LCD.Clear();}void loop(){// Set the cursor position (note: first char is 0 not 1)LCD.CursorPos(0);LCD.PrintChar("Some Special Characters"); //according to datasheet LCD-111.pdf , p20.delay(2000);LCD.Clear();delay(20);LCD.CursorPos(0);LCD.PrintCharx(0b10011000); // bellLCD.CursorPos(2);LCD.PrintCharx(0b10110000); // degreeLCD.CursorPos(4);LCD.PrintCharz(0); // Chr 1 ?LCD.CursorPos(6);LCD.PrintCharz(1); // Chr 2 ?LCD.CursorPos(8);LCD.PrintCharz(2); // Chr 3 ?LCD.CursorPos(10);LCD.PrintCharz(3); // Chr 4 ?delay(4000);LCD.Clear();}

author: jdev99
author_rank: Regular Contributor
timestamp: January 28, 2021, 04:25:59 pm
content: Anybody, any idea??