Exemplo n.º 1
0
/*************************************************************************
Low-level function to read byte from LCD controller
Input:    rs     1: read data    
                 0: read busy flag / address counter
Returns:  byte read from LCD controller
*************************************************************************/
static uint8_t lcd_read(uint8_t rs) 
{
    uint8_t data;
    if (rs) /* write data        (RS=1, RW=0) */
        dataport |= _BV(LCD_RS_PIN);
    else /* write instruction (RS=0, RW=0) */
        dataport &= ~_BV(LCD_RS_PIN);
    dataport |= _BV(LCD_RW_PIN);

    dataport |= _BV(LCD_E_PIN);
    pcf8574_setoutput(LCD_PCF8574_DEVICEID, dataport);   

    lcd_e_delay(); 

    data = pcf8574_getinputpin(LCD_PCF8574_DEVICEID, LCD_DATA0_PIN) << 4;     /* read high nibble first */
    dataport &= ~_BV(LCD_E_PIN);
    pcf8574_setoutput(LCD_PCF8574_DEVICEID, dataport);

    lcd_e_delay();                       /* Enable 500ns low       */

    dataport |= _BV(LCD_E_PIN);
    pcf8574_setoutput(LCD_PCF8574_DEVICEID, dataport);   

    data |= pcf8574_getinputpin(LCD_PCF8574_DEVICEID, LCD_DATA0_PIN) &0x0F;    /* read low nibble        */

    lcd_e_delay();

    dataport |= _BV(LCD_E_PIN);
    pcf8574_setoutput(LCD_PCF8574_DEVICEID, dataport);

    lcd_e_delay();

    return data;
}
Exemplo n.º 2
0
uint8_t lcd_read(uint8_t rs) {
    __IO uint8_t data;

    if(rs) { //read data
        lcd_rs_high();
    } else { //read busy flag
        lcd_rs_low();
    }
    lcd_rw_high(); // read mode

    //set data pins to input
    GPIO_InitStructure.GPIO_Pin = DATA_PORT_Pin_0 | DATA_PORT_Pin_1 |
                                  DATA_PORT_Pin_2 | DATA_PORT_Pin_3;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_Init(LCD_PORT, &GPIO_InitStructure);

    //read 2 nibbles
    lcd_e_high(); //enable
    lcd_e_delay();
    data = (uint8_t)GPIO_ReadInputData(LCD_PORT) << 4;
    lcd_e_low(); //disable

    lcd_e_delay();

    lcd_e_high(); //enable
    lcd_e_delay();
    data |= (uint8_t)GPIO_ReadInputData(LCD_PORT) & 0x0F;
    lcd_e_low(); //disable

    return data;
}
Exemplo n.º 3
0
void lcd_e_toggle() {
    lcd_e_low();
    lcd_e_delay();
    lcd_e_high();
    lcd_e_delay();
    lcd_e_low();
    Delay(100);
}
Exemplo n.º 4
0
/* toggle Enable Pin to initiate write */
static void toggle_e(void)
{
    pcf8574_setoutput(LCD_PCF8574_DEVICEID, dataport);
    lcd_e_delay();
    dataport |= _BV(LCD_E_PIN);
    pcf8574_setoutput(LCD_PCF8574_DEVICEID, dataport);
//    pcf8574_setoutputpinhigh(LCD_PCF8574_DEVICEID, LCD_E_PIN);
    lcd_e_delay();
//    pcf8574_setoutputpinlow(LCD_PCF8574_DEVICEID, LCD_E_PIN);
    dataport &= ~_BV(LCD_E_PIN);
    pcf8574_setoutput(LCD_PCF8574_DEVICEID, dataport);
}