Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/slow write speed and 20x4 lcd problems #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Building the advanced usage example: go to the directory example_backlight. Foll
![](img/blconnect.png)

## Release notes
26-jun-2024: speed up writes, fix character position for 4-line displays, add single char write function
4-mar-2021: added some useful methods to the library<br>
3 -mar-2021: Added backlight option<br>
27-feb-2021: First release
23 changes: 17 additions & 6 deletions lcd_display/lcd_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
uint32_t bit_value = pin_values_to_mask(raw_bits,5) ;
gpio_put_masked(this->LCDmask, bit_value) ;
gpio_put(this->LCDpins[E], HIGH) ;
sleep_ms(5) ;
sleep_us(50) ;
gpio_put(this->LCDpins[E], LOW) ; // gpio values on other pins are pushed at the HIGH->LOW change of the clock.
sleep_ms(5) ;
sleep_us(50) ;
};

void LCDdisplay::send_full_byte(uint rs, uint databits[]) { // RS + array of Bit7, ... , Bit0
Expand Down Expand Up @@ -155,7 +155,7 @@

//set LCD to 4-bit mode and 1 or 2 lines
//by sending a series of Set Function commands to secure the state and set to 4 bits
if (no_lines == 2) { set_function_4[4] = 1; };
if (no_lines == 2 || no_lines == 4) { set_function_4[4] = 1; };
send_raw_data_one_cycle(set_function_8);
send_raw_data_one_cycle(set_function_8);
send_raw_data_one_cycle(set_function_8);
Expand All @@ -181,10 +181,15 @@
case 2:
pos = 64*line+ pos + 0b10000000;
break ;
case 4: if (line == 0 || line == 2) {
pos = 64*(line/2) + pos + 0b10000000;
case 4:
if (line == 0) {
pos += 0x80;
} else if (line == 1) {
pos += 0x80 + 0x40;
} else if (line == 2) {
pos += 0x80 + 0x14;
} else {
pos = 64*((line-1)/2) + 20 + pos + 0b10000000;
pos += 0x80 + 0x54;
};
break;
default:
Expand All @@ -193,6 +198,12 @@
uint_into_8bits(eight_bits,pos);
send_full_byte(COMMAND,eight_bits);
};

void LCDdisplay::write(const char chr) {
uint eight_bits[8];
uint_into_8bits(eight_bits,(uint)(chr));
send_full_byte(DATA, eight_bits);
};

void LCDdisplay::print(const char * str) {
uint eight_bits[8];
Expand Down
4 changes: 4 additions & 0 deletions lcd_display/lcd_display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ class LCDdisplay {
void init() ;

void goto_pos(int pos, int line);

// Write a single character
void write(const char chr);

// Print a string
void print(const char * str);

void print_wrapped(const char * str);
Expand Down