Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: EXAMPLE_Nucleo_InternalTempSensor EXAMPLE_Nucleo_mbed_RTOS_test_code TEST_Dist_lib
Fork of TextLCD by
Revision 9:43c7f34925ac, committed 2015-12-12
- Comitter:
- dzoni
- Date:
- Sat Dec 12 20:14:52 2015 +0000
- Parent:
- 8:308d188a2d3a
- Commit message:
- 1. Optimization: change from wait(float) to wait_us(int)
Changed in this revision
| TextLCD.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/TextLCD.cpp Thu Jan 02 21:07:01 2014 +0000
+++ b/TextLCD.cpp Sat Dec 12 20:14:52 2015 +0000
@@ -23,6 +23,10 @@
#include "TextLCD.h"
#include "mbed.h"
+#define TIME_WAIT_POWER_UP_US (150000) // Time to ensure reliable power-up (150 ms)
+#define TIME_WAIT_1_64_MS_US (1640) // Time 1.64 ms for duration of a command
+#define TIME_WAIT_40_US (40) // Time 40 us for duration of a command
+
TextLCD::TextLCD(PinName rs, PinName e, PinName d4, PinName d5,
PinName d6, PinName d7, LCDType type) : _rs(rs),
_e(e), _d(d4, d5, d6, d7),
@@ -31,15 +35,15 @@
_e = 1;
_rs = 0; // command mode
- wait(0.015); // Wait 15ms to ensure powered up
+ wait_us(TIME_WAIT_POWER_UP_US); // Wait to ensure powered up
// send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
for (int i=0; i<3; i++) {
writeByte(0x3);
- wait(0.00164); // this command takes 1.64ms, so wait for it
+ wait_us(TIME_WAIT_1_64_MS_US); // this command takes 1.64ms, so wait for it
}
- writeByte(0x2); // 4-bit mode
- wait(0.000040f); // most instructions take 40us
+ writeByte(0x2); // 4-bit mode
+ wait_us(TIME_WAIT_40_US); // most instructions take 40us
writeCommand(0x28); // Function set 001 BW N F - -
writeCommand(0x0C);
@@ -55,7 +59,7 @@
void TextLCD::cls() {
writeCommand(0x01); // cls, and set cursor to 0
- wait(0.00164f); // This command takes 1.64 ms
+ wait_us(TIME_WAIT_1_64_MS_US); // This command takes 1.64 ms
locate(0, 0);
}
@@ -91,14 +95,14 @@
void TextLCD::writeByte(int value) {
_d = value >> 4;
- wait(0.000040f); // most instructions take 40us
+ wait_us(TIME_WAIT_40_US); // most instructions take 40us
_e = 0;
- wait(0.000040f);
+ wait_us(TIME_WAIT_40_US); // most instructions take 40us
_e = 1;
_d = value >> 0;
- wait(0.000040f);
+ wait_us(TIME_WAIT_40_US); // most instructions take 40us
_e = 0;
- wait(0.000040f); // most instructions take 40us
+ wait_us(TIME_WAIT_40_US); // most instructions take 40us
_e = 1;
}
