Skip to content

Instantly share code, notes, and snippets.

@yellowcrescent
Created June 2, 2018 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yellowcrescent/35a397c35618c9298fa9ef09bf3d0fa5 to your computer and use it in GitHub Desktop.
Save yellowcrescent/35a397c35618c9298fa9ef09bf3d0fa5 to your computer and use it in GitHub Desktop.
lcd blinky example in verilog
`timescale 1ps / 1ps
module lcd_clock (
input wire clk,
input wire rst,
output reg pulse
);
parameter clk_freq = 26'd12000000; // X1 = 12MHz
parameter lcd_freq = 26'd4000; // target output frequency * 2 (2KHz = 4000)
reg [25:0] clk_div;
always @ (posedge clk or posedge rst)
if (rst) begin
clk_div <= 0;
pulse <= 0;
end else begin
if (clk_div >= clk_freq/lcd_freq) begin
clk_div <= 0;
pulse <= ~pulse;
end else begin
clk_div <= clk_div + 1;
end
end
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment