use 8 sets of seven-segment LED

This commit is contained in:
Chen Lu 2022-02-18 14:40:46 +08:00 committed by Zihao Yu
parent a950c0b64f
commit 131f308ca1
7 changed files with 156 additions and 22 deletions

View File

@ -58,14 +58,77 @@ output AN5
output AN6
output AN7
output SEGA
output SEGB
output SEGC
output SEGD
output SEGE
output SEGF
output SEGG
output DECP
output SEG0A
output SEG0B
output SEG0C
output SEG0D
output SEG0E
output SEG0F
output SEG0G
output DEC0P
output SEG1A
output SEG1B
output SEG1C
output SEG1D
output SEG1E
output SEG1F
output SEG1G
output DEC1P
output SEG2A
output SEG2B
output SEG2C
output SEG2D
output SEG2E
output SEG2F
output SEG2G
output DEC2P
output SEG3A
output SEG3B
output SEG3C
output SEG3D
output SEG3E
output SEG3F
output SEG3G
output DEC3P
output SEG4A
output SEG4B
output SEG4C
output SEG4D
output SEG4E
output SEG4F
output SEG4G
output DEC4P
output SEG5A
output SEG5B
output SEG5C
output SEG5D
output SEG5E
output SEG5F
output SEG5G
output DEC5P
output SEG6A
output SEG6B
output SEG6C
output SEG6D
output SEG6E
output SEG6F
output SEG6G
output DEC6P
output SEG7A
output SEG7B
output SEG7C
output SEG7D
output SEG7E
output SEG7F
output SEG7G
output DEC7P
output VGA_CLK
output VGA_VSYNC

39
emu/src/seg.v Normal file
View File

