-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLCD_MIPS.sv
200 lines (174 loc) · 3.21 KB
/
LCD_MIPS.sv
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
193
194
195
196
197
198
199
200
module LCD_MIPS (
input clk,rst,
input [8:0] data_mem,
output [7:0] DATA,
output [5:0] address,
output RW,EN,RS,ON);
// Internals
logic [5:0] L_Addr;
logic [8:0] L_DATA;
logic [17:0] Delay;
logic c_start;
logic [7:0] c_DATA;
logic c_RS;
logic c_Done;
logic rs_counter;
logic en_delay;
logic en_addr;
logic rs_addr;
assign address = L_Addr;
always_comb begin
if (L_Addr <=5)
case (L_Addr)
0: L_DATA = 9'h038;
1: L_DATA = 9'h00C;
2: L_DATA = 9'h001;
3: L_DATA = 9'h006;
4: L_DATA = 9'h080;
5: L_DATA = 9'h120;
default L_DATA = 0;
endcase
else if (L_Addr <= 31)
L_DATA = data_mem;
else L_DATA = 9'h120;
end
enum {BEG, INIT, DLY, DONE} state, next_state;
// Parameters
parameter INITIAL = 0;
parameter LINE1 = 5;
parameter CH_LINE = LINE1+16;
parameter LINE2 = LINE1+16+1;
parameter SIZE = LINE1+32+1;
//////////////////////////////////////////////////////////////////////////////////////////
//FSM
//Transicion de estado
always_ff @(posedge clk) begin
if(~rst)
state <= BEG;
else
state <= next_state;
end
//Cambio de estado
always_comb begin
if (~rst)
next_state = BEG;
else if (L_Addr<SIZE) begin
case (state)
BEG: next_state = INIT;
INIT: if (c_Done)
next_state = DLY;
else
next_state = INIT;
DLY: if(Delay<18'h3FFFE)
next_state = DLY;
else
next_state = DONE;
DONE: next_state = BEG;
default: next_state = BEG;
endcase
end
else
next_state = BEG;
end
//salidas
always_comb begin
if(~rst) begin
c_start <= 0;
c_DATA <= 0;
c_RS <= 0;
rs_counter <= 1;
rs_addr <= 1;
en_delay <= 0;
en_addr <= 0;
end
else if (L_Addr<SIZE) begin
case (state)
BEG:begin
c_DATA <= L_DATA[7:0];
c_RS <= L_DATA[8];
c_start <=1;
rs_counter <= 1;
en_delay <= 0;
en_addr <= 0;
rs_addr <= 0;
end
INIT:begin
c_start <=0;
c_DATA <= L_DATA[7:0];
c_RS <= L_DATA[8];
rs_counter <= 0;
en_delay <= 0;
en_addr <= 0;
rs_addr <= 0;
end
DLY:begin
c_start <=0;
c_DATA <= L_DATA[7:0];
c_RS <= L_DATA[8];
rs_counter <= 0;
en_delay <= 1;
en_addr <= 0;
rs_addr <= 0;
end
DONE:begin
c_start <=0;
c_DATA <= L_DATA[7:0];
c_RS <= L_DATA[8];
rs_counter <= 1;
en_delay <= 0;
en_addr <= 1;
rs_addr <= 0;
end
default: begin
c_start <= 0;
c_DATA <= 0;
c_RS <= 0;
rs_addr <= 0;
en_addr <= 0;
rs_counter <= 0;
en_delay <= 0;
end
endcase
end
else begin
c_start <= 0;
c_DATA <= 0;
c_RS <= 0;
rs_addr <= 0;
en_addr <= 0;
rs_counter <= 0;
en_delay <= 0;
end
end
///////////////////////////////////////////////////////////////////////////////////////////////
//counter addr
always @(posedge clk) begin
if (rs_addr)
L_Addr <= 0;
else if (en_addr)
L_Addr <= L_Addr + 1;
else
L_Addr <= L_Addr;
end
//counter delay
always @(posedge clk) begin
if (rs_counter)
Delay <= 0;
else if (en_delay)
Delay <= Delay+1;
else
Delay <= Delay;
end
LCD_Controller_MIPS u0 (
.DATA(c_DATA),
.iRS(c_RS),
.LCD_start(c_start),
.LCD_DONE(c_Done),
.clk(clk),
.reset(~rst),
.LCD_DATA(DATA),
.LCD_RW(RW),
.LCD_EN(EN),
.LCD_RS(RS),
.LCD_ON(ON));
endmodule