//****************************************************************************************** // PIC18F4520 Sample Program // Project : // Program Name : // Programer : // Create date : Version 1.0 H23.08.10 // Replace date : // History : // Laungage : MPLAB C18 //****************************************************************************************** // Description // // 1)Define I/O PORT // PORTB(7-0) : SG12864(DB7-0) // PORTD(7) : SG12864(E) // PORTD(6) : SG12864(R/W) // PORTD(5) : SG12864(D/I) // PORTD(4) : SG12864(RES) // PORTD(3) : SG12864(CS2) // PORTD(2) : SG12864(CS1) // PORTC(7) : Serial PORT(Rx) // PORTC(6) : Serial PORT(Tx) // // 2)OSC // 40MHz (10MHz Crystal * PLL4) // //****************************************************************************************** #include #include #include #include #include #include #include #include // //Define configration // #pragma config OSC=HSPLL //Oscillator Selection : HS-PLL Enabled #pragma config FCMEN=OFF //Fail-Safe Clock Monitor Enable bit: #pragma config IESO=OFF //Internal/External Oscillator Switchover bit: #pragma config PWRT=OFF //Power-up Timer: #pragma config BOREN=OFF //Brown-out Reset Enable bits: #pragma config BORV=3 //Brown-out Voltage: #pragma config WDT=OFF //Watchdog Timer: #pragma config WDTPS=1 //Watchdog Postscaler: 1:1 #pragma config MCLRE=ON //MCLR Pin Enable bit: MCLR pin enabled; RE3 input pin disabled //#pragma config MCLRE=OFF //MCLR Pin Enable bit: RE3 input pin enabled; MCLR disabled #pragma config LPT1OSC=OFF //Low-Power Timer1 Oscillator Enable bit: Timer1 configured for higher power operation #pragma config PBADEN=OFF //PORTB A/D Enable bit: PORTB<4:0> pins are configured as digital I/O on Reset //#pragma config PBADEN=ON //PORTB A/D Enable bit: PORTB<4:0> pins are configured as analog input channels on Reset #pragma config CCP2MX=PORTBE //CCP2 MUX bit: CCP2 input/output is multiplexed with RB3 //#pragma config CCP2MX=PORTC//CCP2 MUX bit: CCP2 input/output is multiplexed with RC1 #pragma config STVREN=OFF //Stack Overflow Reset Enable bit: Stack full/underflow will not cause Reset #pragma config LVP=OFF //Low Voltage ICSP: #pragma config XINST=OFF //Extended Instruction Set Enable bit: #pragma config DEBUG=OFF //Background Debugger Enable: #pragma config CP0=OFF //Code Protection Block 0: #pragma config CP1=OFF //Code Protection Block 1: #pragma config CP2=OFF //Code Protection Block 2: #pragma config CP3=OFF //Code Protection Block 3: #pragma config CPB=OFF //Boot Block Code Protection: #pragma config CPD=OFF //Data EEPROM Code Protection: #pragma config WRT0=OFF //Write Protection Block 0: #pragma config WRT1=OFF //Write Protection Block 1: #pragma config WRT2=OFF //Write Protection Block 2: #pragma config WRT3=OFF //Write Protection Block 3: #pragma config WRTB=OFF //Boot Block Write Protection: #pragma config WRTC=OFF //Configuration Register Write Protection: #pragma config WRTD=OFF //Data EEPROM Write Protection: #pragma config EBTR0=OFF //Table Read Protection Block 0: #pragma config EBTR1=OFF //Table Read Protection Block 1: #pragma config EBTR2=OFF //Table Read Protection Block 2: #pragma config EBTR3=OFF //Table Read Protection Block 3: #pragma config EBTRB=OFF //Boot Block Table Read Protection: // //Define Parameter // (1)Pin Assign // #define PI_LCD_E 7 #define PI_LCD_RW 6 #define PI_LCD_DI 5 #define PI_LCD_RES 4 #define PI_LCD_CS2 3 #define PI_LCD_CS1 2 #define PI_LCD_DB7 7 #define PI_LCD_DB6 6 #define PI_LCD_DB5 5 #define PI_LCD_DB4 4 #define PI_LCD_DB3 3 #define PI_LCD_DB2 2 #define PI_LCD_DB1 1 #define PI_LCD_DB0 0 // // (2)Parameter #define PI_NORMAL 0 #define PI_FAILURE 1 #define PI_FUR 2 #define PI_SEC 3 #define PI_OVER 4 #define PI_LINE 10 #define PI_LINE_N 11 #define PI_PAGE 12 #define PI_CLM 13 #define PI_DATA 14 #define PI_CS1 15 #define PI_CS2 16 #define PI_LCD_FUR 17 #define PI_LCD_SEC 18 // //Define Function // void Prog01(void); void Prog02(void); void Prog03(void); char GRF_LINE(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char ); char LINE(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char ); char PSET(unsigned char, unsigned char, unsigned char, unsigned char); void Put_LCD_char(unsigned char, unsigned char, unsigned char ); void Put_LCD_charrec(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char); void Set_fnt(unsigned char *, unsigned char); void LCD_BSF_CNT(unsigned int); void LCD_BCF_CNT(unsigned int); void LCD_BSF_DB(unsigned int); void LCD_BCF_DB(unsigned int); void LCD_MOVF_DB(unsigned char); void LCD_RED_DB(unsigned char *); void LCD_WRTRS_DB(void); void LCD_RDTRS_DB(void); void Init_LCD(void); int LCD_setdat(unsigned char, unsigned char); void LCD_dsp(unsigned char , unsigned char , unsigned char ,unsigned char ,unsigned char, unsigned char); void LCD_read(unsigned char, unsigned char , unsigned char ,unsigned char ,unsigned char *, unsigned char); void LCD_ENSIG(void); void LCD_clear(void); void NopN(unsigned int); void Timer(void); void Wait_1mS(unsigned int); void Init_USART(void); void Trans_USART(unsigned char ); void Rec_USART(unsigned char * ); volatile unsigned char G_PAGE=0; volatile unsigned char G_CLM=0; void main(void) { unsigned char tmp_c; // ************************************* // 1.Initialize Segment // ************************************* // (1)PORT PORTA=0b00000000; PORTB=0b00000000; PORTC=0b00000000; PORTD=0b00000000; PORTE=0b00000000; // (2)TRIS TRISA=0b11111111; TRISB=0b00000000; TRISC=0b11111111; TRISD=0b00000011; TRISE=0b00000111; //Caution !!! (Bit[7-4]) // (3)LAT LATA=0b00000000; LATB=0b00000000; LATC=0b00000000; LATD=0b00000000; LATE=0b00000000; // (4)Select A/D Converter ADCON1=0b00001111; //ALL Degital Port // (5)Initialized LCD Init_LCD(); LCD_clear(); // ************************************* // 2.Program Main // ************************************* // (1)Program main Prog01(); Wait_1mS(1000); //Wait 1[S] ; 1000mS LCD_clear(); Prog02(); Wait_1mS(1000); //Wait 1[S] ; 1000mS LCD_clear(); Prog03(); while(1); } //****************************************************************************************** // Function Name : Prog01 // Title : 表示位置を指定して表示するサンプル // Input : // Output : // Description : //****************************************************************************************** void Prog01(void) { Put_LCD_charrec('S', 0, 0, PI_CS1,PI_LCD_FUR); Put_LCD_charrec('T', 0, 1, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('A', 0, 2, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('R', 0, 3, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('T', 0, 4, PI_CS1,PI_LCD_SEC); Put_LCD_charrec(' ', 0, 5, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('P', 0, 6, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('I', 0, 7, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('C', 0, 8, PI_CS1,PI_LCD_SEC); Put_LCD_charrec(' ', 0, 9, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('1', 0, 0, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('8', 0, 1, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('F', 0, 2, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('4', 0, 3, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('5', 0, 4, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('2', 0, 5, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(' ', 0, 6, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(' ', 0, 7, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(' ', 0, 8, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(' ', 0, 9, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('G', 1, 0, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('R', 1, 1, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('A', 1, 2, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('F', 1, 3, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('I', 1, 4, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('C', 1, 5, PI_CS1,PI_LCD_SEC); Put_LCD_charrec(' ', 1, 6, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('L', 1, 7, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('C', 1, 8, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('D', 1, 9, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('S', 1, 0, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('G', 1, 1, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('1', 1, 2, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('2', 1, 3, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('8', 1, 4, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('6', 1, 5, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('4', 1, 6, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(' ', 1, 7, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('O', 1, 8, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('K', 1, 9, PI_CS2,PI_LCD_SEC); } //****************************************************************************************** // Function Name : Prog02 // Title : CS1,CS2を分けて表示する(00から表示を開始するサンプル) // Input : // Output : //****************************************************************************************** void Prog02(void) { // ******************************** // 1.CS1に表示する // ******************************** Put_LCD_char('0', PI_CS1, PI_FUR); Put_LCD_char('1', PI_CS1, PI_SEC); Put_LCD_char('2', PI_CS1, PI_SEC); Put_LCD_char('3', PI_CS1, PI_SEC); Put_LCD_char('4', PI_CS1, PI_SEC); Put_LCD_char('5', PI_CS1, PI_SEC); Put_LCD_char('6', PI_CS1, PI_SEC); Put_LCD_char('7', PI_CS1, PI_SEC); Put_LCD_char('8', PI_CS1, PI_SEC); Put_LCD_char('9', PI_CS1, PI_SEC); Put_LCD_char('ア', PI_CS1, PI_SEC); Put_LCD_char('イ', PI_CS1, PI_SEC); Put_LCD_char('ウ', PI_CS1, PI_SEC); Put_LCD_char('エ', PI_CS1, PI_SEC); Put_LCD_char('オ', PI_CS1, PI_SEC); Put_LCD_char('カ', PI_CS1, PI_SEC); Put_LCD_char('キ', PI_CS1, PI_SEC); Put_LCD_char('ク', PI_CS1, PI_SEC); Put_LCD_char('ケ', PI_CS1, PI_SEC); Put_LCD_char('コ', PI_CS1, PI_SEC); Put_LCD_char('サ', PI_CS1, PI_SEC); Put_LCD_char('シ', PI_CS1, PI_SEC); Put_LCD_char('ス', PI_CS1, PI_SEC); Put_LCD_char('セ', PI_CS1, PI_SEC); Put_LCD_char('ソ', PI_CS1, PI_SEC); Put_LCD_char('タ', PI_CS1, PI_SEC); Put_LCD_char('チ', PI_CS1, PI_SEC); Put_LCD_char('ツ', PI_CS1, PI_SEC); Put_LCD_char('テ', PI_CS1, PI_SEC); Put_LCD_char('ト', PI_CS1, PI_SEC); Put_LCD_char('ナ', PI_CS1, PI_SEC); Put_LCD_char('ニ', PI_CS1, PI_SEC); Put_LCD_char('ヌ', PI_CS1, PI_SEC); Put_LCD_char('ネ', PI_CS1, PI_SEC); Put_LCD_char('ノ', PI_CS1, PI_SEC); Put_LCD_char('ハ', PI_CS1, PI_SEC); Put_LCD_char('ヒ', PI_CS1, PI_SEC); Put_LCD_char('フ', PI_CS1, PI_SEC); Put_LCD_char('ヘ', PI_CS1, PI_SEC); Put_LCD_char('ホ', PI_CS1, PI_SEC); Put_LCD_char('マ', PI_CS1, PI_SEC); Put_LCD_char('ミ', PI_CS1, PI_SEC); Put_LCD_char('ム', PI_CS1, PI_SEC); Put_LCD_char('メ', PI_CS1, PI_SEC); Put_LCD_char('モ', PI_CS1, PI_SEC); Put_LCD_char('ヤ', PI_CS1, PI_SEC); Put_LCD_char('ユ', PI_CS1, PI_SEC); Put_LCD_char('ヨ', PI_CS1, PI_SEC); Put_LCD_char('ラ', PI_CS1, PI_SEC); Put_LCD_char('リ', PI_CS1, PI_SEC); Put_LCD_char('ル', PI_CS1, PI_SEC); Put_LCD_char('レ', PI_CS1, PI_SEC); Put_LCD_char('ロ', PI_CS1, PI_SEC); Put_LCD_char('ワ', PI_CS1, PI_SEC); Put_LCD_char('ン', PI_CS1, PI_SEC); // ******************************** // 2.CS2に表示する // ******************************** Put_LCD_char('A', PI_CS2, PI_FUR); Put_LCD_char('B', PI_CS2, PI_SEC); Put_LCD_char('C', PI_CS2, PI_SEC); Put_LCD_char('D', PI_CS2, PI_SEC); Put_LCD_char('E', PI_CS2, PI_SEC); Put_LCD_char('F', PI_CS2, PI_SEC); Put_LCD_char('G', PI_CS2, PI_SEC); Put_LCD_char('H', PI_CS2, PI_SEC); Put_LCD_char('I', PI_CS2, PI_SEC); Put_LCD_char('J', PI_CS2, PI_SEC); Put_LCD_char('K', PI_CS2, PI_SEC); Put_LCD_char('L', PI_CS2, PI_SEC); Put_LCD_char('M', PI_CS2, PI_SEC); Put_LCD_char('N', PI_CS2, PI_SEC); Put_LCD_char('O', PI_CS2, PI_SEC); Put_LCD_char('P', PI_CS2, PI_SEC); Put_LCD_char('Q', PI_CS2, PI_SEC); Put_LCD_char('R', PI_CS2, PI_SEC); Put_LCD_char('S', PI_CS2, PI_SEC); Put_LCD_char('T', PI_CS2, PI_SEC); Put_LCD_char('U', PI_CS2, PI_SEC); Put_LCD_char('V', PI_CS2, PI_SEC); Put_LCD_char('W', PI_CS2, PI_SEC); Put_LCD_char('X', PI_CS2, PI_SEC); Put_LCD_char('Y', PI_CS2, PI_SEC); Put_LCD_char('Z', PI_CS2, PI_SEC); Put_LCD_char('u', PI_CS2, PI_SEC); Put_LCD_char('d', PI_CS2, PI_SEC); Put_LCD_char('r', PI_CS2, PI_SEC); Put_LCD_char('l', PI_CS2, PI_SEC); Put_LCD_char(' ', PI_CS2, PI_SEC); Put_LCD_char('a', PI_CS2, PI_SEC); Put_LCD_char('e', PI_CS2, PI_SEC); Put_LCD_char('+', PI_CS2, PI_SEC); Put_LCD_char('-', PI_CS2, PI_SEC); Put_LCD_char('=', PI_CS2, PI_SEC); Put_LCD_char(')', PI_CS2, PI_SEC); Put_LCD_char('(', PI_CS2, PI_SEC); Put_LCD_char(']', PI_CS2, PI_SEC); Put_LCD_char('[', PI_CS2, PI_SEC); Put_LCD_char('>', PI_CS2, PI_SEC); Put_LCD_char('<', PI_CS2, PI_SEC); Put_LCD_char('"', PI_CS2, PI_SEC); Put_LCD_char('!', PI_CS2, PI_SEC); Put_LCD_char('*', PI_CS2, PI_SEC); Put_LCD_char('/', PI_CS2, PI_SEC); } //****************************************************************************************** // Function Name : Prog03 // Title : ドット表示サンプル // Input : // Output : // Description : //****************************************************************************************** void Prog03(void) { unsigned char lp; unsigned char y; float f_y, f_x ; // ***************************************** // 1.Line // ***************************************** // PSET(0, 0, PI_CS1, PI_FUR); GRF_LINE(5, 5, 5, 60, PI_CS1, PI_FUR); GRF_LINE(5, 5, 60, 5, PI_CS1, PI_FUR); Put_LCD_charrec('X', 7, 9, PI_CS1,PI_LCD_FUR); Put_LCD_charrec('Y', 0, 0, PI_CS1,PI_LCD_FUR); // ***************************************** // 2.Graf // ***************************************** // (1)Y = X for(lp=0;lp<55;lp++){ y = lp ; GRF_LINE((lp+5),(y+5),(lp+5),(y+5), PI_CS1, PI_FUR); } // (2)Y = SIN(X) for(lp=0;lp<55;lp++){ f_x = lp; f_x = f_x / (float)5 ; f_y = sin(f_x) * 20 + 20 ; y = (unsigned char)f_y; GRF_LINE((lp+5),(y+5),(lp+5),(y+5), PI_CS1, PI_FUR); } // (3)Y = 1/2 * X + 10 for(lp=0;lp<55;lp++){ f_x = lp; f_y = f_x / 2 + 10 ; y = (unsigned char)f_y; GRF_LINE((lp+5),(y+5),(lp+5),(y+5), PI_CS1, PI_FUR); } // ***************************************** // 3.Title // ***************************************** Put_LCD_charrec('Y', 1, 0, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('=', 1, 1, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('A', 1, 2, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('X', 1, 3, PI_CS2,PI_LCD_SEC); // Put_LCD_charrec('Y', 3, 0, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('=', 3, 1, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('S', 3, 2, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('I', 3, 3, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('N', 3, 4, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('(', 3, 5, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('X', 3, 6, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(')', 3, 7, PI_CS2,PI_LCD_SEC); // Put_LCD_charrec('Y', 5, 0, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('=', 5, 1, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('A', 5, 2, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('X', 5, 3, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('+', 5, 4, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('B', 5, 5, PI_CS2,PI_LCD_SEC); // Put_LCD_charrec('G', 0, 4, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('R', 0, 5, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('A', 0, 6, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('F', 0, 7, PI_CS1,PI_LCD_SEC); } //****************************************************************************************** // Function Name : GRF_LINE // Title : // Input : // Output : //****************************************************************************************** char GRF_LINE(unsigned char in_x0, unsigned char in_y0, unsigned char in_x1, unsigned char in_y1, unsigned char in_cs, unsigned char in_mode) { char status; in_y0 = 63 - in_y0 ; in_y1 = 63 - in_y1 ; status = LINE(in_x0, in_y0, in_x1, in_y1, in_cs, in_mode); return(status); } //****************************************************************************************** // Function Name : LINE // Title : // Input : // Output : //****************************************************************************************** char LINE(unsigned char in_x0, unsigned char in_y0, unsigned char in_x1, unsigned char in_y1, unsigned char in_cs, unsigned char in_mode) { unsigned char tmp_c; float f_x0,f_x1,f_y0,f_y1; float A,B; int x,y; unsigned char cx,cy; int lp; unsigned char chk_flg = 0; // ********************** // 1.Check argument // ********************** if(in_x0 > in_x1){ tmp_c = in_x0; in_x0 = in_x1; in_x1 = tmp_c; tmp_c = in_y0; in_y0 = in_y1; in_y1 = tmp_c; } if((in_x0 == in_x1) && (in_y0 == in_y1)){ if((in_x0 < 63)&&(in_y0 < 63)){ if(in_mode == PI_FUR){ PSET(in_x0, in_y0,in_cs,PI_FUR); } PSET(in_x0, in_y0,in_cs,PI_SEC); } return(PI_NORMAL); }else if(in_x0 == in_x1){ if(in_y0 > in_y1){ tmp_c = in_y0; in_y0 = in_y1; in_y1 = tmp_c; } for(lp=in_y0;lp 62){ in_x0 = 62 ; } if(in_x1 > 62){ in_x1 = 62 ; } // ********************** // 2.Calc A // ********************** f_x0 = (float)in_x0; f_x1 = (float)in_x1; f_y0 = (float)in_y0; f_y1 = (float)in_y1; A = ((float)(f_y1 - f_y0)) / ((float)(f_x1 - f_x0)); B = (float)f_y0 - (float)(A * (float)f_x0); // ********************** // 3.Program // ********************** for(lp=in_x0;lp < ( in_x1 + 1 ) ; lp++){ y = A * lp + B ; if(y < 0 || 62 < y ){ }else{ cx=lp; cy=y; if(in_mode == PI_FUR && chk_flg == 0){ PSET(cx, cy,in_cs,PI_FUR); chk_flg = 1; } PSET(cx, cy,in_cs,PI_SEC); } } return(PI_NORMAL); } //****************************************************************************************** // Function Name : PSET // Title : // Input : // Output : //****************************************************************************************** char PSET(unsigned char in_x, unsigned char in_y, unsigned char in_cs, unsigned char in_mode) { unsigned char tmp_page; unsigned char tmp_data; unsigned char tmp_lcd_data; tmp_page = in_y / 8 ; tmp_data = ( 1 << ( in_y % 8 )); if(tmp_page > 7) return(PI_FAILURE); if(in_mode == PI_FUR){ LCD_read(0, 0, 0, in_cs, &tmp_lcd_data, PI_LINE); } LCD_read(0, tmp_page, in_x, in_cs, &tmp_lcd_data, PI_PAGE); tmp_data = tmp_data | tmp_lcd_data ; LCD_dsp(0, tmp_page, in_x, in_cs, tmp_data, PI_PAGE); return(PI_NORMAL); } //****************************************************************************************** // Function Name : Put_LCD_char // Title : // Input : // Output : //****************************************************************************************** void Put_LCD_char(unsigned char in_char, unsigned char in_cs, unsigned char in_mode) { if(in_mode == PI_FUR){ Put_LCD_charrec(in_char, 0, 0, in_cs,PI_LCD_FUR); G_PAGE = 0; G_CLM = 1; }else{ Put_LCD_charrec(in_char, G_PAGE, G_CLM, in_cs,PI_LCD_SEC); if(G_CLM > 8){ G_CLM = 0; if(G_PAGE>6){ G_PAGE = 0; }else{ G_PAGE++; } }else{ G_CLM++; } } } //****************************************************************************************** // Function Name : Put_LCD_charrec // Title : // Input : char, page, clm(char), cs, mode // Output : //****************************************************************************************** void Put_LCD_charrec(unsigned char in_char, unsigned char in_page, unsigned char in_clm_char, unsigned char in_cs, unsigned char in_mode ) { unsigned char fnt[5]; unsigned int lp; unsigned char tmp_line; unsigned char chk_ovr = PI_NORMAL; // 1.Get Font Set_fnt(&fnt[0], in_char); // 2.Put LCD // (1)Check position if(in_clm_char > 9 ){ if(in_cs == PI_CS1){ chk_ovr = PI_OVER; in_clm_char = 10; }else{ in_cs = PI_CS1; in_clm_char = 0; in_page++; } } if(in_page > 7){ in_page = 0; in_clm_char = 0; } // (2)Put LCD if(in_mode == PI_LCD_FUR ){ tmp_line = in_page *8; LCD_dsp(tmp_line, 0, 0, in_cs, 0x00, PI_LINE); } // if(in_cs == PI_CS1){ in_clm_char = in_clm_char * 6; }else{ in_clm_char = in_clm_char * 6 + 2; } if(chk_ovr == PI_NORMAL){ for(lp=0;lp<5;lp++){ LCD_dsp(0, in_page, in_clm_char, in_cs, fnt[lp], PI_PAGE); in_clm_char++; } LCD_dsp(0, in_page, in_clm_char, in_cs, 0x00, PI_PAGE); }else{ for(lp=0;lp<2;lp++){ LCD_dsp(0, in_page, in_clm_char, in_cs, fnt[lp], PI_PAGE); in_clm_char++; } LCD_dsp(0, in_page, 0, PI_CS2, fnt[4], PI_PAGE); LCD_dsp(0, in_page, 1, PI_CS2, 0x00, PI_PAGE); } } //****************************************************************************************** // Function Name : Set_fnt // Title : // Input : // Output : //****************************************************************************************** void Set_fnt(unsigned char fnt[], unsigned char c) { // **************** // 0-9 // **************** if(c=='0'){ fnt[0] = 0b00000000; fnt[1] = 0b00111110; fnt[2] = 0b01000001; fnt[3] = 0b00111110; fnt[4] = 0b00000000; return; } if(c=='1'){ fnt[0] = 0b00000000; fnt[1] = 0b01000010; fnt[2] = 0b01111111; fnt[3] = 0b01000000; fnt[4] = 0b00000000; return; } if(c=='2'){ fnt[0] = 0b01000010; fnt[1] = 0b01000001; fnt[2] = 0b01100001; fnt[3] = 0b01010001; fnt[4] = 0b01001110; return; } if(c=='3'){ fnt[0] = 0b00100010; fnt[1] = 0b01001001; fnt[2] = 0b01001001; fnt[3] = 0b01001001; fnt[4] = 0b00110110; return; } if(c=='4'){ fnt[0] = 0b00111100; fnt[1] = 0b00100010; fnt[2] = 0b00100001; fnt[3] = 0b01111111; fnt[4] = 0b00100000; return; } if(c=='5'){ fnt[0] = 0b01001111; fnt[1] = 0b01001001; fnt[2] = 0b01001001; fnt[3] = 0b01001001; fnt[4] = 0b00110000; return; } if(c=='6'){ fnt[0] = 0b00111110; fnt[1] = 0b01001001; fnt[2] = 0b01001001; fnt[3] = 0b01001001; fnt[4] = 0b00110000; return; } if(c=='7'){ fnt[0] = 0b00000001; fnt[1] = 0b00000001; fnt[2] = 0b01110001; fnt[3] = 0b00001001; fnt[4] = 0b00000111; return; } if(c=='8'){ fnt[0] = 0b00110110; fnt[1] = 0b01001001; fnt[2] = 0b01001001; fnt[3] = 0b01001001; fnt[4] = 0b00110110; return; } if(c=='9'){ fnt[0] = 0b00100110; fnt[1] = 0b01001001; fnt[2] = 0b01001001; fnt[3] = 0b01001001; fnt[4] = 0b00111110; return; } // **************** // A-Z // **************** if(c=='A'){ fnt[0] = 0b01111100; fnt[1] = 0b00010010; fnt[2] = 0b00010001; fnt[3] = 0b00010010; fnt[4] = 0b01111100; return; } if(c=='B'){ fnt[0] = 0b01111111; fnt[1] = 0b01001001; fnt[2] = 0b01001001; fnt[3] = 0b01001001; fnt[4] = 0b00110110; return; } if(c=='C'){ fnt[0] = 0b00111110; fnt[1] = 0b01000001; fnt[2] = 0b01000001; fnt[3] = 0b01000001; fnt[4] = 0b00100010; return; } if(c=='D'){ fnt[0] = 0b01111111; fnt[1] = 0b01000001; fnt[2] = 0b01000001; fnt[3] = 0b01000001; fnt[4] = 0b00111110; return; } if(c=='E'){ fnt[0] = 0b01111111; fnt[1] = 0b01001001; fnt[2] = 0b01001001; fnt[3] = 0b01001001; fnt[4] = 0b01001001; return; } if(c=='F'){ fnt[0] = 0b01111111; fnt[1] = 0b00001001; fnt[2] = 0b00001001; fnt[3] = 0b00001001; fnt[4] = 0b00001001; return; } if(c=='G'){ fnt[0] = 0b00111110; fnt[1] = 0b01000001; fnt[2] = 0b01001001; fnt[3] = 0b01001001; fnt[4] = 0b01111010; return; } if(c=='H'){ fnt[0] = 0b01111111; fnt[1] = 0b00001000; fnt[2] = 0b00001000; fnt[3] = 0b00001000; fnt[4] = 0b01111111; return; } if(c=='I'){ fnt[0] = 0b00000000; fnt[1] = 0b01000001; fnt[2] = 0b01111111; fnt[3] = 0b01000001; fnt[4] = 0b00000000; return; } if(c=='J'){ fnt[0] = 0b00100000; fnt[1] = 0b01000000; fnt[2] = 0b01000000; fnt[3] = 0b01000000; fnt[4] = 0b00111111; return; } if(c=='K'){ fnt[0] = 0b01111111; fnt[1] = 0b00001000; fnt[2] = 0b00010100; fnt[3] = 0b00100010; fnt[4] = 0b01000001; return; } if(c=='L'){ fnt[0] = 0b01111111; fnt[1] = 0b01000000; fnt[2] = 0b01000000; fnt[3] = 0b01000000; fnt[4] = 0b01000000; return; } if(c=='M'){ fnt[0] = 0b01111111; fnt[1] = 0b00000010; fnt[2] = 0b00011100; fnt[3] = 0b00000010; fnt[4] = 0b01111111; return; } if(c=='N'){ fnt[0] = 0b01111111; fnt[1] = 0b00000010; fnt[2] = 0b00001000; fnt[3] = 0b00100000; fnt[4] = 0b01111111; return; } if(c=='O'){ fnt[0] = 0b00111110; fnt[1] = 0b01000001; fnt[2] = 0b01000001; fnt[3] = 0b01000001; fnt[4] = 0b00111110; return; } if(c=='P'){ fnt[0] = 0b01111111; fnt[1] = 0b00001001; fnt[2] = 0b00001001; fnt[3] = 0b00001001; fnt[4] = 0b00000110; return; } if(c=='Q'){ fnt[0] = 0b00111110; fnt[1] = 0b01000001; fnt[2] = 0b01010001; fnt[3] = 0b00111110; fnt[4] = 0b01000000; return; } if(c=='R'){ fnt[0] = 0b01111111; fnt[1] = 0b00001001; fnt[2] = 0b00011001; fnt[3] = 0b00101001; fnt[4] = 0b01000110; return; } if(c=='S'){ fnt[0] = 0b00100110; fnt[1] = 0b01001001; fnt[2] = 0b01001001; fnt[3] = 0b01001001; fnt[4] = 0b00110010; return; } if(c=='T'){ fnt[0] = 0b00000001; fnt[1] = 0b00000001; fnt[2] = 0b01111111; fnt[3] = 0b00000001; fnt[4] = 0b00000001; return; } if(c=='U'){ fnt[0] = 0b00111111; fnt[1] = 0b01000000; fnt[2] = 0b01000000; fnt[3] = 0b01000000; fnt[4] = 0b00111111; return; } if(c=='V'){ fnt[0] = 0b00011111; fnt[1] = 0b00100000; fnt[2] = 0b01000000; fnt[3] = 0b00100000; fnt[4] = 0b00011111; return; } if(c=='W'){ fnt[0] = 0b00111111; fnt[1] = 0b01000000; fnt[2] = 0b00111111; fnt[3] = 0b01000000; fnt[4] = 0b00111111; return; } if(c=='X'){ fnt[0] = 0b01000001; fnt[1] = 0b00100010; fnt[2] = 0b00011100; fnt[3] = 0b00100010; fnt[4] = 0b01000001; return; } if(c=='Y'){ fnt[0] = 0b00000001; fnt[1] = 0b00000100; fnt[2] = 0b01110000; fnt[3] = 0b00000100; fnt[4] = 0b00000001; return; } if(c=='Z'){ fnt[0] = 0b01100001; fnt[1] = 0b01010001; fnt[2] = 0b01001001; fnt[3] = 0b01000101; fnt[4] = 0b01000011; return; } // **************** // カナ文字 // **************** if(c=='ア'){ fnt[0] = 0b00000001; fnt[1] = 0b01000001; fnt[2] = 0b00111101; fnt[3] = 0b00001001; fnt[4] = 0b00000111; return; } if(c=='イ'){ fnt[0] = 0b00100000; fnt[1] = 0b00010000; fnt[2] = 0b01111100; fnt[3] = 0b00000011; fnt[4] = 0b00000000; return; } if(c=='ウ'){ fnt[0] = 0b00000110; fnt[1] = 0b00000010; fnt[2] = 0b01000011; fnt[3] = 0b00100010; fnt[4] = 0b00011110; return; } if(c=='エ'){ fnt[0] = 0b01000000; fnt[1] = 0b01000010; fnt[2] = 0b01111110; fnt[3] = 0b01000010; fnt[4] = 0b01000000; return; } if(c=='オ'){ fnt[0] = 0b00100010; fnt[1] = 0b00010010; fnt[2] = 0b00001010; fnt[3] = 0b01111111; fnt[4] = 0b00000010; return; } if(c=='カ'){ fnt[0] = 0b01000010; fnt[1] = 0b00111111; fnt[2] = 0b00000010; fnt[3] = 0b01000010; fnt[4] = 0b00111110; return; } if(c=='キ'){ fnt[0] = 0b00001010; fnt[1] = 0b00001010; fnt[2] = 0b01111111; fnt[3] = 0b00001010; fnt[4] = 0b00001010; return; } if(c=='ク'){ fnt[0] = 0b00000100; fnt[1] = 0b00000011; fnt[2] = 0b01000001; fnt[3] = 0b00100001; fnt[4] = 0b00011111; return; } if(c=='ケ'){ fnt[0] = 0b00001000; fnt[1] = 0b00000111; fnt[2] = 0b01000010; fnt[3] = 0b00111110; fnt[4] = 0b00000010; return; } if(c=='コ'){ fnt[0] = 0b01000010; fnt[1] = 0b01000010; fnt[2] = 0b01000010; fnt[3] = 0b01000010; fnt[4] = 0b01111110; return; } if(c=='サ'){ fnt[0] = 0b00000010; fnt[1] = 0b00001111; fnt[2] = 0b01000010; fnt[3] = 0b00111111; fnt[4] = 0b00000010; return; } if(c=='シ'){ fnt[0] = 0b00001010; fnt[1] = 0b00010100; fnt[2] = 0b00000000; fnt[3] = 0b01000000; fnt[4] = 0b00111110; return; } if(c=='ス'){ fnt[0] = 0b01000010; fnt[1] = 0b00100010; fnt[2] = 0b00011010; fnt[3] = 0b00100110; fnt[4] = 0b01000010; return; } if(c=='セ'){ fnt[0] = 0b00000100; fnt[1] = 0b01111111; fnt[2] = 0b01000100; fnt[3] = 0b01000100; fnt[4] = 0b01011100; return; } if(c=='ソ'){ fnt[0] = 0b00000010; fnt[1] = 0b00000100; fnt[2] = 0b01000000; fnt[3] = 0b00100000; fnt[4] = 0b00011110; return; } if(c=='タ'){ fnt[0] = 0b00001000; fnt[1] = 0b00000110; fnt[2] = 0b01001001; fnt[3] = 0b00100001; fnt[4] = 0b00011111; return; } if(c=='チ'){ fnt[0] = 0b00001000; fnt[1] = 0b01001010; fnt[2] = 0b00111111; fnt[3] = 0b00001001; fnt[4] = 0b00001000; return; } if(c=='ツ'){ fnt[0] = 0b00000100; fnt[1] = 0b00001000; fnt[2] = 0b00000100; fnt[3] = 0b01001000; fnt[4] = 0b00111110; return; } if(c=='テ'){ fnt[0] = 0b00000100; fnt[1] = 0b01000101; fnt[2] = 0b00111101; fnt[3] = 0b00000101; fnt[4] = 0b00000100; return; } if(c=='ト'){ fnt[0] = 0b00000000; fnt[1] = 0b01111111; fnt[2] = 0b00001000; fnt[3] = 0b00010000; fnt[4] = 0b00000000; return; } if(c=='ナ'){ fnt[0] = 0b00000100; fnt[1] = 0b00000100; fnt[2] = 0b01000100; fnt[3] = 0b00111111; fnt[4] = 0b00000100; return; } if(c=='ニ'){ fnt[0] = 0b01000000; fnt[1] = 0b01000010; fnt[2] = 0b01000010; fnt[3] = 0b01000010; fnt[4] = 0b01000000; return; } if(c=='ヌ'){ fnt[0] = 0b01000010; fnt[1] = 0b00101010; fnt[2] = 0b00010010; fnt[3] = 0b00101010; fnt[4] = 0b01000110; return; } if(c=='ネ'){ fnt[0] = 0b00100010; fnt[1] = 0b00010010; fnt[2] = 0b01111011; fnt[3] = 0b00010110; fnt[4] = 0b00100010; return; } if(c=='ノ'){ fnt[0] = 0b00000000; fnt[1] = 0b00000000; fnt[2] = 0b01000000; fnt[3] = 0b00111111; fnt[4] = 0b00000000; return; } if(c=='ハ'){ fnt[0] = 0b01100000; fnt[1] = 0b00011110; fnt[2] = 0b00000000; fnt[3] = 0b00011110; fnt[4] = 0b01100000; return; } if(c=='ヒ'){ fnt[0] = 0b00111110; fnt[1] = 0b01001000; fnt[2] = 0b01001000; fnt[3] = 0b01001000; fnt[4] = 0b01001000; return; } if(c=='フ'){ fnt[0] = 0b00000010; fnt[1] = 0b00000010; fnt[2] = 0b01000010; fnt[3] = 0b01000010; fnt[4] = 0b00111110; return; } if(c=='ヘ'){ fnt[0] = 0b00001000; fnt[1] = 0b00000100; fnt[2] = 0b00000100; fnt[3] = 0b00001000; fnt[4] = 0b00010000; return; } if(c=='ホ'){ fnt[0] = 0b00110010; fnt[1] = 0b00000010; fnt[2] = 0b01111111; fnt[3] = 0b00000010; fnt[4] = 0b00110010; return; } if(c=='マ'){ fnt[0] = 0b00000010; fnt[1] = 0b00001010; fnt[2] = 0b00010010; fnt[3] = 0b00101010; fnt[4] = 0b01000110; return; } if(c=='ミ'){ fnt[0] = 0b00000000; fnt[1] = 0b01001001; fnt[2] = 0b01001001; fnt[3] = 0b01001001; fnt[4] = 0b00000000; return; } if(c=='ム'){ fnt[0] = 0b01110000; fnt[1] = 0b01001111; fnt[2] = 0b01000000; fnt[3] = 0b00110000; fnt[4] = 0b01000000; return; } if(c=='メ'){ fnt[0] = 0b01000000; fnt[1] = 0b00101000; fnt[2] = 0b00011111; fnt[3] = 0b00100000; fnt[4] = 0b00000000; return; } if(c=='モ'){ fnt[0] = 0b00001010; fnt[1] = 0b01111110; fnt[2] = 0b01001010; fnt[3] = 0b01001010; fnt[4] = 0b01001010; return; } if(c=='ヤ'){ fnt[0] = 0b00000100; fnt[1] = 0b01111111; fnt[2] = 0b00000100; fnt[3] = 0b00010100; fnt[4] = 0b00001100; return; } if(c=='ユ'){ fnt[0] = 0b01000000; fnt[1] = 0b01000100; fnt[2] = 0b01000100; fnt[3] = 0b01111100; fnt[4] = 0b01000000; return; } if(c=='ヨ'){ fnt[0] = 0b00000000; fnt[1] = 0b01010100; fnt[2] = 0b01010100; fnt[3] = 0b01111100; fnt[4] = 0b00000000; return; } if(c=='ラ'){ fnt[0] = 0b00000100; fnt[1] = 0b00000101; fnt[2] = 0b01000101; fnt[3] = 0b01000101; fnt[4] = 0b00111100; return; } if(c=='リ'){ fnt[0] = 0b00000000; fnt[1] = 0b00001111; fnt[2] = 0b00000000; fnt[3] = 0b01000000; fnt[4] = 0b00111111; return; } if(c=='ル'){ fnt[0] = 0b01111111; fnt[1] = 0b00000000; fnt[2] = 0b01111111; fnt[3] = 0b01000000; fnt[4] = 0b00100000; return; } if(c=='レ'){ fnt[0] = 0b00000000; fnt[1] = 0b01111111; fnt[2] = 0b01000000; fnt[3] = 0b01000000; fnt[4] = 0b00100000; return; } if(c=='ロ'){ fnt[0] = 0b00000000; fnt[1] = 0b01111110; fnt[2] = 0b01000010; fnt[3] = 0b01000010; fnt[4] = 0b01111110; return; } if(c=='ワ'){ fnt[0] = 0b00000000; fnt[1] = 0b00001110; fnt[2] = 0b00000010; fnt[3] = 0b01000010; fnt[4] = 0b00111110; return; } if(c=='ン'){ fnt[0] = 0b00000010; fnt[1] = 0b00000100; fnt[2] = 0b01000000; fnt[3] = 0b00110000; fnt[4] = 0b00001110; return; } if(c=='゙'){ fnt[0] = 0b00000111; fnt[1] = 0b00000000; fnt[2] = 0b00000111; fnt[3] = 0b00000000; fnt[4] = 0b00000000; return; } if(c=='゚'){ fnt[0] = 0b00000111; fnt[1] = 0b00000101; fnt[2] = 0b00000111; fnt[3] = 0b00000000; fnt[4] = 0b00000000; return; } // **************** // ELSE // **************** if(c==' '){ fnt[0] = 0b00000000; fnt[1] = 0b00000000; fnt[2] = 0b00000000; fnt[3] = 0b00000000; fnt[4] = 0b00000000; return; } if(c=='u'){ fnt[0] = 0b00000100; fnt[1] = 0b00000010; fnt[2] = 0b01111111; fnt[3] = 0b00000010; fnt[4] = 0b00000100; return; } if(c=='d'){ fnt[0] = 0b00010000; fnt[1] = 0b00100000; fnt[2] = 0b01111111; fnt[3] = 0b00100000; fnt[4] = 0b00010000; return; } if(c=='r'){ fnt[0] = 0b00001000; fnt[1] = 0b01001001; fnt[2] = 0b00101010; fnt[3] = 0b00011100; fnt[4] = 0b00001000; return; } if(c=='l'){ fnt[0] = 0b00001000; fnt[1] = 0b00011100; fnt[2] = 0b00101010; fnt[3] = 0b01001001; fnt[4] = 0b00001000; return; } if(c=='a'){ fnt[0] = 0b01111111; fnt[1] = 0b01111111; fnt[2] = 0b01111111; fnt[3] = 0b01111111; fnt[4] = 0b01111111; return; } if(c=='+'){ fnt[0] = 0b00001000; fnt[1] = 0b00001000; fnt[2] = 0b01111111; fnt[3] = 0b00001000; fnt[4] = 0b00001000; return; } if(c=='-'){ fnt[0] = 0b00001000; fnt[1] = 0b00001000; fnt[2] = 0b00001000; fnt[3] = 0b00001000; fnt[4] = 0b00001000; return; } if(c=='='){ fnt[0] = 0b00010100; fnt[1] = 0b00010100; fnt[2] = 0b00010100; fnt[3] = 0b00010100; fnt[4] = 0b00010100; return; } if(c==')'){ fnt[0] = 0b00000000; fnt[1] = 0b00000000; fnt[2] = 0b00000000; fnt[3] = 0b01000001; fnt[4] = 0b00111110; return; } if(c=='('){ fnt[0] = 0b00111110; fnt[1] = 0b01000001; fnt[2] = 0b00000000; fnt[3] = 0b00000000; fnt[4] = 0b00000000; return; } if(c==']'){ fnt[0] = 0b00000000; fnt[1] = 0b00000000; fnt[2] = 0b00000000; fnt[3] = 0b01000001; fnt[4] = 0b01111111; return; } if(c=='['){ fnt[0] = 0b01111111; fnt[1] = 0b01000001; fnt[2] = 0b00000000; fnt[3] = 0b00000000; fnt[4] = 0b00000000; return; } if(c=='>'){ fnt[0] = 0b00000000; fnt[1] = 0b01000001; fnt[2] = 0b00100010; fnt[3] = 0b00010100; fnt[4] = 0b00001000; return; } if(c=='['){ fnt[0] = 0b00001000; fnt[1] = 0b00010100; fnt[2] = 0b00100010; fnt[3] = 0b01000001; fnt[4] = 0b00000000; return; } if(c=='*'){ fnt[0] = 0b00100010; fnt[1] = 0b00010100; fnt[2] = 0b00001000; fnt[3] = 0b00010100; fnt[4] = 0b00100010; return; } if(c=='/'){ fnt[0] = 0b01000000; fnt[1] = 0b01100000; fnt[2] = 0b00011000; fnt[3] = 0b00000110; fnt[4] = 0b00000001; return; } if(c=='"'){ fnt[0] = 0b00000000; fnt[1] = 0b00000111; fnt[2] = 0b00000000; fnt[3] = 0b00000111; fnt[4] = 0b00000000; return; } if(c=='!'){ fnt[0] = 0b00000000; fnt[1] = 0b00000000; fnt[2] = 0b11011111; fnt[3] = 0b00000000; fnt[4] = 0b00000000; return; } if(c==','){ fnt[0] = 0b00000000; fnt[1] = 0b01000000; fnt[2] = 0b00110000; fnt[3] = 0b00000000; fnt[4] = 0b00000000; return; } if(c=='.'){ fnt[0] = 0b00000000; fnt[1] = 0b00000000; fnt[2] = 0b01100000; fnt[3] = 0b00000000; fnt[4] = 0b00000000; return; } if(c==':'){ fnt[0] = 0b00000000; fnt[1] = 0b00000000; fnt[2] = 0b00110110; fnt[3] = 0b00000000; fnt[4] = 0b00000000; return; } if(c==';'){ fnt[0] = 0b00000000; fnt[1] = 0b01000000; fnt[2] = 0b00110110; fnt[3] = 0b00000000; fnt[4] = 0b00000000; return; } // ELSE fnt[0] = 0b00000110; fnt[1] = 0b00001001; fnt[2] = 0b01110001; fnt[3] = 0b00000001; fnt[4] = 0b00000010; return; } //****************************************************************************************** // Function Name : Init_LCD // Title : Initialized LCD // Input : // Output : //****************************************************************************************** void Init_LCD(void) { // ************************* // 1.Default Value // ************************* LCD_BSF_CNT(PI_LCD_E); LCD_BCF_CNT(PI_LCD_RW); LCD_BCF_CNT(PI_LCD_DI); LCD_BSF_CNT(PI_LCD_CS1); LCD_BCF_CNT(PI_LCD_CS2); // ************************* // 2.LCD Reset (1.0[μS]<) // ************************* LCD_BCF_CNT(PI_LCD_RES); NopN(1); //1.0[μS]< // LCD_BSF_CNT(PI_LCD_RES); NopN(1); //1.0[μS]< } //****************************************************************************************** // Function Name : LCD_clear // Title : // Input : // Output : //****************************************************************************************** void LCD_clear(void) { unsigned char lp_page; unsigned char lp_clm; for(lp_page=0;lp_page<8;lp_page++){ for(lp_clm=0;lp_clm<64;lp_clm++){ LCD_dsp(0, lp_page, lp_clm, PI_CS1, 0x00, PI_PAGE); LCD_dsp(0, lp_page, lp_clm, PI_CS2, 0x00, PI_PAGE); } } } //****************************************************************************************** // Function Name : LCD_dsp // Title : // Input : // Output : //****************************************************************************************** void LCD_dsp(unsigned char in_line, unsigned char in_page, unsigned char in_clm, unsigned char in_cs, unsigned char in_dat, unsigned char in_mode) { unsigned char tmp_c; // ************************* // 0.Initialize // ************************* if(in_cs == PI_CS1){ LCD_BSF_CNT(PI_LCD_CS1); LCD_BCF_CNT(PI_LCD_CS2); }else{ LCD_BCF_CNT(PI_LCD_CS1); LCD_BSF_CNT(PI_LCD_CS2); } // ************************* // 1.Display ON // ************************* // (1)Set data LCD_BCF_CNT(PI_LCD_RW); LCD_BCF_CNT(PI_LCD_DI); LCD_MOVF_DB((unsigned char)0b00111111); // (2)Enable signal LCD_ENSIG(); // ************************* // 2.Display Start Line(0-63) // ************************* if(in_mode == PI_LINE){ // (1)Set data LCD_BCF_CNT(PI_LCD_RW); LCD_BCF_CNT(PI_LCD_DI); tmp_c = 0b11000000 | in_line; LCD_MOVF_DB(tmp_c); // (2)Enable signal LCD_ENSIG(); }else if(in_mode == PI_LINE_N){ // None } // ************************* // 3.Page Adress set(0-7) // ************************* if(in_mode == PI_PAGE){ // (1)Set data LCD_BCF_CNT(PI_LCD_RW); LCD_BCF_CNT(PI_LCD_DI); tmp_c = 0b10111000 | (in_page & 0b00000111 ); LCD_MOVF_DB(tmp_c); // (2)Enable signal LCD_ENSIG(); } // ************************* // 4.Set Colmn Adress(0-63) // ************************* // (1)Set data LCD_BCF_CNT(PI_LCD_RW); LCD_BCF_CNT(PI_LCD_DI); tmp_c = 0b01000000 | (in_clm & 0b00111111 ); LCD_MOVF_DB(tmp_c); // (2)Enable signal LCD_ENSIG(); // ************************* // 5.Status Read // ************************* // (1)Set data // LCD_RDTRS_DB(); // LCD_BSF_CNT(PI_LCD_RW); // LCD_BCF_CNT(PI_LCD_DI); // (2)Enable signal // LCD_ENSIG(); // while(1){ // LCD_RED_DB(&tmp_c); // if((tmp_c & 0b10000000)==0) break; // } // LCD_BCF_CNT(PI_LCD_RW); // NopN(5); // LCD_WRTRS_DB(); // ************************* // 6.Write Display Data // ************************* // (1)Set data LCD_BCF_CNT(PI_LCD_RW); LCD_BSF_CNT(PI_LCD_DI); LCD_MOVF_DB(in_dat); // (2)Enable signal LCD_ENSIG(); // ************************* // 7.Read Display Data // ************************* // (1)Set data // LCD_RDTRS_DB(); // LCD_BSF_CNT(PI_LCD_RW); // LCD_BSF_CNT(PI_LCD_DI); // (2)Enable signal // LCD_ENSIG(); // LCD_RED_DB(&tmp_c); // LCD_BCF_CNT(PI_LCD_RW); // NopN(5); // LCD_WRTRS_DB(); } //****************************************************************************************** // Function Name : LCD_read // Title : // Input : // Output : //****************************************************************************************** void LCD_read(unsigned char in_line, unsigned char in_page, unsigned char in_clm, unsigned char in_cs, unsigned char *out_dat, unsigned char in_mode) { unsigned char tmp_c; // ************************* // 0.Initialize // ************************* if(in_cs == PI_CS1){ LCD_BSF_CNT(PI_LCD_CS1); LCD_BCF_CNT(PI_LCD_CS2); }else{ LCD_BCF_CNT(PI_LCD_CS1); LCD_BSF_CNT(PI_LCD_CS2); } // ************************* // 1.Display ON // ************************* // (1)Set data LCD_BCF_CNT(PI_LCD_RW); LCD_BCF_CNT(PI_LCD_DI); LCD_MOVF_DB((unsigned char)0b00111111); // (2)Enable signal LCD_ENSIG(); // ************************* // 2.Display Start Line(0-63) // ************************* if(in_mode == PI_LINE){ // (1)Set data LCD_BCF_CNT(PI_LCD_RW); LCD_BCF_CNT(PI_LCD_DI); tmp_c = 0b11000000 | in_line; LCD_MOVF_DB(tmp_c); // (2)Enable signal LCD_ENSIG(); }else if(in_mode == PI_LINE_N){ // None } // ************************* // 3.Page Adress set(0-7) // ************************* if(in_mode == PI_PAGE){ // (1)Set data LCD_BCF_CNT(PI_LCD_RW); LCD_BCF_CNT(PI_LCD_DI); tmp_c = 0b10111000 | (in_page & 0b00000111 ); LCD_MOVF_DB(tmp_c); // (2)Enable signal LCD_ENSIG(); } // ************************* // 4.Set Colmn Adress(0-63) // ************************* // (1)Set data LCD_BCF_CNT(PI_LCD_RW); LCD_BCF_CNT(PI_LCD_DI); tmp_c = 0b01000000 | (in_clm & 0b00111111 ); LCD_MOVF_DB(tmp_c); // (2)Enable signal LCD_ENSIG(); // ************************* // 5.Status Read // ************************* // (1)Set data // LCD_RDTRS_DB(); // LCD_BSF_CNT(PI_LCD_RW); // LCD_BCF_CNT(PI_LCD_DI); // (2)Enable signal // LCD_ENSIG(); // while(1){ // LCD_RED_DB(&tmp_c); // if((tmp_c & 0b10000000)==0) break; // } // LCD_BCF_CNT(PI_LCD_RW); // NopN(5); // LCD_WRTRS_DB(); // ************************* // 6.Read Display Data // ************************* // (1)Set data LCD_RDTRS_DB(); LCD_BSF_CNT(PI_LCD_RW); LCD_BSF_CNT(PI_LCD_DI); // (2)Enable signal LCD_ENSIG(); LCD_RED_DB(out_dat); LCD_BCF_CNT(PI_LCD_RW); NopN(5); LCD_WRTRS_DB(); } //****************************************************************************************** // Function Name : LCD_ENSIG // Title : Enable Signal // Input : // Output : //****************************************************************************************** void LCD_ENSIG(void) { NopN(1); //450[nS]< LCD_BCF_CNT(PI_LCD_E); NopN(1); //450[nS]< // LCD_BSF_CNT(PI_LCD_E); NopN(1); //450[nS]< } //****************************************************************************************** // Function Name : LCD_BCF_CNT // Title : BSF Control // Input : // Output : //****************************************************************************************** void LCD_BCF_CNT(unsigned int pos) { PORTD = PORTD & ~(1 << pos); } //****************************************************************************************** // Function Name : LCD_BSF_CNT // Title : BSF Control // Input : // Output : //****************************************************************************************** void LCD_BSF_CNT(unsigned int pos) { PORTD = PORTD | (1 << pos); } //****************************************************************************************** // Function Name : BCF_TRS_DB // Title : // Input : // Output : //****************************************************************************************** void LCD_WRTRS_DB(void) { TRISB = 0b00000000; } //****************************************************************************************** // Function Name : BSF_TRS_DB // Title : // Input : // Output : //****************************************************************************************** void LCD_RDTRS_DB(void) { TRISB = 0b11111111; } //****************************************************************************************** // Function Name : LCD_BCF_DB // Title : BCF DB0 - DB7 // Input : // Output : //****************************************************************************************** void LCD_BCF_DB(unsigned int pos) { PORTB = PORTB & ~(1 << pos); } //****************************************************************************************** // Function Name : LCD_BSF_DB // Title : BSF DB0 - DB7 // Input : // Output : //****************************************************************************************** void LCD_BSF_DB(unsigned int pos) { PORTB = PORTB | (1 << pos); } //****************************************************************************************** // Function Name : LCD_MOVF_DB // Title : MOVF DB0 - DB7 // Input : // Output : //****************************************************************************************** void LCD_MOVF_DB(unsigned char dat) { PORTB = dat; } //****************************************************************************************** // Function Name : LCD_RED_DB // Title : Read DB0 - DB7 // Input : // Output : //****************************************************************************************** void LCD_RED_DB(unsigned char *dat) { *dat = PORTB; } //****************************************************************************************** // Function Name : NopN // Title : // Input : // Output : 10(STEP) < // Description : OSC:10MHz,PLL:ON // ==> 10MHz * 4(PLL) / 4(PIC) * 10 ==> 1MHz(1μS) / n < //****************************************************************************************** void NopN(unsigned int n) { unsigned int lp; for(lp=0;lp: Timer1 Input Clock Prescale Select bits // 11 = 1:8 Prescale value // 10 = 1:4 Prescale value // 01 = 1:2 Prescale value // 00 = 1:1 Prescale value //* T1CON(3) T1OSCEN: Timer1 Oscillator Enable bit // 1 = Timer1 oscillator is enabled // 0 = Timer1 oscillator is shut off // The oscillator inverter and feedback resistor are turned off to eliminate power drain. //* T1CON(2) T1SYNC: Timer1 External Clock Input Synchronization Select bit // When TMR1CS = 1: // 1 = Do not synchronize external clock input // 0 = Synchronize external clock input // When TMR1CS = 0: // This bit is ignored. Timer1 uses the internal clock when TMR1CS = 0. //* T1CON(1) TMR1CS: Timer1 Clock Source Select bit // 1 = External clock from the T13CKI pin (on the rising edge) // 0 = Internal clock (FOSC/4) //* T1CON(0) bit 0 TMR1ON: Timer1 On bit // 1 = Enables Timer1 // 0 = Stops Timer1 // ******************************************************* T1CON = 0b10000001; // 16-bit Read/Write Mode, 1:8 Prescale value // ******************************************************* // 2.Define TMR1 Register // Caution(16-bit Read/Write Mode) !!!!: // (a)Writing to TMR1H does not directly affect Timer1. // Instead, the high byte of Timer1 is updated with the contents of TMR1H when a write occurs to TMR1L. // This allows all 16 bits of Timer1 to be updated at once. // (b)A read from TMR1L will load the contents of the high byte of Timer1 into the Timer1 high byte buffer. // This provides the user with the ability to accurately read all 16 bits of Timer1 without the need to // determine whether a read of the high byte, followed by a read of the low byte, has become invalid due // to a rollover or carry between reads. // ******************************************************* // TMR1 data ( OSC:10MHz, 4X PLLON, 1:1 Prescale value, 0.001[S];1000Hz ) // 1mS(1000Hz): 10MHz * 4(PLLON) / 4(PIC) / 1(Prescale) / 1000(1000Hz)==> 0d10,000(Count) ==> 0x2710(Count) // TMR1 = 0xFFFF - 0x2710 ==> 0xD8EF // TMR1H = 0xD8; TMR1L = 0xEF; // ******************************************************* // 3.Timer // ******************************************************* PIR1bits.TMR1IF = 0; while(1){ if(PIR1bits.TMR1IF != 0 )break; } } //**************************************************************************** // Function Name : Init_USART // Title : // Input : // Output : // Description : //**************************************************************************** void Init_USART(void) { // ******************************************************* // 1.Define TXSTA(TRANSMIT STATUS AND CONTROL) Register // TXSTA(7) CSRC: Clock Source Select bit // Asynchronous mode:Don’t care // TXSTA(6) TX9: 9-bit Transmit Enable bit // 1 = Selects 9-bit transmission // 0 = Selects 8-bit transmission // TXSTA(5) TXEN: Transmit Enable bit(1) // 1 = Transmit enabled // 0 = Transmit disabled // TXSTA(4) SYNC: EUSART Mode Select bit // 1 = Synchronous mode // 0 = Asynchronous mode // TXSTA(3) SENDB: Send Break Character bit // Asynchronous mode: // 1 = Send Sync Break on next transmission (cleared by hardware upon completion) // 0 = Sync Break transmission completed // TXSTA(2) BRGH: High Baud Rate Select bit // Asynchronous mode: // 1 = High speed // 0 = Low speed // TXSTA(1) TRMT: Transmit Shift Register Status bit // 1 = TSR empty // 0 = TSR full // TXSTA(0) TX9D: Ninth bit of Transmit Data // Can be address/data bit or a parity bit. // ******************************************************* TXSTA = 0b00100100; // ******************************************************* // 2.Define RCSTA(RECEIVE STATUS AND CONTROL) Register // RCSTA(7) SPEN: Serial Port Enable bit // 1 = Serial port enabled (configures RX/DT and TX/CK pins as serial port pins) // 0 = Serial port disabled (held in Reset) // RCSTA(6) RX9: 9-bit Receive Enable bit // 1 = Selects 9-bit reception // 0 = Selects 8-bit reception // RCSTA(5) SREN: Single Receive Enable bit // Asynchronous mode: // Don’t care // RCSTA(4) CREN: Continuous Receive Enable bit // Asynchronous mode: // 1 = Enables receiver // 0 = Disables receiver // RCSTA(3) ADDEN: Address Detect Enable bit // Asynchronous mode 9-bit (RX9 = 1): // 1 = Enables address detection, enable interrupt and load the receive buffer when RSR<8> is set // 0 = Disables address detection, all bytes are received and ninth bit can be used as parity bit // Asynchronous mode 8-bit (RX9 = 0): // Don’t care // RCSTA(2) FERR: Framing Error bit // 1 = Framing error (can be updated by reading RCREG register and receive next valid byte) // 0 = No framing error // RCSTA(1) OERR: Overrun Error bit // 1 = Overrun error (can be cleared by clearing bit CREN) // 0 = No overrun error // RCSTA(0) RX9D: Ninth bit of Received Data // This can be address/data bit or a parity bit and must be calculated by user firmware. // ******************************************************* RCSTA=0b10010000; // ******************************************************* // 3.Define BAUDCON(BAUD RATE CONTROL) Register // BAUDCON(7) ABDOVF: Auto-Baud Detect Overflow bit // Asynchronous mode: // 1 = Auto-baud timer overflowed // 0 = Auto-baud timer did not overflow // BAUDCON(6) RCIDL: Receive Idle Flag bit // Asynchronous mode: // 1 = Receiver is Idle // 0 = Start bit has been detected and the receiver is active // BAUDCON(5) RXDTP: Data/Receive Polarity Select bit // Asynchronous mode: // 1 = Receive data (RX) is inverted (active-low) // 0 = Receive data (RX) is not inverted (active-high) // BAUDCON(4) TXCKP: Clock/Transmit Polarity Select bit // Asynchronous mode: // 1 = Idle state for transmit (TX) is low // 0 = Idle state for transmit (TX) is high // BAUDCON(3) BRG16: 16-bit Baud Rate Generator bit // 1 = 16-bit Baud Rate Generator is used (SPBRGH:SPBRG) // 0 = 8-bit Baud Rate Generator is used (SPBRG) // BAUDCON(2) Unimplemented: Read as ‘0’ // BAUDCON(1) WUE: Wake-up Enable bit // Asynchronous mode: // 1 = Receiver is waiting for a falling edge. No character will be received but RCIF will be set on // the falling edge. WUE will automatically clear on the rising edge. // 0 = Receiver is operating normally // BAUDCON(0) ABDEN: Auto-Baud Detect Enable bit // Asynchronous mode: // 1 = Auto-Baud Detect mode is enabled (clears when auto-baud is complete) // 0 = Auto-Baud Detect mode is disabled // ******************************************************* BAUDCON = 0b00001000; // ******************************************************* // 3.Define BRG(EUSART Baud Rate Generator Register) Register // ******************************************************* // SYNC = 0, BRGH = 1, BRG16 = 1 or SYNC = 1, BRG16 = 1 // BRG = 40000000(Hz)/4/9600(BPS)-1 ==> 0d1040 ==> 0x410 // (1)Define SPBRGH(EUSART Baud Rate Generator Register, High Byte) Register SPBRGH = 0x4; // (2)Define SPBRG(EUSART Baud Rate Generator Register, Low Byte) Register SPBRG = 0x10; } //**************************************************************************** // Function Name : Trans_USART // Title : // Input : // Output : // Description : //**************************************************************************** void Trans_USART(unsigned char IO_data ) { char chk_flg; // // 1.Check Send Flag // while(1){ chk_flg = TXSTA & 0x02; //0000,0010 TXSTA(TRMT) if(chk_flg != 0x00)break; } // // 2.Set data // TXREG = IO_data; } //**************************************************************************** // Function Name : Rec_USART // Title : // Input : // Output : // Description : //**************************************************************************** void Rec_USART(unsigned char *IO_data ) { char chk_flg; // // 1.Check Recvive Flag // while(1){ chk_flg = PIR1 & 0x20; //0010,0000 PIR1(RCIF) if(chk_flg != 0x00)break; } // // 2.Check error // chk_flg = RCSTA & 0x06; //0000,0110 RCSTA(FERR,OERR) if(chk_flg != 0x00){ *IO_data = 0x00; return; } // // 3.Set Recive Data // *IO_data = RCREG; }