molushali 发表于 2011-3-27 16:17:36

lcd1602程序,自身不能驱动1602,得先下个别的1602程序进去才好使是为什么?

module lcd_1602(
                output reg rs,            //数据命令选择端(H/L)
                outputrw,               //读写选择端(H/L)
                outpute,                //使能信号
                output reg data,   //数据信号
                output led_on,            //背光,高电平开,与vga_vs共用
                input rst_n,clk         //复位,25MHz时钟
               );
        assign rw=1'b0;                          //始终为写状态
        assign e=lcd_clk;                        //使能高脉冲
        assign led_on=1'b1;                     //开背光
                                       
//******时钟模块*********       
//        *******分频********                                               
reg cnt;
always@(posedge clk) begin
        if(!rst_n) cnt<=1'b0;
//        else if(cnt==15'h7fff) cnt<=15'd0;
        else cnt<=cnt+1'b1;
end

wire lcd_clk = cnt;                     // (2^15 / 25M) = 1.31ms

parameter idle =4'b0000;                  //空闲状态

//*********初始化**********
parameter disp =4'b0001;                  //显示模式设置
parameter disp_clr=4'b0011;               //清屏
parameter cursor_set1=4'b0010;            //光标设置
parameter cursor_set2=4'b0110;            //光标设置

parameter write_add =4'b0111;            //起始地址

//***********写数据***********
parameter write=4'b0101;
parameter write2_add=4'b1101;
parameter write1=4'b1111;

reg zifu1_r="ILOVEYOU";
reg zifu2_r="   FOREVER    ";

reg current,next;
reg n,m;

always@(posedge lcd_clk,negedge rst_n) begin
        if(!rst_n) current<=idle;
        else current<=next;
end

alwaysbegin
        case(current)
        idle:         next=disp;
         disp:         next=disp_clr;
        disp_clr:   next=cursor_set1;
        cursor_set1:next=cursor_set2;
        cursor_set2:next=write_add;
        write_add:    next=write;
        write:      begin
                      if(n==15) next=write2_add;
                      else next=write;
                      end
        write2_add:   next=write1;
        write1:       begin
                      if(m==15) next=write_add;
                      else next=write1;
                   end
        endcase
end

always@(posedge lcd_clk,negedge rst_n) begin
       if(!rst_n) begin
            rs   <= 0;         // 写指令
            data <= 8'hxx;
             end
   elsebegin
          case(current)
           idle,disp,cursor_set1,cursor_set2,write_add,write2_add:rs<=1'b0;   //写指令
            write,write1:rs<=1'b1;
           endcase

           case(current)
//*********初始化**********
             disp:         data<=8'h38;         //显示开
                disp_clr:   data<=8'h01;            //清屏指令
             cursor_set1:data<=8'h0f;            //显示开,光标闪烁
             cursor_set2:data<=8'h06;            //地址指针加1,整屏不移动
             write_add:    data<=8'h80;                    // 起始地址
             write:    begin
                      data<=zifu1_r;
                   zifu1_r<={zifu1_r,zifu1_r};
                   n<=n+1'b1;
                       end
             write2_add:data<=8'h80+8'h40;
             write1:begin               
                data<=zifu2_r;
                zifu2_r<={zifu2_r,zifu2_r};
                m<=m+1'b1;   
                    end
             idle: data<=8'hxx;
          endcase
          end
end

       
endmodule

Mr_25 发表于 2011-4-2 12:36:52

我前段时间也碰到过这个问题,可能是初始化的问题。

molushali 发表于 2011-4-10 10:28:07

回复【楼主位】molushali 陌路沙砾
-----------------------------------------------------------------------

嗯,初始化的问题,
cursor_set1:data<=8'h0f;            //显示开,光标闪烁
cursor_set2:data<=8'h06;            //地址指针加1,整屏不移动
要改成cursor_set1:data<=8'h06;         
      cursor_set2:data<=8'h0f;      
这样就好使了
页: [1]
查看完整版本: lcd1602程序,自身不能驱动1602,得先下个别的1602程序进去才好使是为什么?