void LCD_init() // fuction for intialize { set_port_direction(outport,0xFF); // intialize output port LCD_SendCmd(0x02); // to initialize LCD in 4-bit mode. LCD_SendCmd(0x28); // to initialize LCD in 2 lines, 5X7 dots and 4bit mode. LCD_SendCmd(0x0C); // make lcd ready for write LCD_SendCmd(0x06); // increment cursor to right LCD_SendCmd(0x80); // start form address 80 @ x in row 0 }
void LCD_Gotoxy(int x,int y) // LCD write data in specific position { if(y>0) // it mean that i will write in second row { LCD_SendCmd(0xC0+x); // second row start @ address = 0xC0 } else // i will write in first row { LCD_SendCmd(0x80+x); // first row start @ address = 0x80 } _delay_ms(200); }
//========================================================================================== // Set cursor position on LCD display. //========================================================================================== void LCD_GoTo (unsigned char line, unsigned char column) { uint8_t position = 0; position = (line * 0x40) + column; position = 0x80 + (position & 0x7F); LCD_SendCmd(position); }
//========================================================================================== // Initialize the LCD. //========================================================================================== void LCD_Initialization(void) { uint8_t i; char const *p; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = (LCD_D7 | LCD_D6 | LCD_D5 | LCD_D4 | LCD_EN | LCD_RS); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(LCD_PORT, &GPIO_InitStructure); delay_ms(15); GPIO_ResetBits(LCD_PORT, LCD_RS); GPIO_ResetBits(LCD_PORT, LCD_EN); for(i = 0; i<3; i++) { GPIO_SetBits(LCD_PORT, LCD_D4 | LCD_D5); GPIO_ResetBits(LCD_PORT, LCD_D6 | LCD_D7); GPIO_SetBits(LCD_PORT, LCD_EN); delay_us(50); GPIO_ResetBits(LCD_PORT, LCD_EN); delay_ms(10); } delay_ms(50); GPIO_SetBits(LCD_PORT, LCD_D5); GPIO_ResetBits(LCD_PORT,LCD_D4 | LCD_D6 | LCD_D7); GPIO_SetBits(LCD_PORT, LCD_EN); delay_ms(50); GPIO_ResetBits(LCD_PORT, LCD_EN); LCD_SendCmd(0x28); LCD_SendCmd(0x08); LCD_SendCmd(0x01); LCD_SendCmd(0x06); LCD_SendCmd(0x0C); delay_ms(5); /* Load user-specific characters into CGRAM */ LCD_SendCmd(0x40); /* Set CGRAM address counter to 0 */ p = &UserFont[0][0]; for (i = 0; i < sizeof(UserFont); i++, p++) LCD_SendData (*p); LCD_SendCmd(0x80); /* Set DDRAM address counter to 0 */ }
void LCD_Clear() { LCD_SendCmd(0x01); _delay_ms(200); }
//========================================================================================== // Clear the LCD display. //========================================================================================== void LCD_Clear(void) { LCD_SendCmd(0x01); }