/**************************************************** * My LCD Libraly for PIC24F * * 2011.08.05 N.Ishii *****************************************************/ #include #include "My_LCD_Lib.h" // lcd char_gane ram user data table char lcd_cg_ram_data[] = { 0,0x0e,0x11,0x11,0x11,0x0e,0,0, // White circle 0,0x0e,0x1f,0x1f,0x1f,0x0e,0,0, // Black circle 0x0a,0x1f,0x1f,0x1f,0x1f,0x0e,0x04,0, // harat 0,0x04,0x0e,0x1f,0x0e,0x04,0,0, // Dia 0x04,0x0e,0x1f,0x1f,0x1f,0x04,0x0e,0, // Spades 0x0e,0x0e,0x15,0x1f,0x15,0x04,0x0e,0, // Clover 0x15,0x0a,0x15,0x0a,0x15,0x0a,0x15,0, // Checkered 0x02,0x13,0x1f,0x1f,0x1c,0x14,0x14,0 // Smole Dog }; //------------------------------------------------------------ // Delay Subrutin void Waitx1ms(int x) // Td = 1mS * x { int i,j; for(i = 0 ; i < x ; ++i) { for(j = 0 ; j < 2620 ; ++j) asm("clrwdt"); //Td=1mS } } void Waitx1us(int x) // Td = 1uS * x { int i; for(i = 0 ; i < x ; ++i) { /// Td=1000nS(125nS x 8) + Margin asm("clrwdt"); //Td=125nS(62.5nS x 2) asm("clrwdt"); asm("clrwdt"); asm("clrwdt"); asm("clrwdt"); asm("clrwdt"); asm("clrwdt"); asm("clrwdt"); asm("clrwdt"); asm("clrwdt"); } } //-------------------------------------------------------------------- void one_chr_wr(char chr_code) { LCD_DATA_WR_MODE; //RS_pin = 1: select data Reg // A Higher 4bit data out LCD_DATA_BIT7 = (unsigned int)((chr_code & 0x80)>>7); LCD_DATA_BIT6 = (unsigned int)((chr_code & 0x40)>>6); LCD_DATA_BIT5 = (unsigned int)((chr_code & 0x20)>>5); LCD_DATA_BIT4 = (unsigned int)((chr_code & 0x10)>>4); Waitx1us(1); LCD_ENABLE_ON; Waitx1us(1); LCD_ENABLE_OFF; // A Lower 4bit data out LCD_DATA_BIT7 = (unsigned int)((chr_code & 0x08)>>3); LCD_DATA_BIT6 = (unsigned int)((chr_code & 0x04)>>2); LCD_DATA_BIT5 = (unsigned int)((chr_code & 0x02)>>1); LCD_DATA_BIT4 = (unsigned int)(chr_code & 0x01); Waitx1us(1); LCD_ENABLE_ON; Waitx1us(1); LCD_ENABLE_OFF; Waitx1us(50); } void lcd_chr_wr(char *buffer) { while(*buffer != '\0') { one_chr_wr(*buffer); /* calling another function */ /* to write each char to the lcd module */ buffer++; } } void lcd_inst_wr(char inst_code) { LCD_INST_WR_MODE; //RS_pin = 0: select Instruction Reg // A Higher 4bit data out LCD_DATA_BIT7 = (unsigned int)((inst_code & 0x80)>>7); LCD_DATA_BIT6 = (unsigned int)((inst_code & 0x40)>>6); LCD_DATA_BIT5 = (unsigned int)((inst_code & 0x20)>>5); LCD_DATA_BIT4 = (unsigned int)((inst_code & 0x10)>>4); Waitx1us(1); LCD_ENABLE_ON; Waitx1us(1); LCD_ENABLE_OFF; // A Lower 4bit data out LCD_DATA_BIT7 = (unsigned int)((inst_code & 0x08)>>3); LCD_DATA_BIT6 = (unsigned int)((inst_code & 0x04)>>2); LCD_DATA_BIT5 = (unsigned int)((inst_code & 0x02)>>1); LCD_DATA_BIT4 = (unsigned int)(inst_code & 0x01); Waitx1us(1); LCD_ENABLE_ON; Waitx1us(1); LCD_ENABLE_OFF; if ((inst_code & 0x03) != 0) Waitx1ms(20); // inst_code is Clear(0x01) or Cursor Home(0x02) Then Wait 20mS else Waitx1us(50); // other code Then Wait 50uS } void lcd_cg_ram_user_set(void) { unsigned int cg_ram_address; for (cg_ram_address = 0 ; cg_ram_address != 64 ; ++cg_ram_address) // 8*8 { lcd_inst_wr(cg_ram_address + 0x40); // CG RAM Address Set(cgramadd:8*3char) one_chr_wr (lcd_cg_ram_data[cg_ram_address]); } // this function excute after is from cg_ram } void lcd_init(void) { // Allow a delay(minimum of 15ms) // Waitx1ms(20); Waitx1ms(25); // Error LCD Movement:The cause of Low Temperrature: 101230 //------ 1st step: port_output regster set -------------- // Initialize the data port/control pins to zero LCD_DATA_BIT7 = 0; LCD_DATA_BIT6 = 0; LCD_DATA_BIT5 = 0; LCD_DATA_BIT4 = 0; LCD_INST_WR_MODE; //RS_pin = 0 LCD_ENABLE_OFF; //E_pin = 0 //-------------------------------------------------------- //------- 2nd step: port_mode regster set --------------- // Configure the data pins as output TRISBbits.TRISB12 =0; // RB12 is LCD DB4 OUTPUT TRISBbits.TRISB13 =0; // RB13 is LCD DB5 OUTPUT TRISBbits.TRISB14 =0; // RB14 is LCD DB6 OUTPUT TRISBbits.TRISB15 =0; // RB15 is LCD DB7 OUTPUT // Make all control pins as outputs TRISBbits.TRISB10 =0; // RB10 is LCD Enable OUTPUT TRISBbits.TRISB11 =0; // RB11 is LCD RS OUTPUT //------------------------------------------------------- // Initialize stage 1: Set stage 1 only 8-bit Interface // Set Upper 4 Bit Data on RB12 - RB15 LCD_DATA_BIT7 = 0; LCD_DATA_BIT6 = 0; LCD_DATA_BIT5 = 1; LCD_DATA_BIT4 = 1; Waitx1us(1); LCD_ENABLE_ON; Waitx1us(1); LCD_ENABLE_OFF; Waitx1ms(5); // Initialize stage 2: Set stage 2 only 8-bit Interface LCD_DATA_BIT7 = 0; LCD_DATA_BIT6 = 0; LCD_DATA_BIT5 = 1; LCD_DATA_BIT4 = 1; Waitx1us(1); LCD_ENABLE_ON; Waitx1us(1); LCD_ENABLE_OFF; Waitx1ms(1); // Initialize stage 3: Set stage 3 only 8-bit Interface LCD_DATA_BIT7 = 0; LCD_DATA_BIT6 = 0; LCD_DATA_BIT5 = 1; LCD_DATA_BIT4 = 1; Waitx1us(1); LCD_ENABLE_ON; Waitx1us(1); LCD_ENABLE_OFF; Waitx1ms(1); // Initialize stage 4: 4-bit Interface LCD_DATA_BIT7 = 0; LCD_DATA_BIT6 = 0; LCD_DATA_BIT5 = 1; LCD_DATA_BIT4 = 0; Waitx1us(1); LCD_ENABLE_ON; Waitx1us(1); LCD_ENABLE_OFF; Waitx1ms(1); //----- Fixed LCD Setting------------ lcd_inst_wr(FOUR_BIT_FONT5x7dot); // Function Set lcd_inst_wr(DISP_ON_CURSOR_ON_BLINK_OFF); lcd_inst_wr(DISP_CLEAR_CURSOR_HOME); // Set DDRAM Address = 0 lcd_inst_wr(RAM_WR_AFTER_PLUS_1); // Entry mode Set }