/* display.c * Author: Dan Burke * CSC 494 Project - An Interactive Internet LCD Display * compile with gcc -o display display.c * Give the compiled program "display" execute permissions and place it * in the root directory of the user that will be running jakarta. * The program reads it's input from a text file called * "displayinput" that contains exactly 32 ascii characters to write to * the display. */ #include #include #include #include #include #include #include #include #include #include #include #include #define LP_BASE 0x378 #define DATA LP_BASE+0 #define CONTROL LP_BASE+2 int main(int argc, char *argv[]){ int y; /* The data to write to the display */ FILE *inputfile = fopen("displayinput", "r"); char ch; char space = ' '; /* Reserve space in i/o for the parallel port */ if (ioperm(LP_BASE, 3, 1) < 0){ fprintf(stderr, "Cannot reserve i/o space\n"); } /* Change the display to instruction mode */ outb(0x09, CONTROL); /* Write 15 to the display, the instruction to turn on the cursor */ outb(0x0f, DATA); usleep(20); /* Now alternate to the read/write enable to write the instruction to * the display */ outb(0x08, CONTROL); usleep(20); outb(0x09, CONTROL); /* Change the instruction to clear the display */ outb(0x01, DATA); /* Ensure the display is in instruction mode */ outb(0x09, CONTROL); usleep(20); /* Now alternate the read/write enable to write the instruction to * the display */ outb(0x08, CONTROL); usleep(20); outb(0x09, CONTROL); /* Change the instruction to set the display to 2 line mode */ outb(0x38, DATA); outb(0x09, CONTROL); usleep(20); /* Alternate the read/write enable to write the instruction */ outb(0x08, CONTROL); usleep(20); outb(0x09, CONTROL); /* Read the first 16 characters and write them to the display. */ ch = getc(inputfile); for(y = 0; y < 16; y++){ outb(ch, DATA); outb(0x00, CONTROL); usleep(2); outb(0x01, CONTROL); usleep(2); ch = getc(inputfile); if (ch == -1) break; } if (ch == -1){ exit(0); } /* Since the display buffer for each line is 40 characters, * write a space character to characters 17-40 to move to line * 2. */ for(y = 16; y < 40; y++){ outb(space, DATA); outb(0x00, CONTROL); usleep(2); outb(0x01, CONTROL); usleep(2); } /* Now read characters 17-32 from the file and write them to * line 2 of the display. */ for (y = 0; y < 16; y++){ outb(ch, DATA); outb(0x00, CONTROL); usleep(2); outb(0x01, CONTROL); usleep(2); ch = getc(inputfile); if (ch == -1) break; } /* Release the i/o space for the parallel port. */ if (ioperm(LP_BASE, 3, 0) < 0){ printf("Error releasing\n"); } return 0; }