//****************************************************************************************** // PIC18F452 Sample Program // Project : // Program Name : // Programer : // Create date : Version 1.0 H23.07.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 OSCS=OFF //Osc. Switch Enable: #pragma config PWRT=OFF //Power-up Timer: #pragma config BOR=OFF //Brown-out Reset: #pragma config BORV=25 //Brown-out Voltage: 2.5V #pragma config WDT=OFF //Watchdog Timer: #pragma config WDTPS=1 //Watchdog Postscaler: 1:1 #pragma config CCP2MUX=OFF //CCP2 MUX: Disable(RB3) //#pragma config CCP2MUX = ON //CCP2 MUX: Enable(RC1) #pragma config STVR=OFF //Stack Overflow Reset: #pragma config LVP=OFF //Low Voltage ICSP: #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 PI_SOLID_LINE 19 #define PI_DOTTED_LINE 20 // //Define Function // void Prog01(void); void Prog02(void); void Prog03(void); void Prog04(void); char GRF_LINE(unsigned char, 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, 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_ADC(void); void GetADC(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=0b00000111; //ALL Degital Port // (5)Initilized A/D Converter Init_ADC(); // (6)Initialized LCD Init_LCD(); LCD_clear(); // ************************************* // 2.Program Main // ************************************* // (1)Program main // Prog01(); // Wait_1mS(1000); //Wait 1[S] ; 1000mS // LCD_clear(); Prog04(); 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 : Prog04 // Title : ドット表示サンプル // Input : // Output : // Description : //****************************************************************************************** void Prog04(void) { unsigned char lp,lp_1; unsigned char y; unsigned int adc_data; unsigned int adc_data_min = 9999; unsigned int adc_data_max = 0; unsigned int adc_data_ave = 0; unsigned long adc_data_total = 0; unsigned char tmp_line[6]; // ***************************************** // 1.Line // ***************************************** // PSET(0, 0, PI_CS1, PI_FUR); GRF_LINE(5, 5, 5, 60, PI_CS1, PI_SOLID_LINE, PI_FUR); GRF_LINE(5, 5, 60, 5, PI_CS1, PI_SOLID_LINE, PI_SEC); GRF_LINE(5, 15, 60, 15, PI_CS1, PI_DOTTED_LINE, PI_SEC); GRF_LINE(5, 25, 60, 25, PI_CS1, PI_DOTTED_LINE, PI_SEC); GRF_LINE(5, 35, 60, 35, PI_CS1, PI_DOTTED_LINE, PI_SEC); GRF_LINE(5, 45, 60, 45, PI_CS1, PI_DOTTED_LINE, PI_SEC); GRF_LINE(5, 55, 60, 55, PI_CS1, PI_DOTTED_LINE, PI_SEC); GRF_LINE(15, 5, 15, 60, PI_CS1, PI_DOTTED_LINE, PI_SEC); GRF_LINE(25, 5, 25, 60, PI_CS1, PI_DOTTED_LINE, PI_SEC); GRF_LINE(35, 5, 35, 60, PI_CS1, PI_DOTTED_LINE, PI_SEC); GRF_LINE(45, 5, 45, 60, PI_CS1, PI_DOTTED_LINE, PI_SEC); GRF_LINE(55, 5, 55, 60, PI_CS1, PI_DOTTED_LINE, PI_SEC); // Put_LCD_charrec('T', 7, 9, PI_CS1,PI_LCD_SEC); Put_LCD_charrec('V', 0, 0, PI_CS1,PI_LCD_SEC); // ***************************************** // 2.Title // ***************************************** Put_LCD_charrec('M', 0, 1, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('E', 0, 2, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('A', 0, 3, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('S', 0, 4, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('U', 0, 5, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('R', 0, 6, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('E', 0, 7, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('[', 1, 4, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('M', 1, 5, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('V', 1, 6, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(']', 1, 7, PI_CS2,PI_LCD_SEC); // Put_LCD_charrec('M', 3, 0, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('A', 3, 1, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('X', 3, 2, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(':', 3, 3, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('M', 4, 0, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('I', 4, 1, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('N', 4, 2, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(':', 4, 3, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('A', 5, 0, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('V', 5, 1, PI_CS2,PI_LCD_SEC); Put_LCD_charrec('E', 5, 2, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(':', 5, 3, PI_CS2,PI_LCD_SEC); // ***************************************** // 3.Graf // ***************************************** // (1)Graf for(lp=0;lp<50;lp++){ GetADC(&adc_data); y = adc_data / 10 ; GRF_LINE((lp+6),5,(lp+6),(y+5), PI_CS1, PI_SOLID_LINE, PI_SEC); adc_data_total = adc_data_total + adc_data ; if(adc_data_min > adc_data) adc_data_min = adc_data ; if(adc_data_max < adc_data) adc_data_max = adc_data ; Wait_1mS(1000); //Wait 1[S] ; 1000mS } // (2)Infomation sprintf(tmp_line,"%5d",adc_data_max * 10); Put_LCD_charrec(tmp_line[0], 3, 4, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[1], 3, 5, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[2], 3, 6, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[3], 3, 7, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[4], 3, 8, PI_CS2,PI_LCD_SEC); sprintf(tmp_line,"%5d",adc_data_min * 10); Put_LCD_charrec(tmp_line[0], 4, 4, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[1], 4, 5, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[2], 4, 6, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[3], 4, 7, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[4], 4, 8, PI_CS2,PI_LCD_SEC); adc_data_ave = adc_data_total / 50 ; sprintf(tmp_line,"%5d",adc_data_ave * 10); Put_LCD_charrec(tmp_line[0], 5, 4, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[1], 5, 5, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[2], 5, 6, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[3], 5, 7, PI_CS2,PI_LCD_SEC); Put_LCD_charrec(tmp_line[4], 5, 8, PI_CS2,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 line_mode, 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, line_mode, 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 line_mode, 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; unsigned char lp_add; // ********************** // 0.Initialize // ********************** if(line_mode == PI_DOTTED_LINE){ lp_add = 2; }else{ lp_add = 1; } // ********************** // 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=lp+lp_add){ 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_ADC // Title : // Input : // Output : // Description : Select AN0 //****************************************************************************************** void Init_ADC(void) { // ******************************************************* // 1.Define ADCON0(A/D CONTROL REGISTER 0) Register // ADCON0(7-6) ADCS1:ADCS0: A/D Conversion Clock Select bits (ADCON0 bits in bold) // ADCON0(5-3) CHS2:CHS0: Analog Channel Select bits // 000 = channel 0, (AN0) // 001 = channel 1, (AN1) // 010 = channel 2, (AN2) // 011 = channel 3, (AN3) // 100 = channel 4, (AN4) // 101 = channel 5, (AN5) // 110 = channel 6, (AN6) // 111 = channel 7, (AN7) // ADCON0(2) GO/DONE: A/D Conversion Status bit // When ADON = 1: // 1 = A/D conversion in progress (setting this bit starts the A/D conversion which is automatically // cleared by hardware when the A/D conversion is complete) // 0 = A/D conversion not in progress // ADCON0(1) Unimplemented: Read as '0' // ADCON0(0) ADON: A/D On bit // 1 = A/D converter module is powered up // 0 = A/D converter module is shut-off and consumes no operating current Legend: // ******************************************************* ADCON0 = 0b10000001; // ******************************************************* // 2.Define ADCON1(A/D CONTROL REGISTER 1) Register // ADCON1(7) ADFM: A/D Result Format Select bit // 1 = Right justified. Six (6) Most Significant bits of ADRESH are read as ’0’. // 0 = Left justified. Six (6) Least Significant bits of ADRESL are read as ’0’. // ADCON1(6) ADCS2: A/D Conversion Clock Select bit (ADCON1 bits in bold) // ADCON1(5-4) Unimplemented: Read as '0' // ADCON1(3-0) PCFG3:PCFG0: A/D Port Configuration Control bits // ******************************************************* ADCON1 = 0b10001110; } //****************************************************************************************** // Function Name : GetADC // Title : // Input : // Output : // Description : //****************************************************************************************** void GetADC(unsigned int *adc_data) { unsigned char Dat_L,Dat_H; // ***************** // 1.Start ADC // ***************** // GO/DONE: A/D Conversion Status bit ADCON0 = ADCON0 | 0b00000100; // ***************** // 2.Get data // ***************** while((ADCON0 & 0b00000100)!=0); Dat_H = ADRESH; Dat_L = ADRESL; // ***************** // 3.Edit data // ***************** *adc_data = Dat_H * 256 + Dat_L; } //**************************************************************************** // 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) Unimplemented: Read as '0' // 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; TXSTA = 0b00100000; // ******************************************************* // 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 SPBRG(Baud Rate Generator Register) Register // ******************************************************* // 9600BPS, OSC:40MHz(40MHz*PLL) ==> SPREG=64 SPBRG=64; } //**************************************************************************** // 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; }