// 2015.2.18 Voltage Monitor // ===> LCD ACM1602N1-FLW-FBW M01 Akizuki // Receive from V_Moni by UART of TWE-Lite M.T #include<16F1827.h> #include #fuses INTRC_IO,NOWDT,NOPROTECT,NOMCLR,BROWNOUT // #use delay(clock= 16000000) //#use delay (clock=10000000) #use i2c(MASTER,SDA=PIN_B1,SCL=PIN_B4,FAST,NOFORCE_SW) #use RS232(PARITY=N, BAUD=38400,XMIT=PIN_B5, RCV=PIN_B2) // 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(); #define line_1 0x80 #define line_2 0xC0 #define data_out 0x80 #define cmd_code 0x00 static int8 cnt, tglsw; // Ring Buffer #define MAX 300 static int16 tail, head; static char buff[MAX]; #int_rda void isr_rcv() { char C; // enqueue //disable_interrupts(INT_RDA); C = (0x7f & getc()); buff[tail++] = C; if(tail>=MAX){ tail = 0; } //enable_interrupts(INT_RDA); } // ========================================== void main(){ char C; char title1[17]="Rec. V Monitor"; char title2[17]="Real_V Minimam_V"; int8 counter; LCD_init(); LCD_Setline(line_1); cnt = 0; while(cnt < 16){ LCD_data(0x30 + cnt++); } delay_ms(300); LCD_Setline(line_2); cnt = 0; while(cnt < 16){ LCD_data(0x40 + cnt++); } delay_ms(300); LCD_Clear(); LCD_Setline(line_1); // title1 for(counter=0;counter<=16;counter++){ LCD_data(title1[counter]); } delay_ms(500); // title2 LCD_Setline(line_1); for(counter=0;counter<=16;counter++){ LCD_data(title2[counter]); } delay_ms(300); LCD_Clear_line2(); LCD_Setline(line_2); tail = head = 0; cnt = tglsw = 0; enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); while(1) { if(tglsw & 0x01){ output_high(PIN_B3); } else{ output_low(PIN_B3); } // dequeue if(tail != head){ C = buff[head++]; if(head >= MAX){ head = 0; } // 0x3b==>';' End of Line if( (cnt>=16)||(C==0x3b)||(C==0x0d)||(C==0x0a) ){ LCD_data(' ');LCD_data(' ');LCD_data(' '); LCD_Setline(line_2); tglsw++ ; cnt = 2; } else{ if( (0x20<=C)&&(C<=0x7a)){ LCD_data(C); cnt++; } } } } } // 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(' '); } }