Example #1
0
/**
 * Writes a raw instruction to the LCD. 
 * @param command The 4-bit instruction code.
 * @param data The 8-bit paramater/data to the specified instruction.
 */
void lcd_write_command(unsigned char command, unsigned char data) {
	/* Wait for the busy flag to clear */
	lcd_wait_busy();
	
	/* Set Enable low, RW low, RS high to write the instruction command */
	lcd_enable_low();
	lcd_rw_low();
	lcd_rs_high();
	__asm("nop;"); __asm("nop;"); __asm("nop;");
	__asm("nop;"); __asm("nop;"); __asm("nop;");
	__asm("nop;"); __asm("nop;"); __asm("nop;");
	/* Instruction commands are a maximum of 4 bits long, so 
	 * just mask off the rest. */
	LCD_DATA_PORT = (command&0x0F);
	lcd_enable_high();
	__asm("nop;"); __asm("nop;"); __asm("nop;");
	__asm("nop;"); __asm("nop;"); __asm("nop;");
	__asm("nop;"); __asm("nop;"); __asm("nop;");

	/* Set RW low, RW low to write the instruction data */
	lcd_rw_low();
	lcd_rs_low();
	LCD_DATA_PORT = data;
	__asm("nop;"); __asm("nop;"); __asm("nop;");
	__asm("nop;"); __asm("nop;"); __asm("nop;");
	lcd_strobe_enable();
	__asm("nop;"); __asm("nop;"); __asm("nop;");
	__asm("nop;"); __asm("nop;"); __asm("nop;");
}
// display clear
void lcd_clrscr () {
  clear_all_pin ();
  toggle_e_pin ();
  SET_BIT (LCD_DATA_PORT, LCD_DATA4_PIN);
  toggle_e_pin ();
  lcd_wait_busy ();
}
// return home
void lcd_return_home () {
  clear_all_pin ();
  toggle_e_pin ();
  SET_BIT (LCD_DATA_PORT, LCD_DATA5_PIN);
  toggle_e_pin ();
  lcd_wait_busy ();
}
void lcd_put_char (char c) {
  clear_all_pin ();
  SET_BIT (LCD_CTL_PORT, LCD_RS_PIN);

  send_data (c);

  lcd_wait_busy ();
}
void lcd_init () {
  _delay_ms (50);

  // set all data pin to output
  SET_BIT(LCD_DATA_DDR, LCD_DATA4_PIN);
  SET_BIT(LCD_DATA_DDR, LCD_DATA5_PIN);
  SET_BIT(LCD_DATA_DDR, LCD_DATA6_PIN);
  SET_BIT(LCD_DATA_DDR, LCD_DATA7_PIN);

  // set all control pin to output
  SET_BIT(LCD_CTL_DDR, LCD_RS_PIN);
  SET_BIT(LCD_CTL_DDR, LCD_RW_PIN);
  SET_BIT(LCD_CTL_DDR, LCD_E_PIN);

  clear_all_pin ();

  // function set
  SET_BIT(LCD_DATA_PORT, LCD_DATA5_PIN);
  SET_BIT(LCD_DATA_PORT, LCD_DATA4_PIN);
  toggle_e_pin ();
  _delay_ms (5);
  toggle_e_pin ();
  _delay_us (200);
  toggle_e_pin ();
  _delay_ms (10);
  // set to 4-bit interface
  CLEAR_BIT(LCD_DATA_PORT, LCD_DATA4_PIN);
  toggle_e_pin ();
  _delay_ms (1);

  // set number of display line (N) and charactor font (F)
  toggle_e_pin ();
  SET_BIT(LCD_DATA_PORT, LCD_DATA7_PIN);
  toggle_e_pin ();
  _delay_ms (1);

  // display on/off control
  clear_all_pin ();
  toggle_e_pin ();
  SET_BIT (LCD_DATA_PORT, LCD_DATA7_PIN);
  SET_BIT (LCD_DATA_PORT, LCD_DATA6_PIN);
  toggle_e_pin ();

  lcd_wait_busy ();

  lcd_clrscr ();

  // entry mode set
  clear_all_pin ();
  toggle_e_pin ();
  SET_BIT (LCD_DATA_PORT, LCD_DATA6_PIN);
  SET_BIT (LCD_DATA_PORT, LCD_DATA5_PIN);
  toggle_e_pin ();
}
// go to position (x, y)
void lcd_goto_xy (uint8_t x, uint8_t y) {
  uint8_t addr;
  if (y == 0) {
    addr = x;
  } else {
    addr = 0x40 + x;
  }
  clear_all_pin ();
  SET_BIT (LCD_DATA_PORT, LCD_DATA7_PIN);
  send_data (addr | 0x80);
  lcd_wait_busy ();
}
Example #7
0
void lcd_write_data(unsigned char db)
{/*        液晶写数据函数

参数: 数据代码
返回: 空
调用: lcd_wait_busy()

说明:
        RS置位、RW置零,EA下降沿写入指令
*/
        lcd_wait_busy();
        LCD_RS=1;
        LCD_RW=0;
        LCD_EA=1;
        LCD_DB_BUS =db;
        LCD_EA=0;
		_nop_();
		_nop_();
        LCD_DB_BUS =0xff;
}
Example #8
0
void lcd_write_cmd(unsigned char cmd)
{/*        液晶写指令函数

参数: 指令代码
调用: lcd_wait_busy()

说明:
        RS、RW置零,EA下降沿写入指令
*/
        lcd_wait_busy();
        LCD_RS=0;
        LCD_RW=0;
        LCD_EA=1;
        LCD_DB_BUS =cmd;
        LCD_EA=0;
		_nop_();
		_nop_();
        LCD_DB_BUS =0xff;

}
void lcd_entry_mode_set (uint8_t mode) {
  clear_all_pin ();
  send_data (mode | 4);
  lcd_wait_busy ();
}
Example #10
0
void lcd_on_off_set (uint8_t mode) {
  clear_all_pin ();
  send_data (mode | 0x08);
  lcd_wait_busy ();
}