#include #include #include #include #include int led_fd; int D4=8; int D5=9; int D6=10; int D7=11; int EN=12; int RS=6; char *line; extern char *optarg; extern int optind, opterr, optopt; void nibbel(char a); void bitout(char, char); void str_out(char *string_out); void data_out(char,char); void usage() { printf("\n LCD-Output for Ediamx-Router with ADM5120\n"); printf(" lcd_out [-parameter] []\n"); printf(" Parameter : -i Poweron-INIT\n"); printf(" -h Cursor Home\n"); printf(" -c Clear Display\n"); printf(" -2 Second Line\n"); printf(" Output String\n"); printf(" -? this help\n"); printf(" (c) R.Scheller 10/2006\n"); printf(" \n"); }; int main(int argc,char *argv[] ) { int c; led_fd = open("/dev/led0",O_RDWR); if (argc==1) { usage(); return -1; } c = 0; c = getopt(argc, argv, "?ich2s:"); /* Process the command line arguments */ switch( c ) { case 'i': bitout(0,5); bitout(0,EN); //set EN-Line to low bitout(0,RS); //set RS-Line to low nibbel(0x03); usleep(1000); nibbel(0x03); usleep(500); nibbel(0x03); usleep(500); nibbel(0x02); usleep(500); data_out(0x28,0); //display function (4-bits, 2 Line) usleep(1); //? error on lib ? always 20ms delay ! data_out(0x0c,0); // blinking off, cursor off usleep(1); data_out(0x01,0); // display clear usleep(1); data_out(0x06,0); //entry mode. cursor moves break; case 'c': data_out(0x01,0); // display clear usleep(5); break; case 'h': data_out(0x02,0); // cursor home usleep(5); break; case '2': data_out(0xC0,0); // cursor second line break; case 's': if(optarg) /* output string */ { strncpy( line, optarg, 80 ); str_out(line); } break; case ':': case '?': usage(); exit(3); break; default: line = argv[1]; str_out(line); break; } close(led_fd); return 0; } void nibbel(char a) {bitout( ( a & 0x01 ), D4 ); bitout( ( a & 0x02 ), D5 ); bitout( ( a & 0x04 ), D6 ); bitout( ( a & 0x08 ), D7 ); bitout( 0 , EN); // EN low nanosleep(1); bitout( 1 , EN); // EN high nanosleep(2); }; void bitout(char value, char led_nr) { if (value==0) {ioctl(led_fd, 1, led_nr);} else {ioctl(led_fd, 0, led_nr);}; }; void data_out(char d_out,char command) {bitout(command,RS); // Data or Command nibbel(d_out>>4); // higher 4 bits nibbel(d_out); // lower 4 bits }; void str_out(char *string_out) { int i; for(i = 0 ; i < (strlen(string_out)) ; i++ ) data_out(string_out[i],1); //Strings are Data };