I2C ディスプレイドライバー

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
tamir_azjargal
Date:
Fri Sep 16 05:48:02 2022 +0000
Commit message:
I2C Display Driver

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Sep 16 05:48:02 2022 +0000
@@ -0,0 +1,75 @@
+#include "mbed.h"
+
+I2C disp(PB_7, PB_6);
+
+const int addr = 0x3E;
+
+Serial pc(USBTX, USBRX, 9600);
+
+uint8_t startup[10] = {
+    0x38,
+    0x39,
+    0x14,
+    0x70,
+    0x54,
+    0x77,//contrast
+    0x6C,
+    0x38,
+    0x0F,
+    0x01
+};
+
+uint8_t message[16] = {
+    0xB1,
+    0xB2,
+    0xB3,
+    0xB4,
+    0xB5,
+    0xB6,
+    0xB7,
+    0xB8,
+    0xB9,
+    0xBA,
+    0xBB,
+    0xBC,
+    0xBD,
+    0xBE,
+    0xBF,
+    0xC0
+};
+
+
+DigitalOut LED(LED1);
+DigitalIn pa5(PA_5);
+DigitalIn pa6(PA_6);
+
+void commandWrite(uint8_t command)
+{
+    char package[2];
+    package[0] = 0x80;
+    package[1] = (char)command;
+    disp.write(addr << 1, (char *)package, 2);
+}
+
+void dataWrite(uint8_t data)
+{
+    char package[2];
+    package[0] = 0xC0;
+    package[1] = (char)data;
+    disp.write(addr << 1, (char *)package, 2);
+}
+
+int main()
+{
+    LED = 0;
+    disp.frequency(100000);
+    for(int i = 0; i < sizeof(startup); i++) {
+        commandWrite(*(startup + i));
+    }
+    wait_ms(10);
+    for(int i = 0; i < sizeof(message); i++) {
+        dataWrite(*(message + i));
+        if(i == 7) commandWrite(0xC0);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Sep 16 05:48:02 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file