-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSD1306.c
81 lines (72 loc) · 2.17 KB
/
SSD1306.c
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
#include "SSD1306.h"
void SSD1306_clr_screen(uint8_t color){
// send buffer 4 times to = 128 width
for(int i=0;i<8;i++){
I2C_Reset_Buffer();
I2C_Buffer_Add1(0xB0 + i);
I2C_Buffer_Add1(0x00);
I2C_Buffer_Add1(0x10);
SSD1306_send_CMD();
I2C_Fill_Buffer(color);
for (int j=0;j<4;j++)
SSD1306_send_data();
}
}
void SSD1306_PrintChar(char chr, uint8_t row, uint8_t col) {
I2C_Reset_Buffer();
I2C_Buffer_Add1(0xB0 + row);
I2C_Buffer_Add1((0x00) | (col & 0x0F));
I2C_Buffer_Add1((0x10) | (col>>4));
SSD1306_send_CMD();
I2C_Reset_Buffer();
for(int i=0; i < 5; i++){
I2C_Buffer_Add1(Font7x10[(chr - 32)][i]) ;
}
I2C_Buffer_Add3(0x00,0x00,0x00) ;
SSD1306_send_data();
return;
}
void SSD1306_PrintStr(char* str, uint8_t row, uint8_t col, bool bold){
if(bold)
SSD1306_PrintStr(str,(row + 4),col,false);
for(int i=0; i < strlen(str);i++){
SSD1306_PrintChar(str[i],row,col);
col+=8;
if(i==15){
col=0;
row++;
}
}
return;
}
void SSD1306_send_data(){
I2C_Write(SSD1306_ADDR, SSD1306_CONTROL_DATA_STREAM);
}
void SSD1306_send_CMD(){
I2C_Write( SSD1306_ADDR, SSD1306_CONTROL_CMD_STREAM);
}
void SSD1306_int(){
I2C_Reset_Buffer();
I2C_Buffer_Add2(SSD1306_SET_MPLX, SSD1306_HEIGHT - 1);
I2C_Buffer_Add2(SSD1306_SET_OFFSET,0);
I2C_Buffer_Add2(SSD1306_MEM_ADDR_MODE,0);
I2C_Buffer_Add1(SSD1306_SET_START);
I2C_Buffer_Add1(SSD1306_COL_NORM);
I2C_Buffer_Add1(SSD1306_ROW_NORM);
I2C_Buffer_Add2(0x20,0x02);//set page address mode
I2C_Buffer_Add3(0x22,0,7); //set page range
I2C_Buffer_Add3(0x21,0,127);//set col range
I2C_Buffer_Add2(0xDA,0x00);
I2C_Buffer_Add2(SSD1306_SET_CONTRAST,200);
I2C_Buffer_Add1(SSD1306_DISPLAY_NORMAL );
I2C_Buffer_Add2(SSD1306_OSC, 0x81 );
I2C_Buffer_Add2(SSD1306_CHARGE_PUMP ,SSD1306_CHARGE_PUMP_ON);
I2C_Buffer_Add2(SSD1306_CHARGE_PERIOD , 2);
I2C_Buffer_Add1(SSD1306_DISPLAY_ON);
SSD1306_send_CMD();
SSD1306_Screen_Test();
}
void SSD1306_Screen_Test(){
SSD1306_clr_screen(0xff);
SSD1306_clr_screen(0x00);
}