-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlcd_st7567s.h
101 lines (86 loc) · 4.33 KB
/
lcd_st7567s.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/******************************
* original code from
* URL: https://github.com/mworkfun/ST7567A_128X32DOT_LCD
*
*
* Modify for LCD ST7567S 128x64
* screen:
* x-----------------------> +
* y |
* | |
* |---------------------
* |
* v +
*
******************************/
#ifndef LCD_ST7567S_h
#define LCD_ST7567S_h
#include <Arduino.h>
#include <Wire.h>
#define DRAW_UPPER_RIGHT 0x01
#define DRAW_UPPER_LEFT 0x02
#define DRAW_LOWER_LEFT 0x04
#define DRAW_LOWER_RIGHT 0x08
#define DRAW_ALL (DRAW_UPPER_RIGHT|DRAW_UPPER_LEFT|DRAW_LOWER_RIGHT|DRAW_LOWER_LEFT)
class lcd_st7567s{
public:
// LCD is driven by ST7567A IC.
// Define instructions on page 37 of the ST7567A data sheet.
enum ST7567A_C {
displayON = 0xaf, //display on.
displayOFF = 0xae, //display off.
startLine = 0x40, //Set display start line.
restart = 0xe2, //restart command.
seg = 0xa0, //Set scan direction of SEG, SEG = 1-0-1-0-0-0-0-MX;
//MX=1-->reverse direction, MX=0-->normal direction.
INV_normal = 0xa6, //normal display.
AP_normal = 0xa4, //normal display.
BS = 0xa3, //select bias setting, bias = 1-0-1-0-0-0-1-BS, BS(0)=1/9, BS(1)=1/7(at 1/65 duty).
com = 0xc8, //Set output direction of COM, COM = 1-1-0-0-MY-X-X-X;
//MY=1-->reverse direction, MY=0-->normal direction.
powerCon1 = 0x2c, //Controls the built-in power circuits;
powerCon2 = 0x2e, //Define instructions on page 43 of the ST7567A data sheet.
powerCon3 = 0x2f,
/********Adjust display brightness********/
regRatio = 0x22, //Controls the regulation ratio of the built-in regulator;
//Define instructions on page 43 of the ST7567A data sheet.
EV1 = 0x81, //Define instructions on page 44 of the ST7567A data sheet.
EV2 = 0x30,
/**********entension command set**********/
exit_EC = 0xfe, //exit extension command set.
enter_EC = 0xff, //enter extension command set.
DSM_ON = 0x72, //display setting mode on.
DSM_OFF = 0x70, //display setting mode off.
DT = 0xd6, //set the display duty, DT=33.
BA = 0x90, //BA=1/9, selects LCD bias ratio for the internal voltage follower to drive the LCD.
//This command has priority over the Bias Select (BS).
FR = 0x9d, //specifies the frame rate for duty.
RMW = 0xe0, //Read-modify-Write command on page 42 of ST7567A datasheet.
END = 0xee,
};
lcd_st7567s();
void WriteByte_command(int dat); //Write a command to LCD.
void WriteCont_command(int str[]); //Continuously write commands to LCD.
void Init(); //This initialization function is called when using LCD.
void testPixel(int t); //use to test LCD screen.
void WriteByte_dat(int dat); //Write a data to RAM.
void WriteCont_dat(int str[]); //Continuously write data to RAM.
int ReadByte_dat(int col, int page); //read one byte RAM data to MCU. col=0-127, page=0-3
void DisplayPixel(int x,int y); //display one pixel. X=0-31, Y=0-127
void ClearPixel(int x,int y); //Does not display a pixel. X=0-31, Y=0-127
void Clear(bool invcolor); // false = RAM write '0', all pixels turn off.
void FontSize(int num); //reserve
void Cursor(int x, int y); //Character display position. x=0-17, y=0-3
void DisplayPicture(); //display picture.
void WriteFont(int num); //Writes the data from the font.c file to RAM.
void Display(char *str); //4 lines of 18 characters each.
// import from U8G2
// https://github.com/olikraus/u8g2
void DrawLine(int x1, int y1, int x2, int y2, bool invcolor);
void draw_circle_section(int x, int y, int x0, int y0, int option, bool invcolor, bool solid);
void draw_circle(int x0, int y0, int rad, int option, bool invcolor, bool solid);
private:
int addr = 0x3f; //Address of LCD device.
int cursor[2]={0,0};
};
#endif