////////////////////////////////////////////////////////////////////////////////// // Author: lsilvest // // Create Date: 02/02/2008 // // Module Name: lcd_display // // Target Devices: Altera DE2 // // Tool versions: Quartus II 7.2 Web Edition // // Description: This LCD module provides the capability to write // a command or a character to the display. // // This module makes it easy to generate the init // sequence and various writing to the LCD display. Note // that it does not handle reads. // // //////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2008 Authors // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. ///////////////////////////////////////////////////////////////////////////////// module lcd_display (input clk, input rst, output lcd_e, output lcd_rw, output lcd_rs, output [7:0] lcd_d, input [7:0] if_data, input if_rs, input [31:0] if_delay, input if_write, output if_ready); reg [1:0] state; reg lcdr_e; reg [31:0] wait_cntr; reg ready; reg init_done; parameter IDLE = 2'b00, WAIT_PULSE_E = 2'b01, WAIT_COMMAND = 2'b10; parameter PULSE_E_DLY = 32'd12; parameter INIT_TIME = 32'd10000000; assign lcd_d = if_data; assign lcd_rs = if_rs; assign lcd_rw = 1'b0; assign lcd_e = lcdr_e; assign if_ready = ready; initial begin state <= IDLE; ready <= 1'b0; lcdr_e <= 1'b0; init_done <= 1'b0; end always@ (posedge clk) begin if (rst) begin state <= IDLE; end else if (!init_done) begin if (wait_cntr < INIT_TIME) wait_cntr <= wait_cntr + 1; else begin init_done <= 1'b1; ready <= 1'b1; end end else begin case (state) IDLE: begin if (if_write) begin lcdr_e <= 1'b1; ready <= 1'b0; wait_cntr <= 32'b0; state <= WAIT_PULSE_E; end end WAIT_PULSE_E: if (wait_cntr < PULSE_E_DLY) begin wait_cntr <= wait_cntr + 1; end else begin lcdr_e <= 1'b0; wait_cntr <= 0; state <= WAIT_COMMAND; end WAIT_COMMAND: if (wait_cntr < if_delay) begin wait_cntr <= wait_cntr + 32'b1; end else begin wait_cntr <= 0; if (!if_write) begin state <= IDLE; ready <= 1'b1; end end endcase // case (state) end end endmodule