/* * description: clear the display on the LCD */ static void lcd_clearDisplay() { lcd_instruction( 0x00 ); // upper 4 bits of command lcd_instruction( 0x10 ); // lower 4 bits of command printk(KERN_INFO "klcd Driver: display clear\n"); }
/* * description: turn off the LCD display. It is called upon module exit */ static void lcd_display_off(void) { lcd_instruction(0x00); // Instruction 0000b lcd_instruction(0x80); /* Instruction 1DCBb Set D= 0, or Display off Set C= 0, or Cursor off Set B= 0, or Blinking off */ printk(KERN_INFO "klcd Driver: lcd_display_off\n"); }
/* * description: hide a blinking cursor from the LCD screen */ static void lcd_cursor_off() { /* Display On/off Control */ lcd_instruction(0x00); // Instruction 0000b lcd_instruction(0xC0); /* Instruction 1DCBb Set D= 1, or Display on Set C= 0, or Cursor off Set B= 0, or Blinking off */ printk(KERN_INFO "klcd Driver: lcd_cursor_off\n"); }
// Reset, as per page 34 of 7920 data sheet void lcd_reset() { // Bring (PB0) low, then high PORTB &= ~0x01; _delay_ms(1); PORTB |= 0x01; _delay_ms(10); lcd_instruction(0b00110000); // 8 bit data, basic instructions lcd_instruction(0b00110000); // 8 bit data, basic instructions lcd_instruction(0b00001100); // d_buffer on lcd_clear(); lcd_instruction(0b00000110); // increment, no shift }
/* * description: set the cursor to the beginning of the line specified. * @param line line number should be either 1 or 2. */ void lcd_setLinePosition(unsigned int line) { if(line == 1) { lcd_instruction(0x80); // set position to LCD line 1 lcd_instruction(0x00); } else if(line == 2) { lcd_instruction(0xC0); lcd_instruction(0x00); } else { printk("ERR: Invalid line number. Select either 1 or 2 \n"); } }
/* * description: set the cursor to the nth character of the line specified. * @param line the line number should be either 1 or 2. * @param nthCharacter n'th character where the cursor should start on the line specified. * It starts from 0, which indicates the beginning of the line. */ void lcd_setPosition(unsigned int line, unsigned int nthCharacter) { char command; if(line == 1) { command = 0x80 + (char) nthCharacter; lcd_instruction( command & 0xF0 ); // upper 4 bits of command lcd_instruction( (command & 0x0F) << 4 ); // lower 4 bits of command } else if(line == 2) { command = 0xC0 + (char) nthCharacter; lcd_instruction( command & 0xF0 ); // upper 4 bits of command lcd_instruction( (command & 0x0F) << 4 ); // lower 4 bits of command } else { printk("ERR: Invalid line number. Select either 1 or 2 \n"); } }
/* * description: initialize the LCD in 4 bit mode as described on the HD44780 LCD controller document. */ static void lcd_initialize() { usleep_range(41*1000, 50*1000); // wait for more than 40 ms once the power is on lcd_instruction(0x30); // Instruction 0011b (Function set) usleep_range(5*1000, 6*1000); // wait for more than 4.1 ms lcd_instruction(0x30); // Instruction 0011b (Function set) usleep_range(100,200); // wait for more than 100 us lcd_instruction(0x30); // Instruction 0011b (Function set) usleep_range(100,200); // wait for more than 100 us lcd_instruction(0x20); /* Instruction 0010b (Function set) Set interface to be 4 bits long */ usleep_range(100,200); // wait for more than 100 us lcd_instruction(0x20); // Instruction 0010b (Function set) lcd_instruction(0x80); /* Instruction NF**b Set N = 1, or 2-line display Set F = 0, or 5x8 dot character font */ usleep_range(41*1000,50*1000); /* Display off */ lcd_instruction(0x00); // Instruction 0000b lcd_instruction(0x80); // Instruction 1000b usleep_range(100,200); /* Display clear */ lcd_instruction(0x00); // Instruction 0000b lcd_instruction(0x10); // Instruction 0001b usleep_range(100,200); /* Entry mode set */ lcd_instruction(0x00); // Instruction 0000b lcd_instruction(0x60); /* Instruction 01(I/D)Sb -> 0110b Set I/D = 1, or increment or decrement DDRAM address by 1 Set S = 0, or no display shift */ usleep_range(100,200); /* Initialization Completed, but set up default LCD setting here */ /* Display On/off Control */ lcd_instruction(0x00); // Instruction 0000b lcd_instruction(0xF0); /* Instruction 1DCBb Set D= 1, or Display on Set C= 1, or Cursor on Set B= 1, or Blinking on */ usleep_range(100,200); }
// Clears the text screen void lcd_clear() { lcd_instruction(0b00000001); // clear _delay_ms(2); // Needs 1.62ms delay }
void lcd_signed(unsigned char line, signed int value, char digits) { lcd_instruction(line); lcd_print(value, 10, SIGNED_ZEROS, digits); }
void lcd_hexidecimal(unsigned char line, unsigned int value, char digits) { lcd_instruction(line); lcd_print(value, 16, UNSIGNED_ZEROS, digits); }
void lcd_binary(unsigned char line, unsigned int value, char digits) { lcd_instruction(line); lcd_print(value, 2, UNSIGNED_ZEROS, digits); }