// GMS6-SR6, GT-723F GPS Monitor 2015.3.27 // ===> LCD ACM1602N1-FLW-FBW M01 Akizuki #include<16F1938.h> //#include //#device ADC=10 #fuses INTRC_IO,NOWDT,NOPROTECT,NOMCLR,BROWNOUT // #use delay(clock= 16000000) //#use delay (clock=10000000) #use i2c(MASTER,SDA=PIN_C4,SCL=PIN_C3,FAST,NOFORCE_SW) #use rs232(BAUD = 9600, XMIT = PIN_C6, RCV = PIN_C7, STREAM=COM_A) //#use RS232(PARITY=N, BAUD=9600,XMIT=PIN_B5, RCV=PIN_B2) //#use rs232(BAUD = 38400, XMIT = PIN_B5, RCV = PIN_B2, STREAM=COM_B) // ACM1602 #define LCD_ADD 0xA0 // ACM1602 Slave Address void LCD_cmd(unsigned char cmd); void LCD_Clear(); void LCD_Setline(unsigned char line); void LCD_init(); void LCD_data(unsigned char data); void LCD_space(int8 n); void LCD_Clear_line2(); void isr_rcv(); void clear_words(); void cut_down(); int8 deque(); #define line_1 0x80 #define line_2 0xC0 #define data_out 0x80 #define cmd_code 0x00 static int8 rate; #define MAX 200 // Size of Ring Buffer static int16 tail, head; static char buff[MAX]; #define gps_max 200 // GPS Buffer static char gps[max]; #define word_max 200 // Cut down in a word static char words[word_max]; #define l_word 12 // Length a word #int_rda void isr_rcv() // enqueue { char C; C = (0x7f & fgetc(COM_A)); buff[tail++] = C; if( tail >= MAX ){ tail = 0; } } int8 deque(){ // dequeue int8 ret_val ; // if no data ==> return null ret_val = 0; if(tail != head){ ret_val = buff[head++]; if( head >= MAX){ head = 0; } } return(ret_val); } // ========================================== void main(){ char C; char gps_pntr ; char title1[17] = "GT-723F GPS Moni"; char title_1938[25] = "PIC16F1938 GPS Monitor"; int16 cnt; int16 pntr; set_tris_b(0xfe); set_tris_c(0xfe); output_low(PIN_B0); delay_ms(1000); LCD_init(); LCD_Setline(line_1); for(cnt=0 ; cnt < 16; cnt++){ LCD_data(0x30 + cnt); } delay_ms(1000); LCD_Setline(line_1); for(cnt=0 ; cnt < 16; cnt++){ LCD_data( title1[cnt] ); } LCD_Setline(line_1); delay_ms(1000); for(cnt=0 ; cnt < 22; cnt++){ LCD_data( title_1938[cnt] ); fprintf(COM_A,title_1938[cnt]); } fprintf(COM_A,'\r'); fprintf(COM_A,'\n'); delay_ms(1000); output_high(PIN_B0); // GPS Power ON LCD_Setline(line_2); gps_pntr = 0; tail = head = 0; cnt = rate = 0; enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); while(true) { C = deque(); if(C != 0x00){ if( gps_pntr < gps_max ){ // 0---->99 gps[gps_pntr++] = C; } if( C == '$'){ gps_pntr = 0; } if ( C == '\r'){ clear_words(); // Clear at Space code cut_down(); // Cut down in a word if( gps[3] == 'G'){ rate++; if(rate & 0x01){ output_high(PIN_C0); } else{ output_low(PIN_C0); } LCD_Setline(line_1); for( cnt=6 ;cnt<=11;cnt++){ // Time LCD_data( gps[cnt] ); } LCD_data('T'); LCD_space(2); pntr = 9*l_word; for(cnt=0 ; cnt<=5; cnt++){ // M LCD_data( words[pntr+cnt] ); } LCD_data( 'M' ); LCD_Setline(line_2); if( rate & 0x02 ){ pntr = 4*l_word; for(cnt=0 ; cnt<=10; cnt++){ // E LCD_data( words[pntr+cnt] ); } LCD_data( 'E' ); LCD_data( ' ' ); } else{ pntr = 2*l_word; for(cnt=0 ; cnt<=10; cnt++){ // N LCD_data( words[pntr+cnt] ); } LCD_data( 'N' ); LCD_data( ' ' ); } pntr = 7*l_word; for(cnt=0 ; cnt<=1; cnt++){ // S LCD_data( words[pntr+cnt] ); } LCD_data( 'S' ); } gps_pntr = 0 ; } } } } // Cut down void cut_down(){ int16 n; int16 w_cnt; // Counter of word int16 word_pntr; // Pointer of words[] w_cnt = word_pntr = 0; for( n = 0; n <= gps_max ; n++){ if( gps[n] == ','){ // 0x2c ',' w_cnt++; word_pntr = w_cnt*l_word; } else{ words[word_pntr++] = gps[n]; } } } // Clear Cut down Area void clear_words(){ int16 n; for( n = 0; n <= word_max ; n++){ words[n] = 0x20 ; } } // ACM1602NI-FLW-FBW-M01 void LCD_Clear_line2(){ int8 n; n = 0; LCD_Setline(line_2); while(n++ < 16){ LCD_data(0x20); } } void LCD_cmd(unsigned char cmd){ int16 u_t=10; i2c_start(); delay_ms(1); i2c_write(LCD_ADD); delay_us(u_t); // Slave Address i2c_write(cmd_code);delay_us(u_t); // Command Mode i2c_write(cmd); delay_us(u_t); // Send Command i2c_stop(); delay_ms(1); } void LCD_Clear(){ LCD_cmd(0x01); delay_ms(3); } void LCD_Setline(unsigned char line) { LCD_cmd(line); } void LCD_init(){ delay_ms(40); LCD_cmd(0x01); // delay_ms(1); LCD_cmd(0x38); // delay_ms(1); LCD_cmd(0x0C); // delay_ms(1); } void LCD_data(unsigned char data){ int16 u_t=10; i2c_start(); delay_ms(1); i2c_write(LCD_ADD); delay_us(u_t); // Slave Address i2c_write(data_out);delay_us(u_t); // Data Out Code i2c_write(data); delay_us(u_t); // Send Command i2c_stop(); delay_ms(1); } void LCD_space(int8 n){ int8 cnt; cnt = 0; while(cnt++ < n){ LCD_data(' '); } }