Basic library for SHARP LCD LS027B4DH01/LS027B7DH01
Dependents: AkiSpiLcd_demo AkiSpiLcd_demo2 LCDRAM AkiSpiLcd_example
Revision 10:eed99ef09e63, committed 2014-09-15
- Comitter:
- k4zuki
- Date:
- Mon Sep 15 14:12:33 2014 +0000
- Parent:
- 9:33d5888d1fb9
- Child:
- 11:16647ecd67ce
- Commit message:
- .
Changed in this revision
--- a/AkiSpiLcd.cpp Sun Sep 07 14:42:13 2014 +0000 +++ b/AkiSpiLcd.cpp Mon Sep 15 14:12:33 2014 +0000 @@ -4,7 +4,7 @@ #include "mbed.h" #include "AkiSpiLcd.h" -#include "Ser23K256.h" +//#include "Ser23K256.h" AkiSpiLcd::AkiSpiLcd(PinName mosi, PinName miso, PinName sck, PinName csl, PinName csr) :_spi(mosi, miso, sck), _csl(csl), _csr(csr) @@ -13,23 +13,24 @@ _csl=0; _csr=1; _spi.format(8,0); - _spi.frequency(1000000); + _spi.frequency(10000000); comflag = modeflag = clearflag = 0; - - int data=0; + + uint8_t data[240]; for(int i=0; i<240; i++) { - data=( ( i & 0x01 ) << 7 )| - ( ( i & 0x02 ) << 5 )| - ( ( i & 0x04 ) << 3 )| - ( ( i & 0x08 ) << 1 )| - ( ( i & 0x10 ) >> 1 )| - ( ( i & 0x20 ) >> 3 )| - ( ( i & 0x40 ) >> 5 )| - ( ( i & 0x80 ) >> 7 ); + data[i]=( ( (i+1) & 0x01 ) << 7 )| + ( ( (i+1) & 0x02 ) << 5 )| + ( ( (i+1) & 0x04 ) << 3 )| + ( ( (i+1) & 0x08 ) << 1 )| + ( ( (i+1) & 0x10 ) >> 1 )| + ( ( (i+1) & 0x20 ) >> 3 )| + ( ( (i+1) & 0x40 ) >> 5 )| + ( ( (i+1) & 0x80 ) >> 7 ); - ram_write(RAMLINE_BASE+i,(uint8_t)data); } - ram_write(RAMMODE_BASE,0x00000000,4); + ram_write(RAMLINE_BASE,data,240); + uint8_t buffer[4] = {0,0,0,0}; + ram_write(RAMMODE_BASE,buffer,4); } @@ -101,14 +102,14 @@ for (int j=0; j<length; j++) { _spi.write( (modeflag << 7) | (comflag << 6) | (clearflag << 5) ); _spi.write( - ( ( (line) & 0x01 ) << 7 )| - ( ( (line) & 0x02 ) << 5 )| - ( ( (line) & 0x04 ) << 3 )| - ( ( (line) & 0x08 ) << 1 )| - ( ( (line) & 0x10 ) >> 1 )| - ( ( (line) & 0x20 ) >> 3 )| - ( ( (line) & 0x40 ) >> 5 )| - ( ( (line) & 0x80 ) >> 7 ) + ( ( (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++) {
--- a/AkiSpiLcd.h Sun Sep 07 14:42:13 2014 +0000 +++ b/AkiSpiLcd.h Mon Sep 15 14:12:33 2014 +0000 @@ -19,7 +19,7 @@ * extern const uint8_t hogepic[]; * int main() * { - * + * * wait_ms(1); * LCD.cls(); * LCD.updateSingle(10,(uint8_t*)(hogepic+2000)); @@ -34,16 +34,39 @@ * } * @endcode */ -#define RAMLINE_BASE 0x6000 -#define RAMMODE_BASE 0x6100 -#define SCREEN0_BASE 0x0000 -#define SCREEN1_BASE 0x3000 + +//#define RAMLINE_BASE 0x6000 +//#define RAMMODE_BASE 0x6100 +//#define SCREEN0_BASE 0x0000 +//#define SCREEN1_BASE 0x3000 #define SCREEN0 0 #define SCREEN1 1 - + class AkiSpiLcd { public: + //! base address list for 23K256 + enum BASE_ADDR { + RAMLINE_BASE = 0x6000, + RAMMODE_BASE = 0x6100, + SCREEN0_BASE = 0x0000, + SCREEN1_BASE = 0x3000 + }; + + //! mode codes for 23K256 + enum MODE { + BYTE_MODE = 0x00, + SEQUENTIAL_MODE = 0x40 + }; + + //! command codes for 23K256 + enum COMMAND { + READ = 0x03, + WRITE = 0x02, + READ_STATUS = 0x05, // called RDSR in datasheet + WRITE_STATUS = 0x01 // called WRSR in datasheet + }; + /** Constructor * @param mosi SPI data input * @param mosi SPI data output @@ -73,7 +96,7 @@ /** Inverting internal COM signal */ void cominvert(); - + /** Reads single line (400 bits = 50 bytes) from a screen */ void ramReadSingle(int line, uint8_t* buffer, int screen); @@ -81,7 +104,7 @@ /** Reads multi lines(400 x N bits = 50 x N bytes) from a screen */ void ramReadMulti(int startline, int length, uint8_t* buffer, int screen); - + /** Writes single line (400 bits = 50 bytes) into a screen */ void ramWriteSingle(int line, uint8_t* data, int screen); @@ -89,7 +112,7 @@ /** Writes multi lines(400 x N bits = 50 x N bytes) into a screen */ void ramWriteMulti(int startline, int length, uint8_t* data, int screen); - + /** copies whole data in screen into LCD */ void ram2lcd(int startline, int length, int screen); @@ -99,27 +122,27 @@ // */ // void dispOn(bool disp); -/** read a byte from SRAM -* @param address The address to read from -* @return the uint8_tacter at that address -*/ + /** read a byte from SRAM + * @param address The address to read from + * @return the uint8_tacter at that address + */ uint8_t ram_read(int address); -/** read multiple bytes from SRAM into a buffer -* @param address The SRAM address to read from -* @param buffer The buffer to read into (must be big enough!) -* @param count The number of bytes to read -*/ + /** read multiple bytes from SRAM into a buffer + * @param address The SRAM address to read from + * @param buffer The buffer to read into (must be big enough!) + * @param count The number of bytes to read + */ void ram_read(int address, uint8_t * buffer, int count); -/** write a byte to SRAM -* @param address The address SRAM to write to -* @param byte The byte to write there -*/ + /** write a byte to SRAM + * @param address The address SRAM to write to + * @param byte The byte to write there + */ void ram_write(int address, uint8_t byte); /** write multiple bytes to SRAM from a buffer -* @param address The SRAM address write to -* @param buffer The buffer to write from -* @param count The number of bytes to write -*/ + * @param address The SRAM address write to + * @param buffer The buffer to write from + * @param count The number of bytes to write + */ void ram_write(int address, uint8_t * buffer, int count); private:
--- a/Ser23K256.lib Sun Sep 07 14:42:13 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/k4zuki/code/Ser23K256/#d8180cb9d9ab