|
凌陽FPGA實驗程序,包含分頻,交通燈源碼
0.png (53.47 KB, 下載次數: 37)
下載附件
2018-4-1 02:11 上傳
單片機源程序如下:
- module traffic(CLK,EN,LAMPA,LAMPB,ACOUNT,BCOUNT);
- output[7:0] ACOUNT,BCOUNT;
- output[2:0] LAMPA,LAMPB;//lampa[2],lampa[1],lamp[0]as the red,green,yellow
- //lampb[2],lampb[1],lamp[0]--red,green,yellow
- input CLK,EN;//clk and enable(high is efficient)
- reg[7:0] numa,numb;
- reg tempa,tempb;
- reg[2:0] counta,countb;
- reg[7:0] ared,ayellow,agreen,bred,byellow,bgreen;
- reg[2:0] LAMPA,LAMPB;
- always @(EN)
- if(!EN)
- begin
- ared<=8'b01000101;
- ayellow<=8'b00000101;
- agreen<= 8'b01000000;
- bred<=8'b01000101;
- byellow<=8'b00000101;
- bgreen<=8'b01000000;
- end
- assign ACOUNT=numa;
- assign BCOUNT=numb;
- always @(posedge CLK)
- begin
- if(EN)
- begin
- if(!tempa)
- begin
- tempa<=1;
- case(counta)
- 0: begin numa<=ared; LAMPA<=3'b100; counta<=1; end
- 1: begin numa<=agreen; LAMPA<=3'b010; counta<=2; end
- 2: begin numa<=ayellow; LAMPA<=3'b001; counta<=0; end
- default: LAMPA<=3'b100;
- endcase
- end
- else begin
- if(numa>1)
- if(numa[3:0]==0) begin
- numa[3:0]<=4'b1001;
- numa[7:4]<=numa[7:4]-1;
- end
- else numa[3:0]<=numa[3:0]-1;
- if (numa==2) tempa<=0;
- end
- end
- else begin
- LAMPA<=3'b100;
- counta<=0; tempa<=0;
- end
- end
- always @(posedge CLK)
- begin
- if (EN)
- begin
- if(!tempb)
- begin
- tempb<=1;
- case (countb)
- 0: begin numb<=bgreen; LAMPB<=3'b010; countb<=1; end
- 1: begin numb<=byellow; LAMPB<=3'b001; countb<=2; end
- 2: begin numb<=bred; LAMPB<=3'b100; countb<=0; end
- default: LAMPB<=3'b010;
- endcase
- end
- else
- begin
- if(numb>1)
- if(!numb[3:0]) begin
- numb[3:0]<=9;
- numb[7:4]<=numb[7:4]-1;
- end
- else numb[3:0]<=numb[3:0]-1;
- if(numb==2) tempb<=0;
- end
- end
- else begin
- LAMPB<=3'b010;
- tempb<=0; countb<=0;
- end
- end
- endmodule
復制代碼
|
-
-
交通燈Verilog.zip
2018-3-31 22:53 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
1.36 MB, 下載次數: 31, 下載積分: 黑幣 -5
|