@ -0,0 +1,39 @@
module seg(
input clk,
input rst,
output reg[7:0] o_seg1,
output reg[7:0] o_seg2,
output reg[7:0] o_seg3,
output reg[7:0] o_seg4,
output reg[7:0] o_seg5,
output reg[7:0] o_seg6,
output reg[7:0] o_seg7,
output reg[7:0] o_seg8
);
parameter segs = {8'b01100001, 8'b11011010, 8'b11110010, 8'b01100110, 8'b10110110, 8'b10111110, 8'b11100000, 8'b11111110};
parameter CLK_NUM = 500000;
reg [31:0] count;
reg [2:0] out_idx;
reg [2:0] offset;
always @(posedge clk) begin
if(rst) begin count <= 0; out_idx <= 0; offset <= 0; end
else begin
if(count == CLK_NUM) begin offset <= offset + 1; end
count <= (count == CLK_NUM) ? 0 : count + 1;
end
end
assign o_seg1 = ~(segs>> (((offset + 3'd0)&7) * 8));
assign o_seg2 = ~(segs>> (((offset + 3'd1)&7) * 8));
assign o_seg3 = ~(segs>> (((offset + 3'd2)&7) * 8));
assign o_seg4 = ~(segs>> (((offset + 3'd3)&7) * 8));
assign o_seg5 = ~(segs>> (((offset + 3'd4)&7) * 8));
assign o_seg6 = ~(segs>> (((offset + 3'd5)&7) * 8));
assign o_seg7 = ~(segs>> (((offset + 3'd6)&7) * 8));
assign o_seg8 = ~(segs>> (((offset + 3'd7)&7) * 8));
endmodule

View File

@ -11,6 +11,14 @@ VGA_B (VGA_B7, VGA_B6, VGA_B5, VGA_B4, VGA_B3, VGA_B2, VGA_B1, VGA_B0)
ledr (LD15, LD14, LD13, LD12, LD11, LD10, LD9, LD8, LD7, LD6, LD5, LD4, LD3, LD2, LD1, LD0)
sw (SW7, SW6, SW5, SW4, SW3, SW2, SW1, SW0)
seg1 (SEG0A, SEG0B, SEG0C, SEG0D, SEG0E, SEG0F, SEG0G, DEC0P)
seg2 (SEG1A, SEG1B, SEG1C, SEG1D, SEG1E, SEG1F, SEG1G, DEC1P)
seg3 (SEG2A, SEG2B, SEG2C, SEG2D, SEG2E, SEG2F, SEG2G, DEC2P)
seg4 (SEG3A, SEG3B, SEG3C, SEG3D, SEG3E, SEG3F, SEG3G, DEC3P)
seg5 (SEG4A, SEG4B, SEG4C, SEG4D, SEG4E, SEG4F, SEG4G, DEC4P)
seg6 (SEG5A, SEG5B, SEG5C, SEG5D, SEG5E, SEG5F, SEG5G, DEC5P)
seg7 (SEG6A, SEG6B, SEG6C, SEG6D, SEG6E, SEG6F, SEG6G, DEC6P)
seg8 (SEG7A, SEG7B, SEG7C, SEG7D, SEG7E, SEG7F, SEG7G, DEC7P)
ps2_clk PS2_CLK
ps2_data PS2_DAT

View File

@ -10,7 +10,16 @@ module top (
output VGA_BLANK_N,
output [7:0] VGA_R,
output [7:0] VGA_G,
output [7:0] VGA_B
output [7:0] VGA_B,
output [7:0] seg1,
output [7:0] seg2,
output [7:0] seg3,
output [7:0] seg4,
output [7:0] seg5,
output [7:0] seg6,
output [7:0] seg7,
output [7:0] seg8,
output [7:0] an
);
test test1(
@ -46,6 +55,19 @@ ps2_keyboard my_keyboard(
.ps2_data(ps2_data)
);
seg mu_seg(
.clk(clk),
.rst(0),
.o_seg1(seg1),
.o_seg2(seg2),
.o_seg3(seg3),
.o_seg4(seg4),
.o_seg5(seg5),
.o_seg6(seg6),
.o_seg7(seg7),
.o_seg8(seg8)
);
vmem my_vmem(
.h_addr(h_addr),
.v_addr(v_addr[8:0]),

View File

@ -77,4 +77,7 @@ void init_components(SDL_Renderer *renderer);
void delete_components();
#define GET_SEGA(i) (output_pin(int(output_pin::SEG0A) + 8 * i))
#define GET_DECP(i) (output_pin(int(output_pin::SEG0A) + 8 * i + 7))
#endif

View File

@ -20,11 +20,15 @@
#define RGB_LEDS_OUTPUT R16, G16, B16, R17, G17, B17
#define SEG7_ENBS_OUTPUT AN0, AN1, AN2, AN3, \
AN4, AN5, AN6, AN7
#define SEG7_SEGS_OUTPUT SEGA, SEGB, SEGC, SEGD, \
SEGE, SEGF, SEGG, DECP
#define SEG7_SEGS_OUTPUT SEG0A, SEG0B, SEG0C, SEG0D, SEG0E, SEG0F, SEG0G, DEC0P, \
SEG1A, SEG1B, SEG1C, SEG1D, SEG1E, SEG1F, SEG1G, DEC1P, \
SEG2A, SEG2B, SEG2C, SEG2D, SEG2E, SEG2F, SEG2G, DEC2P, \
SEG3A, SEG3B, SEG3C, SEG3D, SEG3E, SEG3F, SEG3G, DEC3P, \
SEG4A, SEG4B, SEG4C, SEG4D, SEG4E, SEG4F, SEG4G, DEC4P, \
SEG5A, SEG5B, SEG5C, SEG5D, SEG5E, SEG5F, SEG5G, DEC5P, \
SEG6A, SEG6B, SEG6C, SEG6D, SEG6E, SEG6F, SEG6G, DEC6P, \
SEG7A, SEG7B, SEG7C, SEG7D, SEG7E, SEG7F, SEG7G, DEC7P
//#define UART_OUTPUT

View File

@ -126,12 +126,8 @@ void SEGS7::update_gui() {
void SEGS7::update_state() {
int newval = 0;
if (output_map[get_output(8)] == 0) {
newval = 0x5555;
} else {
for (int i = 0; i < 8; ++i) {
newval |= (output_map[get_output(i)]) ? (1 << (i << 1)) : (1 << (i << 1 | 1));
}
for (int i = 0; i < 8; ++i) {
newval |= (output_map[get_output(i)]) ? (1 << (i << 1)) : (1 << (i << 1 | 1));
}
if (newval != get_state()) {
set_state(newval);
@ -168,7 +164,7 @@ void init_components(SDL_Renderer *renderer) {
// init buttons
for (int i = 0; i < 6; ++i) {
ptr = new Component(renderer, 2, 0, INPUT_TYPE, BUTTON_TYPE);
// off
rect_ptr = new SDL_Rect;
*rect_ptr = btn_rects[i];
@ -240,10 +236,9 @@ void init_components(SDL_Renderer *renderer) {
ptr->set_rect(rect_ptr, j << 1 | 1);
}
for (output_pin p = output_pin::SEGA; p <= output_pin::DECP; p = output_pin(int(p) + 1)) {
for (output_pin p = GET_SEGA(i); p <= GET_DECP(i); p = output_pin(int(p) + 1)) {
ptr->add_output(p);
}
ptr->add_output(output_pin(int(output_pin::AN0) + i));
components.push_back(ptr);
}