├── LICENSE
├── README.md
├── ST7920_SPI.cpp
├── ST7920_SPI.h
├── examples
├── ST7920_lib_Bitmap
│ └── ST7920_lib_Bitmap.ino
├── ST7920_lib_Demo
│ └── ST7920_lib_Demo.ino
├── ST7920_lib_Dithering
│ └── ST7920_lib_Dithering.ino
├── ST7920_lib_DoubleBuffer
│ └── ST7920_lib_DoubleBuffer.ino
├── ST7920_lib_GraphicsMode
│ └── ST7920_lib_GraphicsMode.ino
├── ST7920_lib_HelloWorld
│ └── ST7920_lib_HelloWorld.ino
└── ST7920_lib_TextMode
│ └── ST7920_lib_TextMode.ino
└── keywords.txt
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ST7920_SPI
2 | ST7920 SPI 128x64 LCD library with frame buffer
3 |
4 | YouTube video:
5 | https://youtu.be/JAJcGKE-0k0
6 |
7 | ## Features
8 |
9 | - ST7920 text mode with built-in CGROM fonts (8x16 and 16x16)
10 | - graphics mode with 128x64 pixels frame buffer
11 | - proportional fonts in graphics mode
12 | - hardware doublebuffer
13 | - simple primitives
14 | - pixels
15 | - lines
16 | - rectangles
17 | - filled rectangles
18 | - circles
19 | - filled circles
20 | - fast ordered dithering (17 patterns)
21 | - ultra fast horizontal and vertical line drawing
22 | - bitmaps drawing
23 | - example programs
24 |
25 | ## Connections:
26 |
27 | |LCD pin|LCD pin name|Arduino|
28 | |--|--|--|
29 | |#01| GND| GND|
30 | |#02| VCC |VCC (5V)|
31 | |#04| RS | D10/CS or any pin|
32 | |#05| R/W| D11/MOSI|
33 | |#06| E | D13/SCK|
34 | |#15| PSB| GND (for SPI mode)|
35 | |#19| BLA | D9, VCC or any pin via 300ohm resistor|
36 | |#20| BLK | GND|
37 |
38 | If you find it useful and want to buy me a coffee or a beer:
39 |
40 | https://www.paypal.me/cbm80amiga
41 |
--------------------------------------------------------------------------------
/ST7920_SPI.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cbm80amiga/ST7920_SPI/fb1bf7b0b8212beb4e9cfca294e12b69fababac4/ST7920_SPI.cpp
--------------------------------------------------------------------------------
/ST7920_SPI.h:
--------------------------------------------------------------------------------
1 | // ST7920 128x64 LCD driver
2 | // 2019 by Pawel A. Hernik
3 |
4 | /*
5 | 128x64 ST7920 connections (SPI)
6 |
7 | #01 GND -> GND
8 | #02 VCC -> VCC (5V)
9 | #04 RS -> D10/CS or any pin
10 | #05 R/W -> D11/MOSI
11 | #06 E -> D13/SCK
12 | #15 PSB -> GND (for SPI mode)
13 | #19 BLA -> VCC or any pin via 300ohm
14 | #20 BLK -> GND
15 |
16 | */
17 |
18 | #ifndef _ST7920_SPI_H
19 | #define _ST7920_SPI_H
20 |
21 | #include
22 | #include
23 |
24 | // ST7920 Commands
25 |
26 | #define LCD_CLS 0x01
27 | #define LCD_HOME 0x02
28 | #define LCD_ADDRINC 0x06
29 | #define LCD_DISPLAYON 0x0C
30 | #define LCD_DISPLAYOFF 0x08
31 | #define LCD_CURSORON 0x0E
32 | #define LCD_CURSORBLINK 0x0F
33 | #define LCD_BASIC 0x30
34 | #define LCD_EXTEND 0x34
35 | #define LCD_GFXMODE 0x36
36 | #define LCD_TXTMODE 0x34
37 | #define LCD_STANDBY 0x01
38 | #define LCD_SCROLL 0x03
39 | #define LCD_SCROLLADDR 0x40
40 | #define LCD_ADDR 0x80
41 | #define LCD_LINE0 0x80
42 | #define LCD_LINE1 0x90
43 | #define LCD_LINE2 0x88
44 | #define LCD_LINE3 0x98
45 |
46 | #define SPI_SPEED (1000000UL)
47 |
48 | #ifndef SCR_WD
49 | #define SCR_WD 128
50 | #define SCR_HT 64
51 | #endif
52 |
53 | #define ALIGN_LEFT 0
54 | #define ALIGN_RIGHT -1
55 | #define ALIGN_CENTER -2
56 |
57 | struct _propFont
58 | {
59 | const uint8_t* font;
60 | int8_t xSize;
61 | uint8_t ySize;
62 | uint8_t firstCh;
63 | uint8_t lastCh;
64 | uint8_t minCharWd;
65 | uint8_t minDigitWd;
66 | };
67 |
68 | // ---------------------------------
69 | class ST7920_SPI {
70 | public:
71 | ST7920_SPI(byte cs);
72 |
73 | void init();
74 | void sendCmd(byte b);
75 | void sendData(byte b);
76 | void switchBuf(byte b);
77 | void display(int buf=0);
78 | void copy(uint8_t x16, uint8_t y, uint8_t w16, uint8_t h, uint8_t buf=0);
79 | void gotoXY(byte x, byte y);
80 | void sleep(bool mode=true);
81 | void setGfxMode(bool mode=true);
82 | void printTxt(uint8_t pos, char *str);
83 | void printTxt(uint8_t pos, uint16_t *signs);
84 |
85 | void cls();
86 | void drawPixel(uint8_t x, uint8_t y, uint8_t col);
87 | void drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t col);
88 | void drawLineH(uint8_t x0, uint8_t x1, uint8_t y, uint8_t col);
89 | void drawLineV(uint8_t x, uint8_t y0, uint8_t y1, uint8_t col);
90 | void drawLineVfast(uint8_t x, uint8_t y0, uint8_t y1, uint8_t col);
91 | void drawLineVfastD(uint8_t x, uint8_t y0, uint8_t y1, uint8_t col);
92 | void drawLineHfast(uint8_t x0, uint8_t x1, uint8_t y, uint8_t col);
93 | void drawLineHfastD(uint8_t x0, uint8_t x1, uint8_t y, uint8_t col);
94 | void drawRect(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t col);
95 | void drawRectD(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t col);
96 | void fillRect(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t col);
97 | void fillRectD(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t col);
98 | void drawCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t col);
99 | void fillCircle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t col);
100 | void fillCircleD(uint8_t x0, uint8_t y0, uint8_t r, uint8_t col);
101 | void setDither(uint8_t s);
102 | int drawBitmap(const uint8_t *bmp, int x, uint8_t y, uint8_t w, uint8_t h);
103 | int drawBitmap(const uint8_t *bmp, int x, uint8_t y);
104 |
105 | void setFont(const uint8_t* f);
106 | void setCR(uint8_t _cr) { cr = _cr; }
107 | void setInvert(uint8_t _inv) { invertCh = _inv; }
108 | void setFontMinWd(uint8_t wd) { cfont.minCharWd = wd; }
109 | void setCharMinWd(uint8_t wd) { cfont.minCharWd = wd; }
110 | void setDigitMinWd(uint8_t wd) { cfont.minDigitWd = wd; }
111 | int printChar(int xpos, int ypos, unsigned char c);
112 | int printStr(int xpos, int ypos, char *str);
113 | int charWidth(uint8_t _ch, bool last=true);
114 | int strWidth(char *txt);
115 | unsigned char convertPolish(unsigned char _c);
116 | static bool isNumber(uint8_t ch);
117 | static bool isNumberExt(uint8_t ch);
118 | void setIsNumberFun(bool (*fun)(uint8_t)) { isNumberFun=fun; }
119 |
120 | public:
121 | byte scr[SCR_WD*SCR_HT/8];
122 | byte scrWd = 128/8;
123 | byte scrHt = 64;
124 | uint8_t csPin = 10;
125 |
126 | static byte xstab[8];
127 | static byte xetab[8];
128 | static byte pattern[4];
129 | static const byte ditherTab[4*17];
130 |
131 | //private:
132 | bool (*isNumberFun)(uint8_t ch);
133 | _propFont cfont;
134 | /*
135 | uint8_t xSize;
136 | uint8_t ySize;
137 | uint8_t ySize8;
138 | uint8_t firstCh;
139 | uint8_t lastCh;
140 | uint8_t minCharWd;
141 | uint8_t minDigitWd;
142 | */
143 | uint8_t cr; // carriage return mode for printStr
144 | uint8_t dualChar;
145 | uint8_t invertCh;
146 | uint8_t spacing = 1;
147 | };
148 | #endif
149 |
150 |
--------------------------------------------------------------------------------
/examples/ST7920_lib_Bitmap/ST7920_lib_Bitmap.ino:
--------------------------------------------------------------------------------
1 | // (C)2019 Pawel A. Hernik
2 |
3 | /*
4 | 128x64 ST7920 connections in SPI mode (only 6 wires between LCD and MCU):
5 |
6 | #01 GND -> GND
7 | #02 VCC -> VCC (5V)
8 | #04 RS -> D10/CS or any pin
9 | #05 R/W -> D11/MOSI
10 | #06 E -> D13/SCK
11 | #15 PSB -> GND (for SPI mode)
12 | #19 BLA -> D9, VCC or any pin via 300ohm resistor
13 | #20 BLK -> GND
14 | */
15 |
16 | #define LCD_BACKLIGHT 9
17 | #define LCD_CS 10
18 |
19 | #include "ST7920_SPI.h"
20 | #include
21 | ST7920_SPI lcd(LCD_CS);
22 |
23 | const uint8_t icon1 [] PROGMEM = { 16,16,
24 | 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xDE, 0xCC, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80,
25 | 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0x7B, 0x33, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01,
26 | };
27 |
28 | const uint8_t icon2 [] PROGMEM = { 16,16,
29 | 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xCC, 0xDE, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80,
30 | 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x33, 0x7B, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01,
31 | };
32 |
33 | const uint8_t icon3 [] PROGMEM = { 16,16,
34 | 0xFC, 0x0C, 0x14, 0x24, 0x44, 0x84, 0x04, 0x04, 0x04, 0x04, 0x84, 0x44, 0x24, 0x14, 0x0C, 0xFC,
35 | 0x3F, 0x30, 0x28, 0x24, 0x22, 0x21, 0x21, 0x22, 0x22, 0x21, 0x21, 0x22, 0x24, 0x28, 0x30, 0x3F,
36 | };
37 | void setup()
38 | {
39 | Serial.begin(9600);
40 | pinMode(LCD_BACKLIGHT, OUTPUT);
41 | //analogWrite(LCD_BACKLIGHT,30);
42 | digitalWrite(LCD_BACKLIGHT, HIGH);
43 | SPI.begin();
44 | lcd.init();
45 | lcd.cls();
46 | lcd.drawBitmap(icon1,0,0);
47 | lcd.drawBitmap(icon2,24,0);
48 | lcd.drawBitmap(icon3,48,0);
49 |
50 | lcd.drawBitmap(icon1,0,16);
51 | lcd.drawBitmap(icon2,-1,16);
52 | lcd.drawBitmap(icon3,-2,16);
53 | lcd.drawBitmap(icon3,116,54);
54 | lcd.display(0);
55 | //lcd.copy(0,10,8,32,0);
56 | }
57 |
58 | void loop()
59 | {
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/examples/ST7920_lib_Demo/ST7920_lib_Demo.ino:
--------------------------------------------------------------------------------
1 | // (C)2019 Pawel A. Hernik
2 |
3 | /*
4 | 128x64 ST7920 connections in SPI mode (only 6 wires between LCD and MCU):
5 |
6 | #01 GND -> GND
7 | #02 VCC -> VCC (5V)
8 | #04 RS -> D10/CS or any pin
9 | #05 R/W -> D11/MOSI
10 | #06 E -> D13/SCK
11 | #15 PSB -> GND (for SPI mode)
12 | #19 BLA -> D9, VCC or any pin via 300ohm resistor
13 | #20 BLK -> GND
14 | */
15 |
16 | #define LCD_BACKLIGHT 9
17 | #define LCD_CS 10
18 |
19 | #include "ST7920_SPI.h"
20 | #include
21 | ST7920_SPI lcd(LCD_CS);
22 |
23 | // from PropFonts library
24 | #include "c64enh_font.h"
25 |
26 | char buf[20];
27 |
28 | void setup()
29 | {
30 | Serial.begin(9600);
31 | pinMode(LCD_BACKLIGHT, OUTPUT);
32 | //analogWrite(LCD_BACKLIGHT,30);
33 | digitalWrite(LCD_BACKLIGHT, HIGH);
34 | SPI.begin();
35 | lcd.init();
36 | }
37 |
38 | float t=0;
39 |
40 | void animSinLines()
41 | {
42 | lcd.cls();
43 | float x;
44 | for(int i=0;i<64;i++) {
45 | x=20.0*(2.0+sin(t/10.0+i/18.0)*sin(i/9.0));
46 | lcd.drawLineHfastD(64-x,64+x,i,1);
47 | x=10.0*(2.0+sin(t/8.0+i/15.0)*sin(i/5.0));
48 | lcd.drawLineHfast(64-x,64+x,i,1);
49 | }
50 | t+=0.7;
51 | lcd.display(0);
52 | }
53 |
54 | char *banner="ST7920 LCD Library";
55 |
56 | void animTextSin()
57 | {
58 | lcd.cls();
59 | lcd.setFont(c64enh);
60 | char *txt=banner;
61 | int x=4,i=0;
62 | float y;
63 | while(*txt) {
64 | y=20+10.0*(1.0+sin(t/10.0+i/6.0)*sin(t/18.0+i/9.0));
65 | x+=lcd.printChar(x,(int)y,*txt++);
66 | i++;
67 | }
68 | t+=0.7;
69 | lcd.display(0);
70 | }
71 |
72 | void animTextCircle()
73 | {
74 | lcd.cls();
75 | lcd.setFont(c64enh);
76 | char *txt=banner;
77 | int x=4;
78 | float y,y2,xr;
79 | float r=10.0+6.0*(1.0+sin(t/28.0));
80 | float xo=38.0*(0.0+sin(t/20.0));
81 | float yt=24;
82 | while(*txt) {
83 | xr=2+x-64-xo;
84 | y2=(r+3)*(r+3)-(xr)*(xr);
85 | y=yt;
86 | if(y2>0) y=32-sqrt(y2)-5;
87 | if(y<0) y=0;
88 | if(y>yt) y=yt;
89 | x+=lcd.printChar(x,(int)y,*txt++);
90 | }
91 |
92 | lcd.fillCircleD(64+xo,32,r,1);
93 | //lcd.drawCircle(64+xo,32,r+1,1);
94 | t+=0.4;
95 | lcd.display(0);
96 | }
97 |
98 | void rects()
99 | {
100 | int x,y;
101 | x = random(128);
102 | y = random(40);
103 | lcd.setDither(random(12));
104 | lcd.fillRect(x,y,30,30,0);
105 | lcd.fillRectD(x,y,30,30,1);
106 | lcd.drawRect(x,y,30,30,1);
107 | lcd.display(0);
108 | //delay(100);
109 | }
110 |
111 | void circles()
112 | {
113 | int x,y;
114 | x = 15+random(128-30);
115 | y = 15+random(64-30);
116 | lcd.setDither(random(12));
117 | lcd.fillCircle(x,y,15,0);
118 | lcd.fillCircleD(x,y,15,1);
119 | lcd.drawCircle(x,y,16,1);
120 | lcd.display(0);
121 | //delay(100);
122 | }
123 |
124 | int x=40,y=0;
125 | int dx=6,dy=5;
126 | int x2=80,y2=40;
127 | int dx2=9,dy2=8;
128 |
129 | void animRect()
130 | {
131 | x+=dx;
132 | y+=dy;
133 | if(x>64 || x<0) { dx=-dx; x+=dx; }
134 | if(y>32 || y<0) { dy=-dy; y+=dy; }
135 | lcd.fillRect(x,y,64,32,2);
136 | lcd.display(0);
137 | lcd.fillRect(x,y,64,32,2);
138 | delay(40);
139 | }
140 |
141 | #define MAX_LINES 10
142 | byte lx0[MAX_LINES];
143 | byte lx1[MAX_LINES];
144 | byte ly0[MAX_LINES];
145 | byte ly1[MAX_LINES];
146 | byte curLine=0;
147 |
148 | void animLines()
149 | {
150 | x+=dx;
151 | y+=dy;
152 | x2+=dx2;
153 | y2+=dy2;
154 | if(x>127) { dx=-dx; x=127; }
155 | if(x<1) { dx=-dx; x=0; }
156 | if(y>63) { dy=-dy; y=63; }
157 | if(y<1) { dy=-dy; y=0; }
158 | if(x2>127) { dx2=-dx2; x2=127; }
159 | if(x2<1) { dx2=-dx2; x2=0; }
160 | if(y2>63) { dy2=-dy2; y2=63; }
161 | if(y2<1) { dy2=-dy2; y2=0; }
162 | lx0[curLine]=x;
163 | lx1[curLine]=x2;
164 | ly0[curLine]=y;
165 | ly1[curLine]=y2;
166 | if(++curLine>=MAX_LINES) curLine=0;
167 | lcd.cls();
168 | for(int i=0;i GND
7 | #02 VCC -> VCC (5V)
8 | #04 RS -> D10/CS or any pin
9 | #05 R/W -> D11/MOSI
10 | #06 E -> D13/SCK
11 | #15 PSB -> GND (for SPI mode)
12 | #19 BLA -> D9, VCC or any pin via 300ohm resistor
13 | #20 BLK -> GND
14 | */
15 |
16 | #define LCD_BACKLIGHT 9
17 | #define LCD_CS 10
18 |
19 | #include "ST7920_SPI.h"
20 | #include
21 | ST7920_SPI lcd(LCD_CS);
22 |
23 | // from PropFonts library
24 | #include "c64enh_font.h"
25 | #include "tiny3x7sq_font.h"
26 |
27 | char buf[20];
28 |
29 | void setup()
30 | {
31 | Serial.begin(9600);
32 | pinMode(LCD_BACKLIGHT, OUTPUT);
33 | //analogWrite(LCD_BACKLIGHT,30);
34 | digitalWrite(LCD_BACKLIGHT, HIGH);
35 | SPI.begin();
36 | lcd.init();
37 | lcd.cls();
38 | for(int j=1;j<17;j++) { lcd.setDither(j); lcd.fillRectD((j-1)*8,0,8,64,1); }
39 | lcd.display(0); delay(5000);
40 | }
41 |
42 | void sample(int s)
43 | {
44 | lcd.cls();
45 | lcd.setDither(s);
46 | lcd.setFont(c64enh);
47 | snprintf(buf,20,"Pattern: %02d",s);
48 | lcd.printStr(ALIGN_CENTER, 2, buf);
49 | lcd.fillRectD(4,13,68,32,1);
50 | lcd.fillCircleD(100,28,16,1);
51 | for(int j=1;j<17;j++) {
52 | lcd.setFont(Tiny3x7SqPL);
53 | snprintf(buf,20,"%2d",j);
54 | lcd.printStr((j-1)*8, 64-8*2, buf);
55 | lcd.setDither(j);
56 | lcd.fillRectD((j-1)*8,64-8,8,8,1);
57 | }
58 | lcd.display(0);
59 | delay(500);
60 | }
61 |
62 | void loop()
63 | {
64 |
65 | /*
66 | lcd.cls();
67 | for(int j=1;j<17;j++) {
68 | lcd.setDither(j);
69 | lcd.fillRectD((j-1)*4,0,4,j*4,1);
70 | //lcd.display(0); delay(1000);
71 | }
72 | for(int j=15;j>=0;j--) {
73 | lcd.setDither(j);
74 | lcd.fillRectD((15-j)*4+63,0,4,j*4,1);
75 | lcd.display(0); delay(1000);
76 | }
77 | lcd.display(0);
78 | delay(5000);*/
79 | for(int i=0;i<=16;i++) sample(i);
80 | for(int i=16;i>0;i--) sample(i);
81 | }
82 |
83 |
--------------------------------------------------------------------------------
/examples/ST7920_lib_DoubleBuffer/ST7920_lib_DoubleBuffer.ino:
--------------------------------------------------------------------------------
1 | // (C)2019 Pawel A. Hernik
2 |
3 | /*
4 | 128x64 ST7920 connections in SPI mode (only 6 wires between LCD and MCU):
5 |
6 | #01 GND -> GND
7 | #02 VCC -> VCC (5V)
8 | #04 RS -> D10/CS or any pin
9 | #05 R/W -> D11/MOSI
10 | #06 E -> D13/SCK
11 | #15 PSB -> GND (for SPI mode)
12 | #19 BLA -> D9, VCC or any pin via 300ohm resistor
13 | #20 BLK -> GND
14 | */
15 |
16 | #define LCD_BACKLIGHT 9
17 | #define LCD_CS 10
18 |
19 | #include "ST7920_SPI.h"
20 | #include
21 | ST7920_SPI lcd(LCD_CS);
22 |
23 | // from PropFonts library
24 | #include "c64enh_font.h"
25 |
26 | void setup()
27 | {
28 | Serial.begin(9600);
29 | pinMode(LCD_BACKLIGHT, OUTPUT);
30 | //analogWrite(LCD_BACKLIGHT,30);
31 | digitalWrite(LCD_BACKLIGHT, HIGH);
32 |
33 | SPI.begin();
34 | lcd.init();
35 | lcd.cls();
36 | lcd.setFont(c64enh);
37 | lcd.printStr(ALIGN_CENTER, 8, "Buffer #0");
38 | lcd.fillRect(18,24,32,32,1);
39 | lcd.fillRect(128-18-32,24,32,32,1);
40 | lcd.display(0);
41 | lcd.cls();
42 | lcd.setFont(c64enh);
43 | lcd.printStr(ALIGN_CENTER, 64-16, "Buffer #1");
44 | lcd.fillCircle(64,24,20,1);
45 | lcd.display(1);
46 | }
47 |
48 | void loop()
49 | {
50 | lcd.switchBuf(0);
51 | delay(1000);
52 | lcd.switchBuf(1);
53 | delay(1000);
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/examples/ST7920_lib_GraphicsMode/ST7920_lib_GraphicsMode.ino:
--------------------------------------------------------------------------------
1 | // (C)2019 Pawel A. Hernik
2 |
3 | /*
4 | 128x64 ST7920 connections in SPI mode (only 6 wires between LCD and MCU):
5 |
6 | #01 GND -> GND
7 | #02 VCC -> VCC (5V)
8 | #04 RS -> D10/CS or any pin
9 | #05 R/W -> D11/MOSI
10 | #06 E -> D13/SCK
11 | #15 PSB -> GND (for SPI mode)
12 | #19 BLA -> D9, VCC or any pin via 300ohm resistor
13 | #20 BLK -> GND
14 | */
15 |
16 | #define LCD_BACKLIGHT 9
17 | #define LCD_CS 10
18 |
19 | #include "ST7920_SPI.h"
20 | #include
21 | ST7920_SPI lcd(LCD_CS);
22 |
23 | void setup()
24 | {
25 | Serial.begin(9600);
26 | pinMode(LCD_BACKLIGHT, OUTPUT);
27 | //analogWrite(LCD_BACKLIGHT,30);
28 | digitalWrite(LCD_BACKLIGHT, HIGH);
29 | SPI.begin();
30 | lcd.init();
31 | lcd.cls();
32 | lcd.drawRectD(0,0,128,64,1);
33 |
34 | lcd.drawRect(9,5,30,20,1);
35 | lcd.fillRect(9+40,5,30,20,2);
36 | lcd.fillRectD(9+80,5,30,20,1);
37 | //lcd.drawRect(9+80,5,30,20,1);
38 |
39 | lcd.drawCircle(9+15,44,15,1);
40 | lcd.fillCircle(9+40+15,44,15,1);
41 | lcd.fillCircleD(9+80+15,44,15,1);
42 | //lcd.drawCircle(9+80+15,44,15+1,1);
43 |
44 | lcd.display(0);
45 | }
46 |
47 | void loop()
48 | {
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/examples/ST7920_lib_HelloWorld/ST7920_lib_HelloWorld.ino:
--------------------------------------------------------------------------------
1 | // (C)2019 Pawel A. Hernik
2 |
3 | /*
4 | 128x64 ST7920 connections in SPI mode (only 6 wires between LCD and MCU):
5 |
6 | #01 GND -> GND
7 | #02 VCC -> VCC (5V)
8 | #04 RS -> D10/CS or any pin
9 | #05 R/W -> D11/MOSI
10 | #06 E -> D13/SCK
11 | #15 PSB -> GND (for SPI mode)
12 | #19 BLA -> D9, VCC or any pin via 300ohm resistor
13 | #20 BLK -> GND
14 | */
15 |
16 | #define LCD_BACKLIGHT 9
17 | #define LCD_CS 10
18 |
19 | #include "ST7920_SPI.h"
20 | #include
21 | ST7920_SPI lcd(LCD_CS);
22 |
23 | // from PropFonts library
24 | #include "c64enh_font.h"
25 |
26 | void setup()
27 | {
28 | Serial.begin(9600);
29 | pinMode(LCD_BACKLIGHT, OUTPUT);
30 | //analogWrite(LCD_BACKLIGHT,30);
31 | digitalWrite(LCD_BACKLIGHT, HIGH);
32 |
33 | SPI.begin();
34 | lcd.init();
35 | lcd.cls();
36 | lcd.setFont(c64enh);
37 | lcd.printStr(ALIGN_CENTER, 28, "Hello World!");
38 | lcd.drawRect(18,20,127-18*2,63-20*2,1);
39 | lcd.display(0);
40 | }
41 |
42 | void loop()
43 | {
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/examples/ST7920_lib_TextMode/ST7920_lib_TextMode.ino:
--------------------------------------------------------------------------------
1 | // (C)2019 Pawel A. Hernik
2 |
3 | /*
4 | 128x64 ST7920 connections in SPI mode (only 6 wires between LCD and MCU):
5 |
6 | #01 GND -> GND
7 | #02 VCC -> VCC (5V)
8 | #04 RS -> D10/CS or any pin
9 | #05 R/W -> D11/MOSI
10 | #06 E -> D13/SCK
11 | #15 PSB -> GND (for SPI mode)
12 | #19 BLA -> D9, VCC or any pin via 300ohm resistor
13 | #20 BLK -> GND
14 | */
15 |
16 | #define LCD_BACKLIGHT 9
17 | #define LCD_CS 10
18 |
19 | #include "ST7920_SPI.h"
20 | #include
21 | ST7920_SPI lcd(LCD_CS);
22 |
23 | void setup()
24 | {
25 | Serial.begin(9600);
26 | pinMode(LCD_BACKLIGHT, OUTPUT);
27 | //analogWrite(LCD_BACKLIGHT,30);
28 | digitalWrite(LCD_BACKLIGHT, HIGH);
29 | SPI.begin();
30 | lcd.init();
31 | lcd.setGfxMode(false);
32 |
33 | // Watch https://www.youtube.com/watch?v=OyUXVsbAcmo for built-in font codes
34 | uint16_t star1[] = { 0xa1ee, 0 };
35 | uint16_t star2[] = { 0xa1ef, 0 };
36 | //uint16_t signs[] = { 0xa170,0xa171,0xa173,0xa174,0xa175,0xa176,0 };
37 | uint16_t signs1[] = { 0xa170,0xa171,0 };
38 | uint16_t signs2[] = { 0xa173,0xa174,0 };
39 | //uint16_t roman[] = { 0xa271,0xa271+11,0 };
40 | uint16_t fnt16x16[] = { 0xa300+'F', 0xa300+'n',0xa300+'t',0xa331,0xa336, 0xa141,0xa331,0xa336,0 };
41 | uint16_t date[] = { 0xa161, 0xa300+'1', 0xa300+'5', 0xa270+8, 0xa300+'1', 0xa300+'4', 0xa300+'1', 0xa300+'0',0 };
42 | uint16_t temp[] = { 0xa300+'+', 0xa300+'2', 0xa300+'7', 0xa166,0 };
43 |
44 | lcd.printTxt(LCD_LINE0+0,star1);
45 | lcd.printTxt(LCD_LINE0+7,star2);
46 | lcd.printTxt(LCD_LINE0+2,"Font16x8");
47 | //lcd.printTxt(LCD_LINE1+2,"Line #1");
48 | lcd.printTxt(LCD_LINE1,fnt16x16);
49 | lcd.printTxt(LCD_LINE2+2,temp);
50 | lcd.printTxt(LCD_LINE2+0,signs1);
51 | lcd.printTxt(LCD_LINE2+6,signs2);
52 | //lcd.printTxt(LCD_LINE2+4,roman);
53 | lcd.printTxt(LCD_LINE3,date);
54 | }
55 |
56 | void loop()
57 | {
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/keywords.txt:
--------------------------------------------------------------------------------
1 | SP7920_SPI KEYWORD3
2 |
3 | init KEYWORD2
4 | setFont KEYWORD2
5 | setFontMinWd KEYWORD2
6 | setCharMinWd KEYWORD2
7 | setDigitMinWd KEYWORD2
8 | setCR KEYWORD2
9 | printStr KEYWORD2
10 | printChar KEYWORD2
11 | charWidth KEYWORD2
12 | strWidth KEYWORD2
13 | cls KEYWORD2
14 | drawBitmap KEYWORD2
15 | drawBuf KEYWORD2
16 | setIsNumberFun KEYWORD2
17 |
18 | fillWin KEYWORD2
19 | sendData KEYWORD2
20 | sendCmd KEYWORD2
21 | gotoXY KEYWORD2
22 | sleep KEYWORD2
23 | setInvert KEYWORD2
24 | setGfxMode KEYWORD2
25 |
26 | cls KEYWORD2
27 | drawPixel KEYWORD2
28 | drawLine KEYWORD2
29 | drawLineH KEYWORD2
30 | drawLineV KEYWORD2
31 | drawLineVfast KEYWORD2
32 | drawLineVfastD KEYWORD2
33 | drawLineHfast KEYWORD2
34 | drawLineHfastD KEYWORD2
35 | drawRect KEYWORD2
36 | drawRectD KEYWORD2
37 | fillRect KEYWORD2
38 | fillRectD KEYWORD2
39 | drawCircle KEYWORD2
40 | fillCircle KEYWORD2
41 | fillCircleD KEYWORD2
42 | setDither KEYWORD2
43 |
44 | SCR_WD LITERAL1
45 | SCR_HT LITERAL1
46 | ALIGN_LEFT LITERAL1
47 | ALIGN_RIGHT LITERAL1
48 | ALIGN_CENTER LITERAL1
49 |
--------------------------------------------------------------------------------