Beispiel #1
0
void hd44780_init(struct dev_hd44780_ctx *a_disp) {
	
	uint8_t x = HD44780_DATALINES;

	GPIO_CONFIGURE_AS_OUTPUT(&a_disp->rs);
	GPIO_CONFIGURE_AS_OUTPUT(&a_disp->e);

#if HD44780_USE_RW_LINE == 1
	GPIO_CONFIGURE_AS_OUTPUT(&a_disp->rw);
	GPIO_SET_LOW(&a_disp->rw);
#endif

	// set control lines low
	GPIO_SET_LOW(&a_disp->rs);
	GPIO_SET_LOW(&a_disp->e);

	// set all data lines high
	while (x--) {
		GPIO_CONFIGURE_AS_OUTPUT(&a_disp->data[x]);
		GPIO_SET_HIGH(&a_disp->data[x]);
	}

	// wait for the display
	_delay_ms(HD44780_RESET_DELAY_MS);

#if HD44780_8BIT_MODE == 1
	GPIO_SET_LOW(&a_disp->data[7]);
	GPIO_SET_LOW(&a_disp->data[6]);
#else
	GPIO_SET_LOW(&a_disp->data[3]);
	GPIO_SET_LOW(&a_disp->data[2]);
#endif

	_hd44780_data_latch(a_disp);
	_delay_ms(5);

	_hd44780_data_latch(a_disp);
	_delay_us(100);

#if HD44780_8BIT_MODE == 0
	GPIO_SET_LOW(&a_disp->data[0]);
#endif

	_hd44780_data_latch(a_disp);

	// wait for a while before sending the "real" commands
	_delay_us(10);

	// set font and display lines
#if HD44780_8BIT_MODE == 1
	hd44780_cmd(a_disp, HD44780_CMD_FUNCTION_SET(1, (a_disp->lines >= 2), a_disp->font));
#else
	hd44780_cmd(a_disp, HD44780_CMD_FUNCTION_SET(0, (a_disp->lines >= 2), a_disp->font));
#endif

	// display on, cursor off, blink off
	hd44780_cmd(a_disp, HD44780_CMD_DISPLAY_CONTROL(1, 0, 0));

	// clear the screen
	hd44780_clrscr(a_disp);

	// set entry mode
	hd44780_cmd(a_disp, HD44780_CMD_ENTRY_MODE(1, 0));
}
Beispiel #2
0
//*****************************************************************************
//
//! \brief Init the HD44780 LCD Device.
//!
//! \param None.
//!
//! This function is used to Init the HD44780 Device. It must be call before 
//! any other LCD function use.
//!
//! It Open the pins's GPIO peripheral port, and config the pins type to GPIO 
//! output. Then config the LCD into the default state, clear the LCD and 
//! Open the display. Default A Blink cursor is set on. The LCD cursor move 
//! direction is config as increment default.
//!
//! The HD44780 Initial state can be determined by the \ref HD44780_Config.
//! - Pins that used is determined by \ref HD44780_Config_Pins.
//! - The inteface data length is determined by \ref HD44780_INTERFACE_DATA_LEN.
//! - The LCD display line is determined by \ref HD44780_DISPLAY_LINE.
//! - The LCD character font is determined by \ref HD44780_CHARACTER_FONT.
//! .
//! 
//! \return None.
//
//*****************************************************************************
void 
HD44780Init(void)
{
	ucDisplayFunction = (HD44780_INTERFACE_DATA_LEN |
                         HD44780_FUNCTION_SET_N_2 |
                         HD44780_CHARACTER_FONT);
	ucRsPin = 1;
	ucRwPin = 255;
	ucEnablePin = 2;
	ucDataPin[0] = 6;
	ucDataPin[1] = 5;
	ucDataPin[2] = 4;
	ucDataPin[3] = 3;
	_SPIbuff = 0;

    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(HD44780_PIN_CS));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(HD44780_PIN_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(HD44780_PIN_MOSI));
     

#if HD44780_SPI_MODE == SPIMODE_HARDWARE
    //
    // Enable Peripheral SPI1
    //
    xSysCtlPeripheralEnable2(HD44780_SPI);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

    //
    // Configure Some GPIO pins as SPI Mode    SPI MISO is no use in LCD4884
    //
    xSPinTypeSPI(HD44780_CLK,HD44780_PIN_CLK);
    xSPinTypeSPI(HD44780_MOSI,HD44780_PIN_MOSI);
    xGPIOSPinTypeGPIOOutput(HD44780_PIN_CS);

    //
    // Configure SPI  SPI1,ulRate
    //
    xSPIConfigSet((HD44780_SPI), HD44780_SPI_BAUDRATE,
    	SPI_FORMAT_MODE_3 | SPI_DATA_WIDTH8 | SPI_MSB_FIRST | SPI_MODE_MASTER);

    //
    //! \note Enanble SPI SS,test on M0516LBN.other mcu there may need modify.
    //
    xSPISSSet((HD44780_SPI), xSPI_SS_SOFTWARE, xSPI_SS0);
    xSPIEnable(HD44780_SPI);
#else
    //
    // Set Pins Type to GPIO Output
    //

    xGPIOSPinTypeGPIOOutput(HD44780_PIN_CS);
    xGPIOSPinTypeGPIOOutput(HD44780_PIN_CLK);
    xGPIOSPinTypeGPIOOutput(HD44780_PIN_MOSI);
#endif

    //
    // Output default value : E disable
    //

    //
    // Set Entry Mode: Interface Data Length, Character Font, Display Line
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_FUNCTION_SET(HD44780_INTERFACE_DATA_LEN |
                                             HD44780_FUNCTION_SET_N_2 |
                                             HD44780_CHARACTER_FONT));

    //
    // Display on & Cursor Blink
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_DISPLAY_CTRL(HD44780_DISPLAY_CTRL_D |
                                             0 |
                                             HD44780_DISPLAY_CTRL_B));

    //
    // Clear LCD
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_CLS);

    //
    // Cursor Move Mode: Increment
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_ENTRY_MODE_SET(HD44780_ENTRY_MODE_SET_ID_INC |
                                               0));
    
}