-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patholed_test.v
108 lines (101 loc) · 3.04 KB
/
oled_test.v
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
/* ------------------------------------------------ *
* Title : Pmod OLED Tester *
* Project : Pmod Collection *
* ------------------------------------------------ *
* File : oled_test.v *
* Author : Yigit Suoglu *
* Last Edit : 15/05/2021 *
* ------------------------------------------------ *
* Description : Master module to test OLED *
* interface module, oled *
* ------------------------------------------------ */
//`include "Utils/btn_debouncer.v"
module oled_tester(
input clk,
input rst,
//Interface connections
output power_on,
output display_reset,
output display_off,
output reg update,
output reg [511:0] display_data,
/* MSB(display_data[511:504]): left-up most
decreases as left to right
LSB(display_data[7:0]): right bottum most) */
output reg [1:0] line_count,
output reg [7:0] contrast,
output reg cursor_enable,
output reg cursor_flash,
output reg [5:0] cursor_pos,
input CS,
input MOSI,
input SCK,
input data_command_cntr, //high data, low command
input power_rst,
input vbat_c, //low to turn on
input vdd_c,
//board connections
input [15:0] sw,
//sw = {power on, display on,...,data[9:0]}
output [7:0] JB,
output [7:0] JC,
input btnU, //cursor_update
input btnL, //ch_contrast
input btnR, //save_data
input btnD); //display_reset
wire save_data,update_pre;
wire ch_contrast;
wire cursor_update;
assign JB = {vdd_c,vbat_c,power_rst,data_command_cntr,SCK,1'd0,MOSI,CS};
assign JC = {vdd_c,vbat_c,power_rst,data_command_cntr,SCK,1'd0,MOSI,CS};
assign display_off = ~sw[14];
assign power_on = sw[15];
assign update_pre = save_data | (sw[7:0] != display_data[511:504]) | (line_count != ~sw[9:8]);
always@(posedge clk) update <= update_pre;
always@(posedge clk or posedge rst)
begin
if(rst)
begin
display_data <= 0;
line_count <= 2'b11;
end
else
begin
if(save_data)
begin
display_data <= (display_data >> 8);
end
else
begin
display_data[511:504] <= sw[7:0];
line_count <= ~sw[9:8];
end
end
end
always@(posedge clk or posedge rst)
begin
if(rst)
begin
contrast <= 8'h7F;
end
else
begin
contrast <= (ch_contrast) ? sw[7:0] : contrast;
end
end
always@(posedge clk or posedge rst)
begin
if(rst)
begin
{cursor_enable,cursor_flash,cursor_pos} <= 8'h0;
end
else
begin
{cursor_enable,cursor_flash,cursor_pos} <= (cursor_update) ? sw[7:0] : {cursor_enable,cursor_flash,cursor_pos};
end
end
debouncer dbL(clk, rst, btnL, ch_contrast);
debouncer dbR(clk, rst, btnR, save_data);
debouncer dbU(clk, rst, btnU, cursor_update);
debouncer dbD(clk, rst, btnD, display_reset);
endmodule