// 交通信号機のステートマシン module traffic_lights( clock, reset ); input clock, reset; reg [1:0] light; reg [3:0] cntr, cycle; // 状態の定義 parameter red = 'b00, blue = 'b01, yellow = 'b10, black = 'b11; // 各状態の持続時間 parameter REDcount = 'h7, BLUEcount = 'h5, YELLOWcount= 'h1, BLINKcount = 'h5, CYCLEcount = 'h2; // ステートマシンの定義 always @(posedge clock ) if ( reset ) begin light <= red; // 初期値は赤 cntr <= REDcount; // 赤の時間をセット cycle <= CYCLEcount; // 点滅状態に入るまでの赤青黄のサイクル数をセット end else case (light) red: begin // ライトが赤の時 if ( cntr == 0 & cycle != 0 ) begin // light <= ????? ; // cntr <= ????? ; end else if ( cycle == 0 ) // light <= ????? ; else // cntr <= ?????; end blue: begin // ライトが青の時 if ( cntr == 0 ) begin light <= yellow; cntr <= YELLOWcount; end else cntr <= cntr-1; end yellow: begin // ライトが黄の時 if ( cntr == 0 ) begin light <= red; cycle <= cycle -1; if ( cycle == 1 ) // cntr <= ?????; else // cntr <= ?????; end else cntr <= cntr-1; end black: begin // ライトが消灯の時 // light <= ????? ; if ( cntr == 0 ) begin // cntr <= ?????; // cycle <= ?????; end else // cntr <= ?????; end default: begin light <= red; // 変な状態は赤へ cntr <= REDcount; cycle <= CYCLEcount; end endcase endmodule