#include #include #include #include #include #include #include #include #include #include #include #include #include #define IOM_LCD_BASE 0xbc #define IOM_LCD_COMMAND_SET _IOW(IOM_LCD_BASE,0,32) #define IOM_LCD_FUNCTION_SET _IOW(IOM_LCD_BASE,1,32) #define IOM_LCD_DISPLAY_CONTROL _IOW(IOM_LCD_BASE,2,32) #define IOM_LCD_CURSOR_SHIFT _IOW(IOM_LCD_BASE,3,32) #define IOM_LCD_ENTRY_MODE_SET _IOW(IOM_LCD_BASE,4,32) #define IOM_LCD_RETURN_HOME _IOW(IOM_LCD_BASE,5,32) #define IOM_LCD_CLEAR _IOW(IOM_LCD_BASE,6,32) #define IOM_LCD_DD_ADDRESS _IOW(IOM_LCD_BASE,7,32) #define IOM_LCD_WRITE_BYTE _IOW(IOM_LCD_BASE,8,32) struct strcommand_varible { char rows; char nfonts; char display_enable; char cursor_enable; char nblink; char set_screen; char set_rightshit; char increase; char nshift; char pos; char command; char strlength; char buf[20]; }; void init_keyboard(void); void close_keyboard(void); int kbhit(void); int readch(void); void handler(int); static struct termios initial_settings, new_settings; static int peek_character = -1; void handler(int signo){ int i,dev; char front[20] = "KOO's STOP WATCH"; char row_buffer1[20]; char row_buffer2[20]; char *row_one = row_buffer1; char *row_two = row_buffer2; struct strcommand_varible strcommand; strcommand.rows = 0; strcommand.nfonts = 0; strcommand.display_enable = 1; strcommand.cursor_enable = 0; strcommand.nblink = 0; strcommand.set_screen = 1; strcommand.set_rightshit= 0; strcommand.increase = 1; strcommand.nshift = 0; strcommand.pos = 10; strcommand.command = 1; strcommand.strlength = 16; write(dev,&strcommand,32); sleep(1); int year=0, month=0, day=0, hour=0, min=0, sec=0; int temp_t=0; int temp1[10], temp2[10]; time_t ltime; struct tm * today; time(<ime); today = localtime(<ime); year = today->tm_year + 1900; month = today->tm_mon + 1; day = today->tm_mday; hour = today->tm_hour; min = today->tm_min; sec = today->tm_sec; // display string input routin memset(row_one,0,20); memset(row_two,0,20); // printf("Input String [MAX: 16char]"); // printf("\n First Line:"); // fgets(row_one, 20, stdin); // printf(" Second Line:"); // fgets(row_two, 20, stdin); temp1[0] = year / 1000; row_buffer1[0] = temp1[0] + '0'; temp_t = year % 1000; temp1[1] = temp_t / 100; row_buffer1[1] = temp1[1] + '0'; temp_t = temp_t % 100; temp1[2] = temp_t / 10; row_buffer1[2] = temp1[2] + '0'; temp1[3] = temp_t % 10; row_buffer1[3] = temp1[3] + '0'; row_buffer1[4] = ':'; temp1[5] = month / 10; row_buffer1[5] = temp1[5] + '0'; temp1[6] = month % 10; row_buffer1[6] = temp1[6] + '0'; row_buffer1[7] = ':'; temp1[8] = day / 10; row_buffer1[8] = temp1[8] + '0'; temp1[9] = temp_t % 10; row_buffer1[9] = temp1[9] + '0'; temp2[0] = hour / 10; row_buffer2[0] = temp2[0] + '0'; temp2[1] = hour % 10; row_buffer2[1] = temp2[1] + '0'; row_buffer2[2] = ':'; temp2[3] = min / 10; row_buffer2[3] = temp2[3] + '0'; temp2[4] = min % 10; row_buffer2[4] = temp2[4] + '0'; row_buffer2[5] = ':'; temp2[6] = min / 10; row_buffer2[6] = temp2[6] + '0'; temp2[7] = min % 10; row_buffer2[7] = temp2[7] + '0'; ioctl(dev,IOM_LCD_CLEAR,&strcommand,32); sleep(2); strcommand.pos = 0; ioctl(dev,IOM_LCD_DD_ADDRESS,&strcommand,32); for(i = 0;i < 16;i++) { if(row_one[i] == '\0') break; memcpy(&strcommand.buf[0],&row_one[i],1); ioctl(dev,IOM_LCD_WRITE_BYTE,&strcommand,32); } sleep(2); strcommand.pos = 40; ioctl(dev,IOM_LCD_DD_ADDRESS,&strcommand,32); for(i = 0;i < 16;i++) { if(row_two[i] == '\0') break; memcpy(&strcommand.buf[0],&row_two[i],1); ioctl(dev,IOM_LCD_WRITE_BYTE,&strcommand,32); } sleep(1); // printf("%0004d : %02d : %02d\n", year, month, day); // printf("%02d : %02d : %02d\n", hour, min, sec); init_keyboard(); for(;;){ // ioctl(dev,IOM_LCD_CURSOR_SHIFT,&strcommand,32); // usleep(2000); if(kbhit()) break; } close_keyboard(); close(dev); alarm(1); } void init_keyboard() { tcgetattr(0,&initial_settings); new_settings = initial_settings; new_settings.c_lflag &= ~ICANON; new_settings.c_lflag &= ~ECHO; new_settings.c_lflag &= ~ISIG; new_settings.c_cc[VMIN] = 1; new_settings.c_cc[VTIME] = 0; tcsetattr(0, TCSANOW, &new_settings); } void close_keyboard() { tcsetattr(0, TCSANOW, &initial_settings); } int kbhit() { unsigned char ch; int nread; if (peek_character != -1) return 1; new_settings.c_cc[VMIN]=0; tcsetattr(0, TCSANOW, &new_settings); nread = read(0,&ch,1); new_settings.c_cc[VMIN]=1; tcsetattr(0, TCSANOW, &new_settings); if(nread == 1) { peek_character = ch; return 1; } return 0; } int readch() { char ch; if(peek_character != -1) { ch = peek_character; peek_character = -1; return ch; } read(0,&ch,1); return ch; } int main(int argc, char **argv) { /* char row_buffer1[20]; char row_buffer2[20]; char *row_one = row_buffer1; char *row_two = row_buffer2;*/ int i,dev; char front[20] = "KOO's STOP WATCH"; struct sigaction sa; struct strcommand_varible strcommand; strcommand.rows = 0; strcommand.nfonts = 0; strcommand.display_enable = 1; strcommand.cursor_enable = 0; strcommand.nblink = 0; strcommand.set_screen = 1; strcommand.set_rightshit= 0; strcommand.increase = 1; strcommand.nshift = 0; strcommand.pos = 10; strcommand.command = 1; strcommand.strlength = 16; memcpy(&strcommand.buf[0],front,20); dev = open("/dev/TXTLCD", O_WRONLY|O_NDELAY ); if (dev != -1) { memset(&sa,0,sizeof(sa)); sa.sa_handler = handler; sigaction(SIGALRM, &sa, NULL); alarm(1); while(1){ pause(); } } else { printf( "application : Device Open ERROR!\n"); exit(-1); } return(0); }