-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn5110_drive.c
194 lines (165 loc) · 2.79 KB
/
n5110_drive.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "systick_time.h"
#include "gp_drive.h"
#include "SPI_drive.h"
#include "n5110_drive.h"
// n5110_clear
void n5110_clear(void)
{
int j;
n5110_pos(0,0);
W_GP(PA,1,HIGH);
for(j=0;j<504;j++)
{
spi_tx(1,0x00);
}
}
void n5110_init(unsigned short spi)
{
// Setup RST pin
init_GP(PA,0,OUT50,O_GP_PP);
// Set RST High & Wait 10 ms set low & Wait 10 ms and set high
W_GP(PA,0,HIGH);
DelayMs(10);
W_GP(PA,0,LOW); //Reset of screen
DelayMs(10);
W_GP(PA,0,HIGH);
// Setup DC pin & set low
init_GP(PA,1,OUT50,O_GP_PP);
W_GP(PA,1,LOW);
//Setup screenlight pin & test ligh with 1 sec high
init_GP(PA,2,OUT50,O_GP_PP);
W_GP(PA,2,HIGH);
DelayMs(1000);
W_GP(PA,2,LOW);
spi_init(spi);
//extended instruction set & set voltage
spi_tx(1,0x21);
spi_tx(1,0xC0);
//function set & display control set normal mode
spi_tx(1,0x20);
spi_tx(1,0x0C);
}
void n5110_print(short Ypos, short Xpos, char str[])
{
int i,j;
i = 0;
//Cleaning the String
n5110_pos(0,0);
W_GP(PA,1,HIGH);
for(j=0;j<504;j++)
{
spi_tx(1,0x00);
}
W_GP(PA,1,LOW);
//Writre String into n5110
n5110_pos(Ypos,Xpos);
W_GP(PA,1,HIGH);
while(str[i])
{
for(j=0;j<5;j++)
{
spi_tx(1,ASCII[str[i]-32][j]);
}
i++;
}
W_GP(PA,1,LOW);
//sring position
}
void n5110_pos(short Ypos,short Xpos)
{
W_GP(PA,1,LOW);
spi_tx(1,0x20);
spi_tx(1,((0x40 | Ypos)));
spi_tx(1,(0x80 | Xpos));
}
//update_buffer
void update_buffer(ImgType img, unsigned short img_num, unsigned char screen_buffer[][84])
{
int x_dir, y_dir, endx,endy, cnt;
if((img.w+img.x_pos)>84)
{
endx = 83;
}
else
{
endx = img.w+img.x_pos-1;
}
if((img.h+ img.y_pos)>5)
{
endy = 5;
}
else
{
endy = img.h+img.y_pos-1;
}
cnt = 0;
for(y_dir = img.y_pos;y_dir<=endy;y_dir++)
{
for (x_dir= img.x_pos;x_dir <= endx; x_dir ++)
{
cnt =(y_dir-img.y_pos)*img.w +x_dir-img.x_pos;
screen_buffer[y_dir][x_dir] = img.image[img_num][cnt];
}
}
}
//update str buffer
void update_str_buffer(short Ypos, short Xpos,char str[], unsigned char screen_buffer[][84])
{
int i,j, cnt_col,cnt_row;
cnt_col= Xpos;
cnt_row = Ypos;
i=0;
while(str[i])
{
if(cnt_row>5)
{break;}
for(j=0;j<5;j++)
{
screen_buffer[cnt_row][cnt_col] = ASCII[str[i]-32][j];
if((cnt_col+1)>83)
{
if((cnt_row+1)>5)
{
break;
}
else{
cnt_row ++;
cnt_col = Xpos;
}
}
else
{
cnt_col ++;
}
}
i++;
}
}
//print buffer
void print_buffer(unsigned char screen_buffer[][84])
{
n5110_clear();
n5110_pos(0,0);
int i,j;
W_GP(PA,1,HIGH);
for (i=0;i<6;i++)
{
for(j=0;j<84;j++)
{
spi_tx(1,screen_buffer[i][j]);
}
}
W_GP(PA,1,LOW);
}
//clear buffer
void clear_buffer(unsigned char screen_buffer[][84])
{
int i,j;
for (i=0;i<6;i++)
{
for(j=0;j<84;j++)
{
screen_buffer[i][j] = 0;
}
}
}