// lcd.h: lcd display routines // // Charles Hastings, 1998 // http://pangaea.ml.org/ // // This header includes a few basic interface routines for use with any // standard 14-pin LCD module. These routines require parport.h. // // Connect as follows: // // LCD pin connect to // -------------------------------------- // 1 Vss, potentiometer pin 1 // 2 Vcc, potentiometer pin 3 // 3 potentiometer pin 2 // 4 Instruction/data register (|| pin 1) // 5 Vss // 6 Clock (|| pin 17) // 7 Data 0 (|| pin 2) // 8 Data 1 (|| pin 3) // 9 Data 2 (|| pin 4) // 10 Data 3 (|| pin 5) // 11 Data 4 (|| pin 6) // 12 Data 5 (|| pin 7) // 13 Data 6 (|| pin 8) // 14 Data 7 (|| pin 9) // /////////////////////////////////////////////////////////////////////////////// #include #include #include "parport.h" void initLCD(); void sendLCD(char); void clearLCD(); void posLCD(int, int); void strLCD(char); const t=10; const cursor=0; // For a visible cursor, set this to 1 /////////////////////////////////////////////////////////////////////////////// // Initialize LCD module at power-up /////////////////////////////////////////////////////////////////////////////// void initLCD() { ppout("111111000001"); usleep(t); ppout("111111000000"); usleep(t); ppout("111111000001"); usleep(t); ppout("111111000000"); usleep(t); ppout("111111000001"); usleep(t); ppout("111111000000"); usleep(t); ppout("110111000001"); usleep(t); ppout("110111000000"); usleep(t); ppout("000100000001"); usleep(t); ppout("000100000000"); usleep(t); if(cursor) {ppout("111100000001"); usleep(t); ppout("111100000000"); usleep(t); } else {ppout("001100000001"); usleep(t); ppout("001100000000"); usleep(t); } ppout("011000000001"); usleep(t); ppout("011000000000"); usleep(t); ppout("000000000000"); } /////////////////////////////////////////////////////////////////////////////// // Send the LCD module one character /////////////////////////////////////////////////////////////////////////////// void sendLCD(char decimal) { int loop; char sendByte[]="000000001001"; for(loop=7;loop>=0;loop--) { if(decimal >= int(pow(2,loop))) { decimal=decimal-int(pow(2,loop)); sendByte[loop]='1'; } } ppout(sendByte); sendByte[11]='0'; ppout(sendByte); } /////////////////////////////////////////////////////////////////////////////// // Clear the LCD module /////////////////////////////////////////////////////////////////////////////// void clearLCD() { ppout("100000000001"); usleep(t); ppout("100000000000"); usleep(t); } /////////////////////////////////////////////////////////////////////////////// // Position the cursor /////////////////////////////////////////////////////////////////////////////// void posLCD(int x, int y) { int loop; int position; position=(x-1)+(64*(y-1)); char sendPos[]="000000010001"; for(loop=6;loop>=0;loop--) { if(position >= int(pow(2,loop))) { position=position-int(pow(2,loop)); sendPos[loop]='1'; } } ppout(sendPos); sendPos[11]='0'; ppout(sendPos); } /////////////////////////////////////////////////////////////////////////////// // Send a string to the LCD /////////////////////////////////////////////////////////////////////////////// void strLCD(char data[]) { int loop; for(loop=0;loop<=strlen(data)-1;loop++) { if(loop==16) {posLCD(1,2);} sendLCD(data[loop]); } }