void LCDinit(void) { PORTA = 00; // Clear Control port LATA = 00; // and its corresponding Latch TRISA = 0x01; // Make PORTA as output port ADCON1 = 0x0E; // Make PORTA as digitital I/O // This is done here assuming application code may be using PORTA of Analog application. _delay(4); // _delay(4); // _delay(4); //~15 ms delay WriteNibble(0x30); // #1 control byte _delay(4); WriteNibble(0x30); // #2 control byte _delay_100us(); WriteNibble(0x30); // #3 control byte _delay_100us(); WriteNibble(0x20); // #4 control sets 4 bit mode _delay_100us(); Check_LCDBusy(); // Check whther LCD is free to continue operation FunctionSet(0x28); // #5 control byte Function set DisplayON (0x0D); // Turn on Display DisplayClr (0x01); // Clear Display (clears junk if any) EntryMode(0x06); // Entry mode selection DDRAMadrs(0x80); // Initialise DDRAM address to 80h. } // LCD Init ends
/** @brief Initialize all HD44780 control pins, set default mode, and return home * @retval None */ void hd44780_c::Start(void){ GPIO_InitTypeDef GPIO_InitStructure; //init EN pin RCC_APB2PeriphClockCmd(HD44780_EN_CLK, ENABLE); GPIO_InitStructure.GPIO_Pin = HD44780_EN_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(HD44780_EN_PORT, &GPIO_InitStructure); GPIO_ResetBits(HD44780_EN_PORT, HD44780_EN_PIN); //init RS pin RCC_APB2PeriphClockCmd(HD44780_RS_CLK, ENABLE); GPIO_InitStructure.GPIO_Pin = HD44780_RS_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(HD44780_RS_PORT, &GPIO_InitStructure); //init RW pin RCC_APB2PeriphClockCmd(HD44780_RW_CLK, ENABLE); GPIO_InitStructure.GPIO_Pin = HD44780_RW_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(HD44780_RW_PORT, &GPIO_InitStructure); //init DATA pins RCC_APB2PeriphClockCmd(HD44780_DATA_CLK, ENABLE); GPIO_InitStructure.GPIO_Pin = HD44780_DATA_PIN_4| HD44780_DATA_PIN_5| HD44780_DATA_PIN_6| HD44780_DATA_PIN_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(HD44780_DATA_PORT, &GPIO_InitStructure); FunctionSet(false, false); FunctionSet(false, false); OnOff(true, true, true); EntryMode(false, true); Clear(); Home(); HLib::LoopDelay(1000000); Print("Wellcome to HLib"); }