Example #1
0
/**
 * Initializes the LCD in graphics mode.
 * Uses a character pitch of 8 (8 bits are plotted whenever a byte is drawn)
 */ 
void lcd_graphics_init(void) {
	unsigned char commandData;

	/* Set the data direction registers apprioriately */
	LCD_DATA_DDR = 0xFF;
	LCD_CTRL_DDR |= (1<<LCD_CTRL_RS)|(1<<LCD_CTRL_RW)|(1<<LCD_CTRL_E);

	/* Assert all control lines to low */
	lcd_rw_low();
	lcd_rs_low();
	lcd_enable_low();

	/* Send mode configuration command with
	 * Toggle Display On, Master, Mode Graphics bits set */
	commandData = LCD_MODE_ON_OFF | LCD_MODE_MASTER_SLAVE | LCD_MODE_MODE;
	lcd_write_command(LCD_CMD_MODE, commandData);

	/* Send the set character pitch command with horizontal
 	 * character pitch of 8 (so 8 pixels are painted when we draw) */	
	commandData = LCD_CHAR_PITCH_HP_8;
	lcd_write_command(LCD_CMD_CHAR_PITCH, commandData);
	
	/* Send the number of characters command with the total
	 * number of graphics bytes that can be painted horizontally 
	 * (width/8) */
	commandData = (LCD_WIDTH/8)-1;
	lcd_write_command(LCD_CMD_NUM_CHARS, commandData);

	/* Set the time division */
	commandData = 128-1;
	lcd_write_command(LCD_CMD_TIME_DIVISION, commandData);
	
	/* Set the display low/high start address to 0x00 (left corner) */
	commandData = 0x00;
	lcd_write_command(LCD_CMD_DISPLAY_START_LA, commandData);
	lcd_write_command(LCD_CMD_DISPLAY_START_HA, commandData);

	/* Reset the cursor to home 0x00 (left corner) */
	commandData = 0x00;
	lcd_write_command(LCD_CMD_CURSOR_LA, commandData);
	lcd_write_command(LCD_CMD_CURSOR_HA, commandData);
}
Example #2
0
void lcd_write(uint8_t data, uint8_t rs) {
    __IO uint8_t outputdata;
    if(rs) { //write data
        lcd_rs_high();
    } else { //write instruction
        lcd_rs_low();
    }
    lcd_rw_low(); //set to write

    //set data pins to output
    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_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_Init(LCD_PORT, &GPIO_InitStructure);

    /**
     * Preserve the RS,RW,E bits in order to write out:
     * our data goe son the 4 most significant bits with
     * the high nibble output first.
     */

    outputdata = (uint8_t)GPIO_ReadOutputData(LCD_PORT);
    outputdata &= 0x05; //we're only interested in the lower bits (RS,RW,E)

    //output high nibble first
    GPIO_Write(LCD_PORT, outputdata | (data & 0xF0));
    //push data
    lcd_e_toggle();

    GPIO_Write(LCD_PORT, outputdata | ((data << 4) & 0xF0));
    //push data
    lcd_e_toggle();

    GPIO_Write(LCD_PORT, outputdata | 0xF0); //set pins high as inactive state
}