-
Notifications
You must be signed in to change notification settings - Fork 0
/
vga_ctr.v.bak
228 lines (200 loc) · 6.58 KB
/
vga_ctr.v.bak
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
module vga_ctr
(
input vga_clk,//输入时钟50M
input vga_rst_n,
input [9:0] i_data,
output [8:0] o_address,
output reg[23:0] color_data,//颜色信号 红--绿--蓝
output vga_hs, //行同步信号输出
output vga_vs, //场同步信号输出
output reg clk_25M,
output blank_n, //消隐
output sync_n //信号同步
);
//define colors RGB--8|8|8
`define RED 24'hFF0000 /*11111111,00000000,00000000 */
`define GREEN 24'h00FF00 /*00000000,11111111,00000000 */
`define BLUE 24'h0000FF /*00000000,00000000,11111111 */
`define WHITE 24'hFFFFFF /*11111111,11111111,11111111 */
`define BLACK 24'h000000 /*00000000,00000000,00000000 */
`define YELLOW 24'hFFFF00 /*11111111,11111111,00000000 */
`define CYAN 24'hFF00FF /*11111111,00000000,11111111 */
`define ROYAL 24'h00FFFF /*00000000,11111111,11111111 */
// 640 * 480
`define H_FRONT 11'd16
`define H_SYNC 11'd96
`define H_BACK 11'd48
`define H_DISP 11'd640
`define H_TOTAL 11'd800
`define V_FRONT 11'd10
`define V_SYNC 11'd2
`define V_BACK 11'd33
`define V_DISP 11'd480
`define V_TOTAL 11'd525
reg [11:0] cnt_hs; //行信号clk计数,
reg [11:0] cnt_vs; //场信号clk计数
wire lcd_request;
wire [11:0] vga_x; //VGA的x坐标
wire [11:0] vga_y; //VGA的y坐标
wire [8:0] i_data_temp;//进行坐标变换
wire [8:0] i_temp;
wire area0;//网格线标志
wire area1;//界面区域标志
wire area2;//数据框标志
wire area3;//
//功能: 产生25MHz的像素时钟
//////////////////////////////////////////////////////////////////
always @(posedge vga_clk or negedge vga_rst_n)
begin
if(!vga_rst_n)
clk_25M <= 1'b0 ;
else
clk_25M <= ~clk_25M ;
end
//----------------------------------------------
always @ (posedge clk_25M or negedge vga_rst_n)
begin
if (!vga_rst_n)
cnt_hs <= 11'd0;
else
begin
if(cnt_hs < `H_TOTAL - 1'b1) //line over
cnt_hs <= cnt_hs + 1'b1;
else
cnt_hs <= 11'd0;
end
end
assign vga_hs = (cnt_hs <= `H_SYNC - 1'b1) ? 1'b0 : 1'b1;
//VGA行同步信号
always@(posedge clk_25M or negedge vga_rst_n)
begin
if (!vga_rst_n)
cnt_vs <= 11'b0;
else if(cnt_hs == `H_TOTAL - 1'b1) //line over
begin
if(cnt_vs < `V_TOTAL - 1'b1) //frame over
cnt_vs <= cnt_vs + 1'b1;
else cnt_vs <= 11'd0;
end
end
assign vga_vs = (cnt_vs <= `V_SYNC - 1'b1) ? 1'b0 : 1'b1;
//VGA场同步信号
assign blank_n = lcd_request;//vga_hs & vga_vs;
assign sync_n=1'b0;
assign o_address = vga_x[8:0];
//ahead x clock
localparam H_AHEAD = 12'd1;
assign lcd_request = ((cnt_hs >= `H_SYNC + `H_BACK - H_AHEAD )&& (cnt_hs < `H_SYNC + `H_BACK + `H_DISP - H_AHEAD) &&
(cnt_vs >= `V_SYNC + `V_BACK )&& (cnt_vs < `V_SYNC + `V_BACK + `V_DISP) )
? 1'b1 : 1'b0;
//lcd vgax & vgay
assign vga_x = lcd_request ? (cnt_hs - (`H_SYNC + `H_BACK - H_AHEAD)) : 11'd0;
assign vga_y = lcd_request ? (cnt_vs - (`V_SYNC + `V_BACK)) : 11'd0;
//-----------------------
assign i_data_temp = i_data[9:1];
assign i_temp = (240-i_data_temp/2)+120;
// 示波器界面
assign area0 = ( vga_x == 10 || vga_x==60 ||
vga_x==110 || vga_x==160 ||
vga_x==210 || vga_x==260 ||
vga_x==310 || vga_x==360 ||
vga_x==410 || vga_x==460 ||
vga_x==510
|| vga_y == 20 || vga_y == 75
|| vga_y == 130 || vga_y == 185
|| vga_y == 240 || vga_y == 295
|| vga_y == 350 || vga_y == 405
|| vga_y == 460 )
?1'b1 : 1'b0;
assign area1 = (vga_x >= 10 && vga_x <= 510 && vga_y >= 20 && vga_y <= 460) ?1'b1 : 1'b0;
//--------------------
//示波器数据显示界面
assign area2 = (vga_x >= 520 && vga_x <= 620 && vga_y >= 80 && vga_y <= 400) ?1'b1 : 1'b0;
//显示数字
//8
assign area3 = ( vga_x >= 1 && vga_x <= 6 && ( vga_y == 1 || vga_y == 6 || vga_y == 11 ) ||
vga_y >= 1 && vga_y <= 11 && ( vga_x == 1 || vga_x == 6 )
//vga_x >= 1 && vga_x <= 4 && ( vga_y == 1 || vga_y == 4 || vga_y == 7 )
//vga_x >= 1 && vga_x <= 4 && ( vga_y == 1 || vga_y == 4 || vga_y == 7 )
) ?1'b1 : 1'b0;
//显示
always@(posedge clk_25M or negedge vga_rst_n)
begin
if(!vga_rst_n)
color_data <= 24'H0;
else if(area1)
if(vga_y == (i_temp[8:0]))
color_data <= `RED;
else if(area0)
color_data<= `BLACK; //24'H77909E;//格线
else
color_data <= 24'H606060;//内背景
else if(area2)
color_data <= `WHITE;//
else if(area3)
color_data <= `BLACK;//
else
color_data <= 24'H808080;//外背景
end
endmodule
/*if(!vga_rst_n)
color_data <= 24'h0;
else
begin
if ((vga_x >= 0) &&( vga_x < (`H_DISP/8)*1) )
color_data <= `RED;
else if(vga_x >= (`H_DISP/8)*1 && vga_x < (`H_DISP/8)*2)
color_data <= `BLUE;
else if(vga_x >= (`H_DISP/8)*2 && vga_x < (`H_DISP/8)*3)
color_data <= `GREEN;
else if(vga_x >= (`H_DISP/8)*3 && vga_x < (`H_DISP/8)*4)
color_data <= `CYAN;
else if(vga_x >= (`H_DISP/8)*4 && vga_x < (`H_DISP/8)*5)
color_data <= `BLACK;
else if(vga_x >= (`H_DISP/8)*5 && vga_x < (`H_DISP/8)*6)
color_data <= `WHITE;
else if(vga_x >= (`H_DISP/8)*6 && vga_x < (`H_DISP/8)*7)
color_data <= `ROYAL;
else if(vga_x >= (`H_DISP/8)*7 && vga_x < (`H_DISP/8)*8)
color_data <= `YELLOW;
end */
/*if(!vga_rst_n)
color_data <= 24'h0;
else
begin
if ((vga_y >= 0) &&( vga_y < (`V_DISP/4)*1) )
color_data <= `RED;
else if(vga_y >= (`V_DISP/4)*1 && vga_y < (`V_DISP/4)*2)
color_data <= `BLUE;
else if(vga_y >= (`V_DISP/4)*2 && vga_y < (`V_DISP/4)*3)
color_data <= `GREEN;
else if(vga_y >= (`V_DISP/4)*3 && vga_y < (`V_DISP/4)*4)
color_data <= `YELLOW;
end */
/*
if(!vga_rst_n)
color_data <= 24'h0;
else
begin
if ((vga_y >= 10) &&( vga_y < (`V_DISP/4)*1+10) )
color_data <= `RED;
else if(vga_y >= ((`V_DISP/4)*1+10) && vga_y < (`V_DISP/4)*4)
begin
if ((vga_x >= 0) &&( vga_x < (`H_DISP/8)*1) )
color_data <= `WHITE;
else if(vga_x >= (`H_DISP/8)*1 && vga_x < (`H_DISP/8)*2)
color_data <= `BLUE;
else if(vga_x >= (`H_DISP/8)*2 && vga_x < (`H_DISP/8)*3)
color_data <= `GREEN;
else if(vga_x >= (`H_DISP/8)*3 && vga_x < (`H_DISP/8)*4)
color_data <= `CYAN;
else if(vga_x >= (`H_DISP/8)*4 && vga_x < (`H_DISP/8)*5)
color_data <= `BLACK;
else if(vga_x >= (`H_DISP/8)*5 && vga_x < (`H_DISP/8)*6)
color_data <= `WHITE;
else if(vga_x >= (`H_DISP/8)*6 && vga_x < (`H_DISP/8)*7)
color_data <= `ROYAL;
else if(vga_x >= (`H_DISP/8)*7 && vga_x < (`H_DISP/8)*8)
color_data <= `YELLOW;
end
end */