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: AkiSpiLcd_demo AkiSpiLcd_demo2 LCDRAM AkiSpiLcd_example
Revision 0:b3c8fdd01601, committed 2014-05-06
- Comitter:
- k4zuki
- Date:
- Tue May 06 17:07:34 2014 +0000
- Child:
- 1:57de84d2025c
- Commit message:
- some formatting fix
Changed in this revision
| AkiSpiLcd.cpp | Show annotated file Show diff for this revision Revisions of this file |
| AkiSpiLcd.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/AkiSpiLcd.cpp Tue May 06 17:07:34 2014 +0000
@@ -0,0 +1,139 @@
+/*
+this is for SHARP LCD LS027B4DH01
+by Kazuki Yamamoto, or _K4ZUKI_
+*/
+
+#include "mbed.h"
+#include "AkiSpiLcd.h"
+
+AkiSpiLcd::AkiSpiLcd(PinName mosi,PinName sck, PinName cs, PinName disp)
+ :_spi(mosi,NC,sck), _cs(cs), _disp(disp)
+{
+ _cs=0;
+ _spi.format(8,0);
+ _spi.frequency(2000000);
+ comflag = modeflag = clearflag = 0;
+ _disp=1;
+}
+
+void AkiSpiLcd::cls()
+{
+ modeflag=0;
+ clearflag=1;
+
+ _cs=1;
+ wait_us(5);
+
+ _spi.write( (modeflag << 7) | (comflag << 6) | (clearflag << 5) );
+ _spi.write(0x00);
+
+ wait_us(5);
+ _cs=0;
+
+ if(comflag == 0) {
+ comflag = 1;
+ } else {
+ comflag = 0;
+ }
+}
+
+void AkiSpiLcd::updateSingle(int line, uint8_t* data)
+{
+ modeflag=1;
+ clearflag=0;
+
+ _cs=1;
+ wait_us(5);
+
+ _spi.write( (modeflag << 7) | (comflag << 6) | (clearflag << 5) );
+ _spi.write(
+ ( ( (line+1) & 0x01 ) << 7 )|
+ ( ( (line+1) & 0x02 ) << 5 )|
+ ( ( (line+1) & 0x04 ) << 3 )|
+ ( ( (line+1) & 0x08 ) << 1 )|
+ ( ( (line+1) & 0x10 ) >> 1 )|
+ ( ( (line+1) & 0x20 ) >> 3 )|
+ ( ( (line+1) & 0x40 ) >> 5 )|
+ ( ( (line+1) & 0x80 ) >> 7 )
+ );
+
+ for(int i=0; i<50; i++) {
+ _spi.write( *(data+i) );
+ }
+ _spi.write(0x00);
+ _spi.write(0x00);
+
+ wait_us(5);
+ _cs=0;
+
+ if(comflag == 0) {
+ comflag = 1;
+ } else {
+ comflag = 0;
+ }
+}
+
+void AkiSpiLcd::updateMulti(int line, int length, uint8_t* data)
+{
+ modeflag=1;
+ clearflag=0;
+
+ if(length>0) {
+ _cs=1;
+ wait_us(5);
+ for (int j=0; j<length; j++) {
+ _spi.write( (modeflag << 7) | (comflag << 6) | (clearflag << 5) );
+ _spi.write(
+ ( ( (line+1) & 0x01 ) << 7 )|
+ ( ( (line+1) & 0x02 ) << 5 )|
+ ( ( (line+1) & 0x04 ) << 3 )|
+ ( ( (line+1) & 0x08 ) << 1 )|
+ ( ( (line+1) & 0x10 ) >> 1 )|
+ ( ( (line+1) & 0x20 ) >> 3 )|
+ ( ( (line+1) & 0x40 ) >> 5 )|
+ ( ( (line+1) & 0x80 ) >> 7 )
+ );
+
+ for(int i=0; i<50; i++) {
+ _spi.write( *(data+(50*j+i)) );//hogepic[50*j+i]
+ }
+ line+=1;
+ }
+ _spi.write(0x00);
+ _spi.write(0x00);
+ wait_us(5);
+ _cs=0;
+ }
+ if(comflag == 0) {
+ comflag = 1;
+ } else {
+ comflag = 0;
+ }
+}
+
+void AkiSpiLcd::cominvert()
+{
+ modeflag=0;
+ clearflag=0;
+
+ _cs=1;
+
+ _spi.write( (modeflag << 7) | (comflag << 6) | (clearflag << 5) );
+ _spi.write(0x00);
+ wait_us(5);
+ _cs=0;
+ if(comflag == 0) {
+ comflag = 1;
+ } else {
+ comflag = 0;
+ }
+}
+
+void AkiSpiLcd::dispOn(bool disp)
+{
+ if(disp) {
+ _disp=1;
+ } else {
+ _disp=0;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/AkiSpiLcd.h Tue May 06 17:07:34 2014 +0000
@@ -0,0 +1,55 @@
+/*
+this is for SHARP LCD LS027B4DH01
+by Kazuki Yamamoto, or _K4ZUKI_
+*/
+
+#ifndef __AKISPILCD_H__
+#define __AKISPILCD_H
+//#include "mbed.h"
+
+class AkiSpiLcd
+{
+public:
+ /** Constructor
+ * @param mosi SPI data input
+ * @param sck SPI clock input
+ * @param cs HIGH-active chip enable input
+ * @param disp HIGH-active display enable input
+ */
+ AkiSpiLcd(PinName mosi,PinName sck, PinName cs, PinName disp);
+
+ /** Clear screen
+ */
+ void cls();
+
+ /** Writes single line(400 bits = 50 bytes)
+ * @param line line number(1-240)
+ * @param *data pointer to data
+ */
+ void updateSingle(int line, uint8_t* data);
+
+ /** Writes multi lines(400 x N bits = 50 x N bytes)
+ * @param line line number(1-240)
+ * @param length number of line to write
+ * @param *data pointer to data
+ */
+ void updateMulti(int line, int length, uint8_t* data);
+
+ /** Inverting internal COM signal
+ */
+ void cominvert();
+
+ /** Enables/disables display. internal memory will not flushed
+ * @param disp true = display is on / false = display is off
+ */
+ void dispOn(bool disp);
+
+private:
+ int comflag;
+ int modeflag;
+ int clearflag;
+ SPI _spi;
+ DigitalOut _cs;
+ DigitalOut _disp;
+};
+#endif
