parent
d64d218d18
commit
9db454faca
@ -1,104 +1,104 @@
|
|||||||
// This file is part of the Universal Laboratory (uLab)
|
// This file is part of the Universal Laboratory (uLab)
|
||||||
//
|
//
|
||||||
// © 2007 - 2019 Raptor Engineering, LLC
|
// © 2007 - 2019 Raptor Engineering, LLC
|
||||||
// All Rights Reserved
|
// All Rights Reserved
|
||||||
//
|
//
|
||||||
// Licensed under the terms of the AGPL v3
|
// Licensed under the terms of the AGPL v3
|
||||||
|
|
||||||
module guest_fpga_top(clk, reset, four_bit_input, four_bit_output, eight_bit_input, eight_bit_output, sixteen_bit_input, sixteen_bit_output, lcd_data_in_address, lcd_data_in_data, lcd_data_in_enable, led_segment_bus, led_digit_select);
|
module guest_fpga_top(clk, reset, four_bit_input, four_bit_output, eight_bit_input, eight_bit_output, sixteen_bit_input, sixteen_bit_output, lcd_data_in_address, lcd_data_in_data, lcd_data_in_enable, led_segment_bus, led_digit_select);
|
||||||
input clk;
|
input clk;
|
||||||
input reset;
|
input reset;
|
||||||
|
|
||||||
input [3:0] four_bit_input;
|
input [3:0] four_bit_input;
|
||||||
output reg [3:0] four_bit_output;
|
output reg [3:0] four_bit_output;
|
||||||
input [7:0] eight_bit_input;
|
input [7:0] eight_bit_input;
|
||||||
output reg [7:0] eight_bit_output;
|
output reg [7:0] eight_bit_output;
|
||||||
input [15:0] sixteen_bit_input;
|
input [15:0] sixteen_bit_input;
|
||||||
output reg [15:0] sixteen_bit_output;
|
output reg [15:0] sixteen_bit_output;
|
||||||
|
|
||||||
output reg [5:0] lcd_data_in_address;
|
output reg [5:0] lcd_data_in_address;
|
||||||
output reg [7:0] lcd_data_in_data;
|
output reg [7:0] lcd_data_in_data;
|
||||||
output reg lcd_data_in_enable;
|
output reg lcd_data_in_enable;
|
||||||
|
|
||||||
output reg [7:0] led_segment_bus;
|
output reg [7:0] led_segment_bus;
|
||||||
output reg [3:0] led_digit_select;
|
output reg [3:0] led_digit_select;
|
||||||
|
|
||||||
reg [7:0] lcd_sample_counter = 48; // Create a sample LCD display counter register
|
reg [7:0] lcd_sample_counter = 48; // Create a sample LCD display counter register
|
||||||
reg [31:0] lcd_character_change_timer = 0; // Wait a certain number of cycles before loading a new character
|
reg [31:0] lcd_character_change_timer = 0; // Wait a certain number of cycles before loading a new character
|
||||||
reg [5:0] lcd_current_character = 0; // The current character's address
|
reg [5:0] lcd_current_character = 0; // The current character's address
|
||||||
|
|
||||||
always @(posedge clk) begin
|
always @(posedge clk) begin
|
||||||
four_bit_output = four_bit_input; // Loopback
|
four_bit_output = four_bit_input; // Loopback
|
||||||
eight_bit_output = eight_bit_input[3:0] + eight_bit_input[7:4]; // Sample adder
|
eight_bit_output = eight_bit_input[3:0] + eight_bit_input[7:4]; // Sample adder
|
||||||
sixteen_bit_output = sixteen_bit_input[15:8] * sixteen_bit_input[7:0]; // Sample multiplier
|
sixteen_bit_output = sixteen_bit_input[15:8] * sixteen_bit_input[7:0]; // Sample multiplier
|
||||||
|
|
||||||
// Sample LCD display routine
|
// Sample LCD display routine
|
||||||
lcd_data_in_address = lcd_current_character; // Character location on the LCD display
|
lcd_data_in_address = lcd_current_character; // Character location on the LCD display
|
||||||
lcd_data_in_data = lcd_sample_counter; // Character code to display
|
lcd_data_in_data = lcd_sample_counter; // Character code to display
|
||||||
lcd_data_in_enable = 1; // Enable data transmission
|
lcd_data_in_enable = 1; // Enable data transmission
|
||||||
|
|
||||||
// Cycle through all character positions
|
// Cycle through all character positions
|
||||||
lcd_current_character = lcd_current_character + 1;
|
lcd_current_character = lcd_current_character + 1;
|
||||||
if (lcd_current_character > 31) begin
|
if (lcd_current_character > 31) begin
|
||||||
lcd_current_character = 16;
|
lcd_current_character = 16;
|
||||||
end
|
end
|
||||||
|
|
||||||
// Cycle through the numbers 0 to 9 at one second intervals
|
// Cycle through the numbers 0 to 9 at one second intervals
|
||||||
lcd_character_change_timer = lcd_character_change_timer + 1;
|
lcd_character_change_timer = lcd_character_change_timer + 1;
|
||||||
if (lcd_character_change_timer > 6000000) begin // Wait one second in between character changes
|
if (lcd_character_change_timer > 6000000) begin // Wait one second in between character changes
|
||||||
lcd_character_change_timer = 0;
|
lcd_character_change_timer = 0;
|
||||||
lcd_sample_counter = lcd_sample_counter + 1;
|
lcd_sample_counter = lcd_sample_counter + 1;
|
||||||
if (lcd_sample_counter > 57) begin // Character code for the digit 9
|
if (lcd_sample_counter > 57) begin // Character code for the digit 9
|
||||||
lcd_sample_counter = 48; // Character code for the digit 0
|
lcd_sample_counter = 48; // Character code for the digit 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
// 7-segment LED display driver clock generator
|
// 7-segment LED display driver clock generator
|
||||||
reg sseg_clock;
|
reg sseg_clock;
|
||||||
reg [4:0] sseg_clock_counter;
|
reg [10:0] sseg_clock_counter;
|
||||||
|
|
||||||
always @(posedge clk) begin
|
always @(posedge clk) begin
|
||||||
sseg_clock_counter = sseg_clock_counter + 1;
|
sseg_clock_counter = sseg_clock_counter + 1;
|
||||||
if (sseg_clock_counter > 16) begin
|
if (sseg_clock_counter > 1023) begin
|
||||||
sseg_clock_counter = 0;
|
sseg_clock_counter = 0;
|
||||||
sseg_clock = ~sseg_clock;
|
sseg_clock = ~sseg_clock;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
// 7-segment LED display driver
|
// 7-segment LED display driver
|
||||||
// led_segment_bus and led_digit_select are active low
|
// led_segment_bus and led_digit_select are active low
|
||||||
// The bit sequence, MSB to LSB, is dp a b c d e f g
|
// The bit sequence, MSB to LSB, is dp a b c d e f g
|
||||||
// Segment letters are taken from ug130.pdf page 15
|
// Segment letters are taken from ug130.pdf page 15
|
||||||
|
|
||||||
// 0: 8'b10000001
|
// 0: 8'b10000001
|
||||||
// 1: 8'b11001111
|
// 1: 8'b11001111
|
||||||
// 2: 8'b10010010
|
// 2: 8'b10010010
|
||||||
// 3: 8'b10000110
|
// 3: 8'b10000110
|
||||||
reg [2:0] current_anode;
|
reg [2:0] current_anode;
|
||||||
always @(posedge sseg_clock) begin
|
always @(posedge sseg_clock) begin
|
||||||
current_anode = current_anode + 1;
|
current_anode = current_anode + 1;
|
||||||
if (current_anode > 3) begin
|
if (current_anode > 3) begin
|
||||||
current_anode = 0;
|
current_anode = 0;
|
||||||
end
|
end
|
||||||
|
|
||||||
case (current_anode)
|
case (current_anode)
|
||||||
0: begin
|
0: begin
|
||||||
led_digit_select = 4'b1110;
|
led_digit_select = 4'b1110;
|
||||||
led_segment_bus = 8'b10000001;
|
led_segment_bus = 8'b10000001;
|
||||||
end
|
end
|
||||||
1: begin
|
1: begin
|
||||||
led_digit_select = 4'b1101;
|
led_digit_select = 4'b1101;
|
||||||
led_segment_bus = 8'b11001111;
|
led_segment_bus = 8'b11001111;
|
||||||
end
|
end
|
||||||
2: begin
|
2: begin
|
||||||
led_digit_select = 4'b1011;
|
led_digit_select = 4'b1011;
|
||||||
led_segment_bus = 8'b10010010;
|
led_segment_bus = 8'b10010010;
|
||||||
end
|
end
|
||||||
3: begin
|
3: begin
|
||||||
led_digit_select = 4'b0111;
|
led_digit_select = 4'b0111;
|
||||||
led_segment_bus = 8'b10000110;
|
led_segment_bus = 8'b10000110;
|
||||||
end
|
end
|
||||||
endcase
|
endcase
|
||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
|
Loading…
Reference in new issue