#include <16f877.h> #fuses HS,NOWDT #use delay(CLOCK=20000000) #byte PORTA = 5 #byte PORTB = 6 #byte PORTC = 7 #byte PORTD = 8 #byte PORTE = 9 const unsigned char convtbl[] = {"0123456789"}; #define LCD_RS PIN_C6 #define LCD_EN PIN_C7 //#define LCD_RS PIN_B4 //#define LCD_EN PIN_B5 void lcd_strobe(void) { output_high(LCD_EN); output_low(LCD_EN); } void lcd_write(unsigned char c) { output_bit(PIN_D4, (c >> 4) & 0x01); output_bit(PIN_D5, (c >> 5) & 0x01); output_bit(PIN_D6, (c >> 6) & 0x01); output_bit(PIN_D7, (c >> 7) & 0x01); lcd_strobe(); output_bit(PIN_D4, (c >> 0) & 0x01); output_bit(PIN_D5, (c >> 1) & 0x01); output_bit(PIN_D6, (c >> 2) & 0x01); output_bit(PIN_D7, (c >> 3) & 0x01); lcd_strobe(); delay_us(40); } void lcd_clear(void) { output_low(LCD_RS); lcd_write(0x1); delay_ms(2); } #if 0 void lcd_puts(char * s) { output_high(LCD_RS); while(*s) lcd_write(*s++); } #endif void lcd_putch(unsigned char c) { output_high(LCD_RS); lcd_write(c); } void lcd_goto(unsigned char pos) { output_low(LCD_RS); lcd_write(0x80+pos); } void lcd_init(void) { output_low(LCD_RS); delay_ms(15); output_high(PIN_D4); output_high(PIN_D5); output_low(PIN_D6); output_low(PIN_D7); lcd_strobe(); delay_ms(5); lcd_strobe(); delay_us(100); lcd_strobe(); delay_ms(5); output_low(PIN_D4); output_high(PIN_D5); output_low(PIN_D6); output_low(PIN_D7); lcd_strobe(); delay_us(40); lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font lcd_write(0x08); // display off lcd_write(0x0C); // display on, blink curson off lcd_write(0x06); // entry mode } //Line1 = 0x00 //Line2 = 0x40 //Line3 = 0x14 //Line4 = 0x54 static unsigned char buff[82]; static unsigned char now; static unsigned char temp; #define HEXTOI(c) ((c) - '0') #define HPLUS 9 //9Hour(=Japan) void command_execute(void) { static unsigned char bnot[4]; static unsigned char bhoui[4]; #if 0 if(buff[0] == '$' && buff[1] == 'G' && buff[2] == 'P' && buff[3] == 'R' && buff[4] == 'M' && buff[5] == 'C' ){ bnot[0] = buff[41]; bnot[1] = buff[42]; bnot[2] = buff[43]; bnot[3] = buff[45]; bhoui[0] = buff[47]; bhoui[1] = buff[48]; bhoui[2] = buff[49]; bhoui[3] = buff[51]; #if 0 yymmdd[0] = buff[57]; yymmdd[1] = buff[58]; yymmdd[2] = buff[55]; yymmdd[3] = buff[56]; yymmdd[4] = buff[53]; yymmdd[5] = buff[54]; #endif } #endif if(buff[0] == '$' && buff[1] == 'G' && buff[2] == 'P' && buff[3] == 'G' && buff[4] == 'G' && buff[5] == 'A' ){ lcd_goto(0x00); //DATE//////////////////////////////////////////////// #if 0 lcd_putch(yymmdd[0]); lcd_putch(yymmdd[1]); lcd_putch('/'); lcd_putch(yymmdd[2]); lcd_putch(yymmdd[3]); lcd_putch('/'); lcd_putch(yymmdd[4]); lcd_putch(yymmdd[5]); lcd_putch(' '); #endif temp = HEXTOI(buff[7]) * 10; temp += HEXTOI(buff[8]); temp += HPLUS; if(temp >= 24) temp -= 24; lcd_putch(convtbl[temp / 10]); lcd_putch(convtbl[temp % 10]); lcd_putch(':'); lcd_putch(buff[9]); lcd_putch(buff[10]); lcd_putch(':'); lcd_putch(buff[11]); lcd_putch(buff[12]); lcd_putch(' '); //DATA//////////////////////////////////////////////// //lcd_putch(buff[39] == '1' ? 'O' : 'X'); //lcd_putch(' '); lcd_putch(buff[41]); lcd_putch(buff[42]); lcd_goto(0x40); //N//////////////////////////////////////////////// lcd_putch(buff[24]); lcd_putch(' '); lcd_putch(buff[14]); lcd_putch(buff[15]); lcd_putch(buff[16]); lcd_putch(buff[17]); lcd_putch(buff[18]); lcd_putch(buff[19]); lcd_putch(buff[20]); lcd_putch(buff[21]); lcd_putch(buff[22]); //lcd_putch(' '); //lcd_putch(' '); lcd_goto(0x14); //E//////////////////////////////////////////////// lcd_putch(buff[37]); lcd_putch(buff[26]); lcd_putch(buff[27]); lcd_putch(buff[28]); lcd_putch(buff[29]); lcd_putch(buff[30]); lcd_putch(buff[31]); lcd_putch(buff[32]); lcd_putch(buff[33]); lcd_putch(buff[34]); lcd_putch(buff[35]); //lcd_putch(' '); //lcd_putch(' '); #if 0 lcd_goto(0x54); //NOT//////////////////////////////////////////////// if(buff[39] == '1'){ lcd_putch(bnot[0]); lcd_putch(bnot[1]); lcd_putch(bnot[2]); lcd_putch('.'); lcd_putch(bnot[3]); lcd_putch(' '); lcd_putch(bhoui[0]); lcd_putch(bhoui[1]); lcd_putch(bhoui[2]); lcd_putch('.'); lcd_putch(bhoui[3]); } else{ lcd_putch('0'); lcd_putch('0'); lcd_putch('0'); lcd_putch('.'); lcd_putch('0'); lcd_putch(' '); lcd_putch('0'); lcd_putch('0'); lcd_putch('0'); lcd_putch('.'); lcd_putch('0'); } #endif } } void stack_push(unsigned char c) { switch(c){ case 0x0a: break; case 0x0d: command_execute(); now = 0; break; default: buff[now] = c; now += 1; break; } } void main(void) { setup_adc(NO_ANALOGS); //Not Used set_tris_a(0x00); //PORT A set_tris_b(0x00); //PORT B set_tris_c(0x00); //PORT C set_tris_d(0x00); //PORT D set_tris_e(0x00); //PORT E PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; PORTE = 0x00; delay_ms(500); lcd_init(); lcd_clear(); lcd_goto(0); #use rs232(BAUD=4800, XMIT=PIN_D1, RCV=PIN_D0) now = 0; while(1){ stack_push(getc()); } }