三段式状态机VGA显示程序及仿真

三段式状态机VGA显示程序及仿真 module vgas(iclk,oclk,rst,valid_r,sync,datacolor,H_sync,V_sync);input iclk,rst;output oclk;output valid_r;output sync;output [23:0]datacolor;output H_sync;output V_sync...
摘要由CSDN通过智能技术生成

三段式状态机VGA显示程序及仿真
module vgas(iclk,oclk,rst,valid_r,sync,datacolor,H_sync,V_sync);

input iclk,rst;

output oclk;

output valid_r;

output sync;

output [23:0]datacolor;

output H_sync;

output V_sync;

reg [15:0] hcount=0;

reg [15:0] vcount=0;

reg [3:0] hstate;

reg [3:0] vstate;

reg [3:0] h_nextstate;

reg [3:0] v_nextstate;

reg H_sync;

reg V_sync;

//reg valid;

reg [23:0] color;

reg [7:0] R;

reg [7:0] G;

reg [7:0] B;

wire [23:0] datacolor;

wire valid_r;

parameter a=4’b1000,

      b=4'b0100,

c=4’b0010,

d=4’b0001,

h=4’b1000,

      i=4'b0100,

j=4’b0010,

k=4’b0001;

always@(posedge clk )

begin

if(hcount==16’d799)

hcount<=0;

else

hcount<=hcount+1;

end

//列计数

always@(posedge clk )

 begin

if((vcount==16’d524)&&(hcount==16’d799))

vcount<=0;

else if(hcount==16’d799)

vcount<=vcount+1;

 end

//行状态迁移

always @(posedge clk) begin

if(!rst)

hstate<=a;

else

hstate<=h_nextstate;

end

always @(*) begin

   h_nextstate=a;

case(hstate)

a: begin

if(hcount>95)

h_nextstate=b;

else

h_nextstate=a;

end

b: begin

if(hcount>142)

h_nextstate=c;

else

h_nextstate=b;

end

c: begin

if(hcount>782)

h_nextstate=d;

else

h_nextstate=c;

end

d: begin

if(hcount>798)

h_nextstate=a;

else

h_nextstate=d;

end

default:h_nextstate=a;

endcase

end

///描述次态寄存器输出

always @(posedge clk) begin

case(h_nextstate)

a: H_sync<=0;

b: H_sync<=1;

c: H_sync<=1;

     d: H_sync<=1;

    default:H_sync<=h;

endcase

end

//场状态迁移

always @(posedge clk) begin

if(!rst)

vstate<=h;

else

vstate<=v_nextstate;

end

always @(*) begin

   v_nextstate=h;

case(vstate)

h: begin

if(vcount>0)

v_nextstate=i;

else

v_nextstate=h;

end

i: begin

if(vcount>33)

v_nextstate=j;

else

v_nextstate=i;

end

j: begin

if(vcount>513)

v_nextstate=k;

else

v_nextstate=j;

end

k: begin

if(vcount>523)

v_nextstate=h;

else

v_nextstate=k;

end

default:v_nextstate=h;

endcase

end

//

always @(posedge clk) begin

case(v_nextstate)

h: V_sync<=0;

i: V_sync<=1;

j: V_sync<=1;

     k: V_sync<=1;

    default:V_sync<=0;

endcase

end

assign valid_r=H_sync&V_sync;

always @(posedge clk) begin

if(valid_r)

begin

if((hcount>143)&&(hcount<=223)) color<=24’h111111;

if((hcount>223)&&(hcount<=303)) color<=24’h101111;

if((hcount>303)&&(hcount<=383)) color<=24’h110111;

if((hcount>383)&&(hcount<=463)) color<=24’h111100;

if((hcount>463)&&(hcount<=543)) color<=24’h111110;

if((hcount>543)&&(hcount<=623)) color<=24’h011101;

if((hcount>623)&&(hcount<=703)) color<=24’h110011;

if((hcount>703)&&(hcount<=783)) color<=24’h111100;

end

else color<=24’h000000;

end

assign datacolor=color;

assign sync=1;

vgascore instance_name

(// Clock in ports

.CLK_IN1(iclk),      // IN

// Clock out ports

.CLK_OUT1(clk),     // OUT

.CLK_OUT2(CLK_OUT_NON));    // OUT

// INST_TAG_END —— End INSTANTIATION Template ———

ODDR2 #(

  .DDR_ALIGNMENT("NONE"), // Sets output alignment to "NONE", "C0" or "C1" 

  .INIT(1'b0),    // Sets initial state of the Q output to 1'b0 or 1'b1

  .SRTYPE("SYNC") // Specifies "SYNC" or "ASYNC" set/reset

)

ODDR2_inst (

  .Q(oclk),   // 1-bit DDR output data

  .C0(CLK_OUT_NON),   // 1-bit clock input

  .C1(~CLK_OUT_NON),   // 1-bit clock input

  .CE(1'b1), // 1-bit clock enable input

  .D0(1'b1), // 1-bit data input (associated with C0)

  .D1(1'b0), // 1-bit data input (associated with C1)

  .R(1'b0),   // 1-bit reset input

  .S(1'b0)    // 1-bit set input

);

// End of ODDR2_inst instantiation

endmodule

仿真程序如下:

module vgatesttwo;

// Inputs

reg iclk;

reg rst;

// Outputs

wire oclk;

wire valid_r;

wire sync;

wire [23:0] datacolor;

wire H_sync;

wire V_sync;

// Instantiate the Unit Under Test (UUT)

vgas uut (

.iclk(iclk),

.oclk(oclk),

.rst(rst),

.valid_r(valid_r),

.sync(sync),

.datacolor(datacolor),

.H_sync(H_sync),

.V_sync(V_sync)

);

initial begin

// Initialize Inputs

iclk = 0;

rst = 0;

// Wait 100 ns for global reset to finish

100;

// Add stimulus here

 #5 rst=1;

end

 always 

#5 iclk<=!iclk;

endmodule

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值