Esempio n. 1
0
/*************************************************************************
Display character at current cursor position
Input:    character to be displayed
Returns:  none
*************************************************************************/
void lcd_putc(char c)
{
    lcd_waitbusy();
    twi_lcd_buf[2] = TWI_LCD_PUTC;
    twi_lcd_buf[3] = c;
    lcd_waitbusy();
    TWI_Master_Transceive_Message(twi_lcd_buf,4);
}/* lcd_putc */
Esempio n. 2
0
static void lcd_wrdata(uint8_t data)
{
  /* Make sure that the LCD is available */

  lcd_waitbusy();

  /* Select DB0-15 as outputs (only DB-0-7 are actually used) */

  putreg16(0, PIC32MX_IOPORTE_TRIS);

  /* Set up to write the data */

  pic32mx_gpiowrite(GPIO_LCD_RS, true);    /* Select data */
  pic32mx_gpiowrite(GPIO_LCD_RW, false);   /* Select write */
  lcd_shortdelay(2);

  pic32mx_gpiowrite(GPIO_LCD_E, true);     /* Enable transfer */
  lcd_shortdelay(1);

  /* Write the data to the LCD */

  putreg16(data, PIC32MX_IOPORTE_PORT);    /* Write the data */
  lcd_shortdelay(1);
  pic32mx_gpiowrite(GPIO_LCD_E, false);
}
Esempio n. 3
0
/*************************************************************************
Send data byte to LCD controller
Input:   data to send to LCD controller, see HD44780 data sheet
Returns: none
*************************************************************************/
void lcd_data(uint8_t data)
{
    twi_lcd_buf[2] = TWI_LCD_DATA;
    twi_lcd_buf[3] = data;
    lcd_waitbusy();
    TWI_Master_Transceive_Message(twi_lcd_buf,4);
}
Esempio n. 4
0
/*************************************************************************
Send LCD controller instruction command
Input:   instruction to send to LCD controller, see HD44780 data sheet
Returns: none
*************************************************************************/
void lcd_command(uint8_t cmd)
{
    twi_lcd_buf[2] = TWI_LCD_COMMAND;
    twi_lcd_buf[3] = cmd;
    lcd_waitbusy();
    TWI_Master_Transceive_Message(twi_lcd_buf,4);
}
Esempio n. 5
0
/*************************************************************************
Initialize display and select type of cursor
Input:    dispAttr LCD_DISP_OFF            display off
                   LCD_DISP_ON             display on, cursor off
                   LCD_DISP_ON_CURSOR      display on, cursor on
                   LCD_DISP_CURSOR_BLINK   display on, cursor on flashing
Returns:  none
*************************************************************************/
void lcd_init(uint8_t dispAttr)
{
    lcd_waitbusy();
    twi_lcd_buf[2] = TWI_LCD_INIT;
    twi_lcd_buf[3] = dispAttr;
    TWI_Master_Transceive_Message(twi_lcd_buf,4);
}/* lcd_init */
Esempio n. 6
0
/*************************************************************************
Display character at current cursor position
Input:    character to be displayed
Returns:  none
*************************************************************************/
void lcd_putc(char c)
{
    __IO uint8_t pos;


    pos = lcd_waitbusy();   // read busy-flag and address counter
    if (c=='\n')
    {
        lcd_newline(pos);
    }
    else
    {
        if ( pos == LCD_START_LINE1+LCD_DISP_LENGTH ) {
            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE2,0);
        } else if ( pos == LCD_START_LINE2+LCD_DISP_LENGTH ) {
            lcd_write((1<<LCD_DDRAM)+LCD_START_LINE1,0);
        }
        lcd_waitbusy();
        lcd_write(c, 1);
    }

}/* lcd_putc */
Esempio n. 7
0
/*************************************************************************
Display string without auto linefeed
Input:    string to be displayed
Returns:  none
*************************************************************************/
void lcd_puts(const char *s)
/* print string on lcd (no auto linefeed) */
{
    register char c;
    uint8_t i = 3;

    twi_lcd_buf[2] = TWI_LCD_PUTS;
    while ( (c = *s++) )
        twi_lcd_buf[i++] = c;

    twi_lcd_buf[i++] = 0;
    lcd_waitbusy();
    TWI_Master_Transceive_Message(twi_lcd_buf,i);
}/* lcd_puts */
Esempio n. 8
0
/*************************************************************************
Display string from program memory without auto linefeed
Input:     string from program memory be be displayed
Returns:   none
*************************************************************************/
void lcd_puts_p(const char *progmem_s)
/* print string from program memory on lcd (no auto linefeed) */
{
    register char c;
    uint8_t i = 3;

    twi_lcd_buf[2] = TWI_LCD_PUTS;
    while ( (c = pgm_read_byte(progmem_s++)) )
    {
        twi_lcd_buf[i++] = c;
    }
    twi_lcd_buf[i++] = 0;
    lcd_waitbusy();
    TWI_Master_Transceive_Message(twi_lcd_buf,i);

}/* lcd_puts_p */
Esempio n. 9
0
static uint8_t lcd_rddata(void)
{
  /* Make sure that the LCD is available */

  lcd_waitbusy();

  /* Setup to read data */

  pic32mx_gpiowrite(GPIO_LCD_RS, true);    /* Select data */
  pic32mx_gpiowrite(GPIO_LCD_RW, true);    /* Select read */
  lcd_shortdelay(2);

  pic32mx_gpiowrite(GPIO_LCD_E, true);     /* Enable transfer */
  lcd_shortdelay(1);

  putreg16(0xff, PIC32MX_IOPORTE_TRISSET); /* Set DB0-7 as inputs */
  pic32mx_gpiowrite(GPIO_LCD_E, false);    /* Disable transfer */

  /* Read the data from the LCD */

  return (uint8_t)getreg16(PIC32MX_IOPORTE_PORT);
}
Esempio n. 10
0
// rs = TRUE to write data, FALSE to write to command
static void lcd_write(const HD44780* device,uint8_t data,boolean rs){

    lcd_waitbusy(device);

    pin_set(device->ctrlRS, rs);
    pin_low(device->ctrlRW);		// write mode

	/* configure data pins as output */
    databus_output(device);

    if(device->fourBit){
    	// High nibble first
    	writeNibble(device,data>>4,4);
    	toggle_e(device);
    	// Low nibble last
    	writeNibble(device,data,4);
    	toggle_e(device);

    	/* all data pins high (inactive) */
    	for(uint8_t pin=4; pin<8; pin++){
    		pin_high(device->data[pin]);
    	}
    }else{
Esempio n. 11
0
int lcd_getxy(void)
{
    return lcd_waitbusy();
}
Esempio n. 12
0
/*************************************************************************
Send data byte to LCD controller
Input:   data to send to LCD controller, see HD44780 data sheet
Returns: none
*************************************************************************/
void lcd_data(uint8_t data)
{
    lcd_waitbusy();
    lcd_write(data,1);
}
Esempio n. 13
0
void lcd_command(uint8_t cmd)
{
    lcd_waitbusy();
    lcd_write(cmd,0);
    Delay(1000);
}
Esempio n. 14
0
int up_lcd1602_initialize(void)
{
  int ret = OK;

  /* Only initialize the driver once. */

  if (!g_lcd1602.initialized)
    {
      lcdinfo("Initializing\n");

      /* Configure GPIO pins */

      putreg16(0, PIC32MX_IOPORTE_TRIS);       /* Set DB0-15 as outputs */
      pic32mx_configgpio(GPIO_LCD_RS);         /* RS: Selects commnand or data */
      pic32mx_configgpio(GPIO_LCD_RW);         /* RW: Selects read or write */
      pic32mx_configgpio(GPIO_LCD_E);          /* E:  Starts transfer */

      /* Configure LCD power in the OFF state */

      pic32mx_configgpio(GPIO_LCD_LIGHT);       /* K */
      pic32mx_configgpio(GPIO_LCD_COMP);        /* Vo */
      pic32mx_configgpio(GPIO_LCD_PWR);         /* Vbuson/AN5/RB5 controls +5V USB */
      g_lcd1602.brightness = 0;                 /* Remember tht the light is off */

      /* A small delay is necessary between when GPIO_LCD_E was set up as an
       * output with initial value of 0 and this operation.  That delay should
       * be well covered by the intervening GPIO configurations.
       */

      pic32mx_gpiowrite(GPIO_LCD_E, true);     /* Enable transfer */

      /* Configure and enable the LCD */
      /* Delay for 4.1MS or more */

      up_mdelay(5);

      /* Select the 8-bit interface. BF cannot be checked before this command.
       * This needs to be done a few times with some magic delays.
       *
       * Function set: 5x7 Style | N=2R | DL=8D
       */

      lcd_wrcommand(HD4478OU_FUNC | HD4478OU_FUNC_F5x7 | HD4478OU_FUNC_N1 | HD4478OU_FUNC_DL8D);
      up_udelay(100);            /* Delay more than 100uS */

      lcd_wrcommand(HD4478OU_FUNC | HD4478OU_FUNC_F5x7 | HD4478OU_FUNC_N1 | HD4478OU_FUNC_DL8D);
      up_udelay(40);             /* Delay more than 40uS */
      lcd_wrcommand(HD4478OU_FUNC | HD4478OU_FUNC_F5x7 | HD4478OU_FUNC_N1 | HD4478OU_FUNC_DL8D);
      lcd_waitbusy();

      lcd_wrcommand(HD4478OU_FUNC | HD4478OU_FUNC_F5x7 | HD4478OU_FUNC_N1 | HD4478OU_FUNC_DL8D);
      lcd_waitbusy();

      /* Display ON, cursor OFF, blink OFF */

      lcd_wrcommand(HD4478OU_DISPLAY | HD4478OU_DISPLAY_ON);
      lcd_waitbusy();

      /* Clear the display and home the cursor */

      lcd_wrcommand(HD4478OU_CLEAR); /* Clear display */
      lcd_waitbusy();

      lcd_wrcommand(HD4478OU_RETURN); /* Return home: AC=0 */
      lcd_waitbusy();

      /* Entry Mode Set:
       *
       * - Increment address by one,
       * - Shift cursor to right (display is not shifted)
       */

      lcd_wrcommand(HD4478OU_INPUT | HD4478OU_INPUT_INCR);

      /* Register the LCD device driver */

      ret = register_driver("/dev/lcd1602", &g_lcdops, 0644, &g_lcd1602);
      g_lcd1602.initialized = true;
    }

  return ret;
}
Esempio n. 15
0
/*************************************************************************
  Low-level function to write byte to LCD controller
Input:    data   byte to write to LCD
rs     1: write data
0: write instruction
Returns:  none
 *************************************************************************/
static void lcd_write(uint8_t data,uint8_t rs)
{
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
	lcd_waitbusy();
	if (PrevCmdInvolvedAddressCounter)
	{
		Delay_us(5);
		PrevCmdInvolvedAddressCounter=0;
	}
#endif

	if (rs)
	{
		lcd_rs_port_high();                            // RS=1: Write Character
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
		PrevCmdInvolvedAddressCounter=1;
#endif
	}
	else
	{
		lcd_rs_port_low();                          // RS=0: Write Command
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
		PrevCmdInvolvedAddressCounter=0;
#endif
	}

#if LCD_BITS==4
	lcd_db7_port_set(data&_BV(7));                  //Output High Nibble
	lcd_db6_port_set(data&_BV(6));
	lcd_db5_port_set(data&_BV(5));
	lcd_db4_port_set(data&_BV(4));

	Delay_ns(100);
	lcd_e_port_high();

	Delay_ns(500);
	lcd_e_port_low();

	lcd_db7_port_set(data&_BV(3));                  //Output High Nibble
	lcd_db6_port_set(data&_BV(2));
	lcd_db5_port_set(data&_BV(1));
	lcd_db4_port_set(data&_BV(0));

	Delay_ns(100);
	lcd_e_port_high();

	Delay_ns(500);
	lcd_e_port_low();

	lcd_db7_port_high();                            // All Data Pins High (Inactive)
	lcd_db6_port_high();
	lcd_db5_port_high();
	lcd_db4_port_high();

#else //using 8-Bit_Mode
	lcd_db7_port_set(data&_BV(7));                  //Output High Nibble
	lcd_db6_port_set(data&_BV(6));
	lcd_db5_port_set(data&_BV(5));
	lcd_db4_port_set(data&_BV(4));
	lcd_db3_port_set(data&_BV(3));                  //Output High Nibble
	lcd_db2_port_set(data&_BV(2));
	lcd_db1_port_set(data&_BV(1));
	lcd_db0_port_set(data&_BV(0));

	Delay_ns(100);
	lcd_e_port_high();
	Delay_ns(500);
	lcd_e_port_low();

	lcd_db7_port_high();                            // All Data Pins High (Inactive)
	lcd_db6_port_high();
	lcd_db5_port_high();
	lcd_db4_port_high();
	lcd_db3_port_high();
	lcd_db2_port_high();
	lcd_db1_port_high();
	lcd_db0_port_high();
#endif

#if (WAIT_MODE==0 || RW_LINE_IMPLEMENTED==0)
	if (!rs && data<=((1<<LCD_CLR) | (1<<LCD_HOME))) // Is command clrscr or home?
		Delay_us(1640);
	else Delay_us(40);
#endif
}
Esempio n. 16
0
static uint8_t lcd_read(uint8_t rs)
{
	uint8_t data;

#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
	if (rs)
		lcd_waitbusy();
	if (PrevCmdInvolvedAddressCounter)
	{
		Delay_us(5);
		PrevCmdInvolvedAddressCounter=0;
	}
#endif

	if (rs)
	{
		lcd_rs_port_high();                             // RS=1: Read Data
#if (WAIT_MODE==1 && RW_LINE_IMPLEMENTED==1)
		PrevCmdInvolvedAddressCounter=1;
#endif
	}
	else lcd_rs_port_low();                           // RS=0: Read Busy Flag


	lcd_rw_port_high();                               // RW=1: Read Mode

#if LCD_BITS==4
	lcd_db7_ddr_low();                              // Configure Data Pins as Input
	lcd_db6_ddr_low();
	lcd_db5_ddr_low();
	lcd_db4_ddr_low();

	lcd_e_port_high();                              // Read High Nibble First
	Delay_ns(500);

	data=lcd_db4_pin_get() << 4 | lcd_db5_pin_get() << 5 |
		lcd_db6_pin_get() << 6 | lcd_db7_pin_get() << 7;

	lcd_e_port_low();
	Delay_ns(500);

	lcd_e_port_high();                              // Read Low Nibble
	Delay_ns(500);

	data|=lcd_db4_pin_get() << 0 | lcd_db5_pin_get() << 1 |
		lcd_db6_pin_get() << 2 | lcd_db7_pin_get() << 3;

	lcd_e_port_low();

	lcd_db7_ddr_high();                             // Configure Data Pins as Output
	lcd_db6_ddr_high();
	lcd_db5_ddr_high();
	lcd_db4_ddr_high();

	lcd_db7_port_high();                            // Pins High (Inactive)
	lcd_db6_port_high();
	lcd_db5_port_high();
	lcd_db4_port_high();
#else //using 8-Bit-Mode
	lcd_db7_ddr_low();                              // Configure Data Pins as Input
	lcd_db6_ddr_low();
	lcd_db5_ddr_low();
	lcd_db4_ddr_low();
	lcd_db3_ddr_low();
	lcd_db2_ddr_low();
	lcd_db1_ddr_low();
	lcd_db0_ddr_low();

	lcd_e_port_high();
	Delay_ns(500);

	data=lcd_db7_pin_get() << 7 | lcd_db6_pin_get() << 6 |
		lcd_db5_pin_get() << 5 | lcd_db4_pin_get() << 4 |
		lcd_db3_pin_get() << 3 | lcd_db2_pin_get() << 2 |
		lcd_db1_pin_get() << 1 | lcd_db0_pin_get();

	lcd_e_port_low();

	lcd_db7_ddr_high();                             // Configure Data Pins as Output
	lcd_db6_ddr_high();
	lcd_db5_ddr_high();
	lcd_db4_ddr_high();
	lcd_db3_ddr_high();
	lcd_db2_ddr_high();
	lcd_db1_ddr_high();
	lcd_db0_ddr_high();

	lcd_db7_port_high();                            // Pins High (Inactive)
	lcd_db6_port_high();
	lcd_db5_port_high();
	lcd_db4_port_high();
	lcd_db3_port_high();
	lcd_db2_port_high();
	lcd_db1_port_high();
	lcd_db0_port_high();
#endif

	lcd_rw_port_low();

#if (WAIT_MODE==0 || RW_LINE_IMPLEMENTED==0)
	if (rs)
		Delay_us(40);
	else Delay_us(1);
#endif
	return data;
}