⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd_init.v

📁 基于ALTERA公司的DE2的LCD显示程序
💻 V
📖 第 1 页 / 共 2 页
字号:

        [Wait more than 100us]

RS  R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0  Can't check BF before this instruction
 0   0   0   0   1   1   *   *   *   *   Function set (8-bit interface)

                                         BF can be checked after the following
                                         instructions. When BF is not checked,
                                         the waiting time between instructions
                                         is longer than the execution time.
                                         (See Instruction set)

RS  R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
 0   0   0   0   1   1   N   F   *   *   Function set  [8-bit Interface      ]
                                                       [Specify display lines]
RS  R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0                [and character font   ]
 0   0   0   0   0   0   1   0   0   0   Display OFF    These cannot be
                                                        changed afterwards
RS  R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
 0   0   0   0   0   0   0   0   0   1   Display ON

RS  R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
 0   0   0   0   0   0   0   1  I/D  S   entry mode set

        [end of initialisation]


When interface is 4-bits wide 
        [Power ON]

[  Wait more than 15ms  ]
[after Vdd rises to 4.5v]

RS  R/W DB7 DB6 DB5 DB4  Can't check BF before this instruction
 0   0   0   0   1   1   Function set (8-bit interface)

    [Wait more than]
    [     4.1ms    ]

RS  R/W DB7 DB6 DB5 DB4  Can't check BF before this instruction
 0   0   0   0   1   1   Function set (8-bit interface)

    [Wait more than]
    [     100us    ]

RS  R/W DB7 DB6 DB5 DB4  Can't check BF before this instruction
 0   0   0   0   1   1   Function set (8-bit interface)

                         BF can be checked after the following
                         instructions. When BF is not checked,
                         the waiting time between instructions
                         is longer than the execution time.
                         (See Instruction set)

RS  R/W DB7 DB6 DB5 DB4
 0   0   0   0   1   0   Function set (to 4-bit interface)

RS  R/W DB7 DB6 DB5 DB4
 0   0   0   0   1   0
 0   0   N   F   *   *   Function set  [4-bit Interface      ]
                                       [Specify display lines]
RS  R/W DB7 DB6 DB5 DB4                [and character font   ]
 0   0   0   0   0   0                  These cannot be
 0   0   1   0   0   0   Display OFF    changed afterwards
                                        
RS  R/W DB7 DB6 DB5 DB4
 0   0   0   0   0   0   
 0   0   0   0   0   1   Display ON

RS  R/W DB7 DB6 DB5 DB4 
 0   0   0   0   0   0   
 0   0   0   1  I/D  S   entry mode set

[end of initialisation]


----------------------------------------------------*/
module LCD_init ( clk_50Hz,rst,Start_init,LCD_Data_In,
                 Finish_init,LCD_RS,LCD_E,
                 LCD_Data_Out, );
	input  clk_50Hz,rst;
	input  Start_init;                   //1:active
	input [7:0]LCD_Data_In;              //LCD input data from controller
	output Finish_init;                  //1:active
  output LCD_RS;                       //0:Instruction;1:data
  output LCD_E;                        //posedge work
 	output [7:0] LCD_Data_Out;           //LCD output data 
	
	reg [7:0] LCD_Data_Out_buf;
	//reg Start_init;
	//wire Start_init;
	reg Finish_init;
	reg LCD_E;
	reg LCD_RS;
//-------------instruction patameter set-----------------	
	parameter  Func_sel = 8'h38,   //显示模式设置
	           Disp_on  = 8'h0f,   //开显示和光标
	           Clr_disp = 8'h01;   //显示清屏
//--generate 1-shot statemachine for initial instruction--	        
	reg [4:0] state;        
	parameter	 LCD_Func = 5'b00001,       //发送模式设置指令
	           LCD_Disp = 5'b00010,       //发送开显示和光标指令
	           LCD_Clr  = 5'b00100,       //发送清屏指令
	           Idle     = 5'b01000,
	           LCD_Wr   = 5'b10000;
	//parameter  A = 8'h40;           
	//assign LCD_RW = 1'b0;           
  //assign Start_init = 1'b1;
	always @ (posedge clk_50Hz)
	  begin 
	  	if(!rst)
	    begin 
	  	state       <= Idle;
	  	Finish_init <= 1'b0;
	  	LCD_E       <= 1'b0;
	    LCD_RS      <= 1'b0;
			end
	    else if (Start_init)
	    case (state)
	    	Idle:   begin
	                if (Start_init) 
	                     begin
	    	      	      state <= LCD_Func;
	                      LCD_RS <= 1'b0;
	                     end
	    		        else state <= Idle;
	              end
	      LCD_Func: begin
	               if (Start_init&LCD_E )
	                   begin
	                   LCD_E  <= 1'b0;
	                   LCD_RS <= 1'b0;
	                   end
	               else if(!LCD_E)
	                  begin
	      	          state        <= LCD_Disp;
	      	          LCD_E        <= 1'b1; 
	                  LCD_RS       <= 1'b0;     	        
	      	          LCD_Data_Out_buf <= Func_sel;
	      	          end
	      	        else state <= Idle;
	                end
	      LCD_Disp: begin
	                 if (Start_init&LCD_E )
	                   begin
	                   LCD_E  <= 1'b0;
	                   LCD_RS <= 1'b0;
	                   end
	                else if (!LCD_E)
	                  begin
	      	          state        <= LCD_Clr;
	      	          LCD_E        <= 1'b1;
	                  LCD_RS       <= 1'b0;
	      	          LCD_Data_Out_buf <= Disp_on;
	      	          end	
	      	        else state <= Idle;  
	               end      
	    	LCD_Clr :begin
	                 if (Start_init&LCD_E )
	                   begin
	                   LCD_E  <= 1'b0;
	                   LCD_RS <= 1'b0;
	                   end
	                 else if (!LCD_E)
	                  begin
	      	          state            <= LCD_Wr;
	      	          LCD_E            <= 1'b1;
	                  LCD_RS           <= 1'b0;
	      	          LCD_Data_Out_buf <= Clr_disp;
	      	          Finish_init      <= 1'b1;	      	          
	      	         end	
	      	        else state <= Idle;
	               end
	       LCD_Wr : begin 
	      	         if (Start_init&Finish_init&LCD_E)
	      	           begin
	      	           	LCD_E  <= 1'b0;
	      	           	LCD_RS <= 1'b1; 
	      	          end
	      	          else if (!LCD_E)
	      	            begin 
	      	            	state            <= LCD_Wr;
	      	            	LCD_E            <= 1'b1;
	                      LCD_RS           <= 1'b1;
	      	              LCD_Data_Out_buf <= LCD_Data_In; 
	      	            end 
	                  else state <= Idle;
	      	          end  
	      default : state <= Idle;
	    endcase
	    
	    else   state       <= Idle;
	      
	  end	
	  
	  assign LCD_Data_Out = LCD_Data_Out_buf ;            
  
endmodule	          
	          
	          
	          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -