Basys 3 ASCII terminal: VGA 80x30 text, USB keyboard, UART

- VGA 640x480@60 text display, 8x16 CP437 font ROM from Linux console fonts
- USB HID keyboard (PS/2 via onboard PIC24), scan code set 2 to ASCII
  with xterm sequences for cursor/editing keys
- UART RX/TX with switch-selectable baud, local echo option
- Terminal engine: control codes, deferred wrap, hardware scroll,
  VT100/ANSI subset (cursor moves, erase, reverse video, cursor hide)
- Vivado build/program/flash scripts and xsim whole-design testbench

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
barantandClaude Opus 5.5 committed 2026-11-17 10:26:13 -08:00
commit 0e95a14cfe
18 files changed
+5596

No files matched your search

+106
View File
@@ -0,0 +1,106 @@
`timescale 1ns / 1ps
// 8N1 UART receiver and transmitter. div = clock frequency / baud rate.
module uart_rx (
input clk,
input rst,
input [13:0] div,
input rx,
output reg [7:0] data,
output reg valid
);
localparam IDLE = 3'd0, START = 3'd1, DATA = 3'd2, STOP = 3'd3, BREAK = 3'd4;
reg [2:0] sync = 3'b111;
reg [2:0] st;
reg [13:0] cnt;
reg [2:0] bitn;
reg [7:0] sh;
wire rxs = sync[2];
always @(posedge clk) sync <= {sync[1:0], rx};
always @(posedge clk) begin
valid <= 1'b0;
if (rst) begin
st <= IDLE;
end else case (st)
IDLE:
if (!rxs) begin
st <= START;
cnt <= {1'b0, div[13:1]}; // sample mid-bit
end
START:
if (cnt == 0) begin
if (!rxs) begin
st <= DATA;
cnt <= div - 1'b1;
bitn <= 3'd0;
end else
st <= IDLE; // glitch, not a start bit
end else
cnt <= cnt - 1'b1;
DATA:
if (cnt == 0) begin
sh <= {rxs, sh[7:1]};
cnt <= div - 1'b1;
bitn <= bitn + 1'b1;
if (bitn == 3'd7) st <= STOP;
end else
cnt <= cnt - 1'b1;
STOP:
if (cnt == 0) begin
if (rxs) begin
data <= sh;
valid <= 1'b1;
st <= IDLE;
end else
st <= BREAK; // bad stop bit: drop it
end else
cnt <= cnt - 1'b1;
BREAK:
if (rxs) st <= IDLE; // wait for the line to go idle
default:
st <= IDLE;
endcase
end
endmodule
module uart_tx (
input clk,
input rst,
input [13:0] div,
input [7:0] data,
input start,
output reg tx = 1'b1,
output reg busy
);
reg [9:0] sh;
reg [3:0] n;
reg [13:0] cnt;
always @(posedge clk) begin
if (rst) begin
tx <= 1'b1;
busy <= 1'b0;
end else if (!busy) begin
if (start) begin
sh <= {1'b1, data, 1'b0};
n <= 4'd0;
cnt <= 14'd0;
busy <= 1'b1;
end
end else if (cnt == 0) begin
if (n == 4'd10)
busy <= 1'b0;
else begin
tx <= sh[0];
sh <= {1'b1, sh[9:1]};
n <= n + 1'b1;
cnt <= div - 1'b1;
end
end else
cnt <= cnt - 1'b1;
end
endmodule