🌵🌵🌵前言
✨你好啊,我是“ 怪& ”,是一名在校大学生哦。
🌍主页链接:怪&的个人博客主页
☀️博文主更方向为:课程学习知识、作业题解、期末备考。随着专业的深入会越来越广哦…一起期待。
❤️一个“不想让我曾没有做好的也成为你的遗憾”的博主。
💪很高兴与你相遇,一起加油!
一、题目
FPGA交通信号灯的设计
二、功能介绍
1、30秒绿灯倒计时+30秒红灯倒计时。
2、倒计时最后5秒计时每半秒(闪烁)。
3、在HEX7、HEX6显示倒计时数字。
4、可显示十字路口红绿灯的情况(东西南北)。
5、可通过KEY[0]重置信号从初始状态重新开始。
6、在HEX3、HEX2有南北方向通行/禁止通行的信号指示。
7、在HEX1、HEX0有东西方向通行/禁止通行的信号指示。
8、在南北信号灯为红灯时,在LEDR17、LEDR16、LEDR15、LEDR14、LEDR13、LEDR12有红灯的多路彩灯指示。(从左往右依次增多、从右往左依次增多、全明、全暗交替等)
9、在东西信号灯为绿灯时,在LEDG6、LEDG5、LEDG4、LEDG3、LEDG2、LEDG1有绿灯的多路彩灯指示。(从左往右依次增多、从右往左依次增多、全明、全暗交替等)
10、可通过SW[0]使南北信号灯持续为红灯,东西信号灯持续为绿灯。(应对突发情况,例如救护车通行、警察执行任务等,调整操作后可继续依次执行)
11、可通过SW[1]使南北信号灯持续为绿灯,东西信号灯持续为红灯。(应对突发情况,例如救护车通行、警察执行任务等,调整操作后可继续依次执行)
12、可通过SW[2]使南、北、东、西信号灯维持不变,调整操作后可继续依次执行。
三、视频展示
(正在审核,稍后呈现)
四、代码展示
module Traffic_Light(clk,clr,EastAndWest_to_red,EastAndWest_to_green,keep,out_rg,out_num,NorthAndSouth_Red_color,EastAndWest_Green_color);
(*chip_pin="Y2"*)input clk; //时钟信号
(*chip_pin="M23"*)input clr; //清零信号
(*chip_pin="AB28"*)input EastAndWest_to_red; //如果开关sw0为1,使东西走向的信号灯一直变为红
(*chip_pin="AC28"*)input EastAndWest_to_green; //如果开关sw1为1,使东西走向的信号灯一直变为红
(*chip_pin="AC27"*)input keep; //如果开关sw2为1,维持
(*chip_pin="F17,H16,G19,G21"*)output reg[3:0] out_rg; //红绿灯信号
(*chip_pin= "AD17,AE17,AG17,AH17,AF17,AG18,AA14,AA17,AB16,AA16,AB17,AB15,AA15,AC17,V21,U21,AB20,AA21,AD24,AF23,Y19,AA25,AA26,Y25,W26,Y26,W27,W28,M24,Y22,W21,W22,W25,U23,U24,G18,F22,E17,L26,L25,J22,H22"*)output reg[41:0] out_num; //2数字的计数信号+4个位置的交通指示信号
(*chip_pin="H15,G16,G15,F15,H17,J16"*)output reg[5:0] NorthAndSouth_Red_color; //南北红灯的彩灯
(*chip_pin="G22,G20,H21,E24,E25,E22"*)output reg[5:0] EastAndWest_Green_color; //东西绿灯的彩灯
reg clk_half_1s;//分频至1s
reg [64:0]count;
parameter s1=1,s2=2,s3=3,s4=4,s5=5,s6=6,s7=7,s8=8,s9=9,s10=10,
s11=11,s12=12,s13=13,s14=14,s15=15,s16=16,s17=17,s18=18,s19=19,s20=20,
s21=21,s22=22,s23=23,s24=24,s25=25,s26=26,s27=27,s28=28,s29=29,s30=30,
s31=31,s32=32,s33=33,s34=34,s35=35,s36=36,s37=37,s38=38,s39=39,s40=40,
s41=41,s42=42,s43=43,s44=44,s45=45,s46=46,s47=47,s48=48,s49=49,s50=50,
s51=51,s52=52,s53=53,s54=54,s55=55,s56=56,s57=57,s58=58,s59=59,s60=60,
s61=61,s62=62,s63=63,s64=64,s65=65,s66=66,s67=67,s68=68,s69=69,s70=70,
s71=71,s72=72,s73=73,s74=74,s75=75,s76=76,s77=77,s78=78,s79=79,s80=80,
s81=81,s82=82,s83=83,s84=84,s85=85,s86=86,s87=87,s88=88,s89=89,s90=90,
s91=91,s92=92,s93=93,s94=94,s95=95,s96=96,s97=97,s98=98,s99=99,s100=100,
s101=101,s102=102,s103=103,s104=104,s105=105,s106=106,s107=107,s108=108,s109=109,s110=110,
s111=111,s112=112,s113=113,s114=114,s115=115,s116=116,s117=117,s118=118,s119=119,s120=120;
localparam //---------------------------------- 作为局部常量 --------------------------------
zero =7'b0000001, //0
one =7'b1001111, //1
two =7'b0010010, //2
three =7'b0000110, //3
four =7'b1001100, //4
five =7'b0100100, //5
six =7'b0100000, //6
seven =7'b0001111, //7
eight =7'b0000000, //8
nine =7'b0000100, //9
wron =7'b0000111, //错号的左半部分
wrong =7'b0110001, //错号的右半部分
dark =7'b1111111, //七位数码管的暗
color_1 =6'b000000, //暗暗暗暗暗暗
color_2 =6'b100000, //亮暗暗暗暗暗
color_3 =6'b110000, //亮亮暗暗暗暗
color_4 =6'b111000, //亮亮亮暗暗暗
color_5 =6'b111100, //亮亮亮亮暗暗
color_6 =6'b111110, //亮亮亮亮亮暗
color_7 =6'b111111, //亮亮亮亮亮亮
color_8 =6'b000000, //暗暗暗暗暗暗
color_9 =6'b000001, //暗暗暗暗暗亮
color_10 =6'b000011, //暗暗暗暗亮亮
color_11 =6'b000111, //暗暗暗亮亮亮
color_12 =6'b001111, //暗暗亮亮亮亮
color_13 =6'b011111, //暗亮亮亮亮亮
color_14 =6'b111111; //亮亮亮亮亮亮
reg [6:0]cs,ns; //定义现态和下一时态
always @(posedge clk) //-----------------------------------------分频至0.5s---------------------------------
begin
if(count=='d12499999)
begin
count<=0;
clk_half_1s<=~clk_half_1s;
end
else
count<=count+1;
end
always @(posedge clk_half_1s, negedge clr,posedge EastAndWest_to_red, posedge EastAndWest_to_green,posedge keep )
begin
if(~clr) cs=s1;
else if(EastAndWest_to_red) cs=s61;
else if(EastAndWest_to_green) cs=s1;
else if(keep) cs=cs;
else cs=ns;
end
always @(cs) //定义下一时态ns
begin
case (cs)
s1:ns=s2;
s2:ns=s3;
s3:ns=s4;
s4:ns=s5;
s5:ns=s6;
s6:ns=s7;
s7:ns=s8;
s8:ns=s9;
s9:ns=s10;
s10:ns=s11;
s11:ns=s12;
s12:ns=s13;
s13:ns=s14;
s14:ns=s15;
s15:ns=s16;
s16:ns=s17;
s17:ns=s18;
s18:ns=s19;
s19:ns=s20;
s20:ns=s21;
s21:ns=s22;
s22:ns=s23;
s23:ns=s24;
s24:ns=s25;
s25:ns=s26;
s26:ns=s27;
s27:ns=s28;
s28:ns=s29;
s29:ns=s30;
s30:ns=s31;
s31:ns=s32;
s32:ns=s33;
s33:ns=s34;
s34:ns=s35;
s35:ns=s36;
s36:ns=s37;
s37:ns=s38;
s38:ns=s39;
s39:ns=s40;
s40:ns=s41;
s41:ns=s42;
s42:ns=s43;
s43:ns=s44;
s44:ns=s45;
s45:ns=s46;
s46:ns=s47;
s47:ns=s48;
s48:ns=s49;
s49:ns=s50;
s50:ns=s51;
s51:ns=s52;
s52:ns=s53;
s53:ns=s54;
s54:ns=s55;
s55:ns=s56;
s56:ns=s57;
s57:ns=s58;
s58:ns=s59;
s59:ns=s60;
s60:ns=s61;
s61:ns=s62;
s62:ns=s63;
s63:ns=s64;
s64:ns=s65;
s65:ns=s66;
s66:ns=s67;
s67:ns=s68;
s68:ns=s69;
s69:ns=s70;
s70:ns=s71;
s71:ns=s72;
s72:ns=s73;
s73:ns=s74;
s74:ns=s75;
s75:ns=s76;
s76:ns=s77;
s77:ns=s78;
s78:ns=s79;
s79:ns=s80;
s80:ns=s81;
s81:ns=s82;
s82:ns=s83;
s83:ns=s84;
s84:ns=s85;
s85:ns=s86;
s86:ns=s87;
s87:ns=s88;
s88:ns=s89;
s89:ns=s90;
s90:ns=s91;
s91:ns=s92;
s92:ns=s93;
s93:ns=s94;
s94:ns=s95;
s95:ns=s96;
s96:ns=s97;
s97:ns=s98;
s98:ns=s99;
s99:ns=s100;
s100:ns=s101;
s101:ns=s102;
s102:ns=s103;
s103:ns=s104;
s104:ns=s105;
s105:ns=s106;
s106:ns=s107;
s107:ns=s108;
s108:ns=s109;
s109:ns=s110;
s110:ns=s111;
s111:ns=s112;
s112:ns=s113;
s113:ns=s114;
s114:ns=s115;
s115:ns=s116;
s116:ns=s117;
s117:ns=s118;
s118:ns=s119;
s119:ns=s120;
s120:ns=s1;
default:ns=s1;
endcase
end
always @(cs)
begin
case(cs)
s1: begin out_num={three,zero,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s2: begin out_num={three,zero,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s3: begin out_num={two,nine,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s4: begin out_num={two,nine,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s5: begin out_num={two,eight,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s6: begin out_num={two,eight,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s7: begin out_num={two,seven,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s8: begin out_num={two,seven,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s9: begin out_num={two,six,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s10: begin out_num={two,six,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s11: begin out_num={two,five,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s12: begin out_num={two,five,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s13: begin out_num={two,four,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s14: begin out_num={two,four,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s15: begin out_num={two,three,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s16: begin out_num={two,three,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s17: begin out_num={two,two,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s18: begin out_num={two,two,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s19: begin out_num={two,one,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s20: begin out_num={two,one,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s21: begin out_num={two,zero,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s22: begin out_num={two,zero,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s23: begin out_num={one,nine,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s24: begin out_num={one,nine,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s25: begin out_num={one,eight,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s26: begin out_num={one,eight,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s27: begin out_num={one,seven,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s28: begin out_num={one,seven,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s29: begin out_num={one,six,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s30: begin out_num={one,six,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s31: begin out_num={one,five,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s32: begin out_num={one,five,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s33: begin out_num={one,four,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s34: begin out_num={one,four,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s35: begin out_num={one,three,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s36: begin out_num={one,three,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s37: begin out_num={one,two,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s38: begin out_num={one,two,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s39: begin out_num={one,one,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s40: begin out_num={one,one,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s41: begin out_num={one,zero,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s42: begin out_num={one,zero,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s43: begin out_num={zero,nine,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s44: begin out_num={zero,nine,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s45: begin out_num={zero,eight,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s46: begin out_num={zero,eight,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s47: begin out_num={zero,seven,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s48: begin out_num={zero,seven,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s49: begin out_num={zero,six,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s50: begin out_num={zero,six,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s51: begin out_num={zero,five,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s52: begin out_num={zero,five,dark,dark,dark,dark}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0000;end
s53: begin out_num={zero,four,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s54: begin out_num={zero,four,dark,dark,dark,dark}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0000;end
s55: begin out_num={zero,three,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s56: begin out_num={zero,three,dark,dark,dark,dark}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0000;end
s57: begin out_num={zero,two,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s58: begin out_num={zero,two,dark,dark,dark,dark}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0000;end
s59: begin out_num={zero,one,six,zero,wron,wrong}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b1010;end
s60: begin out_num={zero,one,dark,dark,dark,dark}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0000;end
s61: begin out_num={three,zero,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0101; end
s62: begin out_num={three,zero,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_2,color_2}; out_rg=4'b0101; end
s63: begin out_num={two,nine,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_3,color_3}; out_rg=4'b0101; end
s64: begin out_num={two,nine,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_4,color_4}; out_rg=4'b0101; end
s65: begin out_num={two,eight,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_5,color_5}; out_rg=4'b0101; end
s66: begin out_num={two,eight,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_6,color_6}; out_rg=4'b0101; end
s67: begin out_num={two,seven,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_7,color_7}; out_rg=4'b0101; end
s68: begin out_num={two,seven,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_8,color_8}; out_rg=4'b0101; end
s69: begin out_num={two,six,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_9,color_9}; out_rg=4'b0101; end
s70: begin out_num={two,six,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_10,color_10}; out_rg=4'b0101; end
s71: begin out_num={two,five,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_11,color_11}; out_rg=4'b0101; end
s72: begin out_num={two,five,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_12,color_12}; out_rg=4'b0101; end
s73: begin out_num={two,four,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_13,color_13}; out_rg=4'b0101; end
s74: begin out_num={two,four,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_14,color_14}; out_rg=4'b0101; end
s75: begin out_num={two,three,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0101; end
s76: begin out_num={two,three,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_2,color_2}; out_rg=4'b0101; end
s77: begin out_num={two,two,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_3,color_3}; out_rg=4'b0101; end
s78: begin out_num={two,two,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_4,color_4}; out_rg=4'b0101; end
s79: begin out_num={two,one,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_5,color_5}; out_rg=4'b0101; end
s80: begin out_num={two,one,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_6,color_6}; out_rg=4'b0101; end
s81: begin out_num={two,zero,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_7,color_7}; out_rg=4'b0101; end
s82: begin out_num={two,zero,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_8,color_8}; out_rg=4'b0101; end
s83: begin out_num={one,nine,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_9,color_9}; out_rg=4'b0101; end
s84: begin out_num={one,nine,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_10,color_10}; out_rg=4'b0101; end
s85: begin out_num={one,eight,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_11,color_11}; out_rg=4'b0101; end
s86: begin out_num={one,eight,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_12,color_12}; out_rg=4'b0101; end
s87: begin out_num={one,seven,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_13,color_13}; out_rg=4'b0101; end
s88: begin out_num={one,seven,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_14,color_14}; out_rg=4'b0101; end
s89: begin out_num={one,six,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0101; end
s90: begin out_num={one,six,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_2,color_2}; out_rg=4'b0101; end
s91: begin out_num={one,five,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_3,color_3}; out_rg=4'b0101; end
s92: begin out_num={one,five,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_4,color_4}; out_rg=4'b0101; end
s93: begin out_num={one,four,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_5,color_5}; out_rg=4'b0101; end
s94: begin out_num={one,four,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_6,color_6}; out_rg=4'b0101; end
s95: begin out_num={one,three,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_7,color_7}; out_rg=4'b0101; end
s96: begin out_num={one,three,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_8,color_8}; out_rg=4'b0101; end
s97: begin out_num={one,two,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_9,color_9}; out_rg=4'b0101; end
s98: begin out_num={one,two,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_10,color_10}; out_rg=4'b0101; end
s99: begin out_num={one,one,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_11,color_11}; out_rg=4'b0101; end
s100: begin out_num={one,one,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_12,color_12}; out_rg=4'b0101; end
s101: begin out_num={one,zero,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_13,color_13}; out_rg=4'b0101; end
s102: begin out_num={one,zero,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_14,color_14}; out_rg=4'b0101; end
s103: begin out_num={zero,nine,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0101; end
s104: begin out_num={zero,nine,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_2,color_2}; out_rg=4'b0101; end
s105: begin out_num={zero,eight,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_3,color_3}; out_rg=4'b0101; end
s106: begin out_num={zero,eight,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_4,color_4}; out_rg=4'b0101; end
s107: begin out_num={zero,seven,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_5,color_5}; out_rg=4'b0101; end
s108: begin out_num={zero,seven,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_6,color_6}; out_rg=4'b0101; end
s109: begin out_num={zero,six,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_7,color_7}; out_rg=4'b0101; end
s110: begin out_num={zero,six,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_8,color_8}; out_rg=4'b0101; end
s111: begin out_num={zero,five,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_9,color_9}; out_rg=4'b0101; end
s112: begin out_num={zero,five,dark,dark,dark,dark}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_10,color_10}; out_rg=4'b0000; end
s113: begin out_num={zero,four,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_11,color_11}; out_rg=4'b0101; end
s114: begin out_num={zero,four,dark,dark,dark,dark}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_12,color_12}; out_rg=4'b0000; end
s115: begin out_num={zero,three,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_13,color_13}; out_rg=4'b0101; end
s116: begin out_num={zero,three,dark,dark,dark,dark}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_14,color_14}; out_rg=4'b0000; end
s117: begin out_num={zero,two,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0101; end
s118: begin out_num={zero,two,dark,dark,dark,dark}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_14,color_14}; out_rg=4'b0000; end
s119: begin out_num={zero,one,wron,wrong,six,zero}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0101; end
s120: begin out_num={zero,one,dark,dark,dark,dark}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_14,color_14}; out_rg=4'b0000; end
default: begin out_num={dark,dark,dark,dark,dark,dark}; {NorthAndSouth_Red_color,EastAndWest_Green_color}={color_1,color_1}; out_rg=4'b0000; end
endcase
end
endmodule
五、设计思路
此次FPGA交通信号灯的课程设计,总经过三个版本的更迭。
- 第一个版本(EDA课程设计_基础款),初步完成老师所设置的基本要求:含30秒绿灯倒计时+30秒红灯倒计时,倒计时最后5秒时计时每半秒闪烁一次,东西南北信号灯的显示,以及清零信号重置开始。
- 第二个版本(EDA_交通信号灯半成品_含指示信号),在完成老师的基本要求基础上增加指示信号:在第一个版本的基础上增加了东、西、南、北信号灯亮起时在HEX3、HEX2、HEX1、HEX0的指示信号。
- 第三个版本(EDA_交通信号灯_最终版),在以上两者基础上增加丰富的信号指示灯与多个自定义控制功能:增加了在南北信号为红灯时的多路彩灯提示信号,东西信号为绿灯时的多路彩灯提示信号,可通过SW[0]使南北信号灯持续为红灯、东西信号灯持续为绿灯,可通过SW[1]使南北信号灯持续为绿灯,东西信号灯持续为红灯,可通过SW[2]使南、北、东、西信号灯维持不变。
六、模块结构
1、首先通过分频,得到2HZ的时钟。
2、第一个always实现:清零信号,通过SW[0]使南北信号灯持续为红灯、东西信号灯持续为绿灯,通过SW[1]使南北信号灯持续为绿灯,东西信号灯持续为红灯,通过SW[2]使南、北、东、西信号灯维持不变,以及定义当前状态。
3、第二个always实现:定义下一状态。
4、第三个always实现:倒计时数字、东西南北信号灯文字提示、东西南北红绿灯、彩灯信号等的赋值。
七、效果展示
1、信号灯解释(共七项)
(1)、倒计时数字显示
(2)、南北东西信号灯文字指示
注:
南北方向为左框,东西方向为右框。
][ 即为×,表示禁止通行。
60即为GO,表示允许通行。
(3)、南北红绿灯信号指示
上边为绿灯指示,下边为红灯指示。(相应颜色灯亮起即信号,上绿下红)
(4)、东西方向红绿灯信号指示
左边为红灯指示,右边为绿灯指示。(相应颜色灯亮起即信号,左红右绿)
(5)、南北方向红灯彩灯指示信号
(6)、东西方向绿灯彩灯指示信号
(7)、自定义按键功能
从右往左依次为:
按下KEY[0]重置开始、SW[0]置一使南北信号灯持续为红灯、东西信号灯持续为绿灯,SW[1]置一使南北信号灯持续为绿灯,东西信号灯持续为红灯,SW[2]置一使南、北、东、西信号灯维持不变。(优先级,SW[0]>SW[1]>SW[2])
2、KEY[0]清零信号重置开始效果展示
在实验时录制的视频,在1m4s时按下清零信号,可见其立刻回到初始状态南北为绿灯,倒计时为30,重新开始,过两秒后在1m6s时又倒计时至28的状态。(表示清零信号正确执行)
3、SW[0]置一使南北信号灯持续为红灯、东西信号灯持续为绿灯
在1m11s使SW[0]置一,在1m12s至1m15s期间SW[0]始终为1,且南北信号灯持续为红灯,东西信号灯持续为绿灯。倒计时数字持续为30。
4、SW[1]置一使南北信号灯持续为绿灯、东西信号灯持续为红灯
在1m19s使SW[1]置一,在1m20s至1m21s期间SW[1]始终为1,且南北信号灯持续为绿灯,东西信号灯持续为红灯,倒计时数字持续为30。
5、SW[2]置一使南、北、东、西信号灯维持不变
在1m26s使SW[2]置一,在1m26s至1m30s期间SW[2]始终为1,且南北信号灯持续为绿灯,东西信号灯持续为红灯,倒计时数字持续为26。
6、南北绿灯,东西红灯时,最后5s对应的半秒一闪烁
7、南北红灯,东西绿灯时,最后5s对应的半秒一闪烁
8、彩灯演示
9、交通信号灯总体演示(倒计时流程)
八、问题分析
在此次课程设计中,我选择了FPGA交通信号灯的设计题目。
- (1)、基础功能:30s红灯倒计时设计、30s绿灯倒计时设计、最后5s闪烁时计时每半秒闪烁一次、南北东西四方向红绿灯设计。
- (2)、与实际结合的指示信号:红绿灯亮起时的文字“允许通行/禁止通行”的指示、红绿灯亮起时的彩灯提示。
- (3)、应对于突发情况功能(例如:救护车紧急通行,警察执行任务等):使南北方向持续为红灯、东西方向持续为绿灯,使南北方向持续为绿灯、东西方向持续为红灯,使南北东西信号灯维持不变。
起初,在增加功能的多样性时,我的想法较为单调,在我深入思考,从实际交通信号灯的场景出发,同时结合FPGA的红绿指示灯以及七位数码管的位置,初步为设计增加创意与功能。虽然为大量的状态信号指示赋值容易混乱,但是在我多次的复查和修改后,最终完整实现了我所预期的设计。
九、总结
此次FPGA交通信号灯的设计,经过EDA课程设计_基础款、EDA_交通信号灯半成品_含指示信号、EDA_交通信号灯_最终版三个版本的更迭,最终结果呈现如上。
为了将自己的想法皆实现至此课程设计中,我曾多次前往实验室,花费不止七个小时去思考创意、编写与调试代码,经过我的不止四十次的修改完善,终于完成了最终版的设计。
在此次课程设计中,我再次复习了管脚分配、有限状态机的设计、清零信号的设置、红/绿彩灯的亮/暗设计、七位数码管显示设计、case语句的使用等知识。并对以上知识的实际应用与结合有了自己的理解与设计
与此同时,我还运用了parameter、localparam 来定义变量、使用{}来便利赋值、自定义通过按键来实现信号跳转、结合实际给出救护车紧急通行/警察执行任务时需特殊处理交通信号灯的功能。在使用一些技巧快速编码的同时,结合实际应用设计功能。
在实验过程中,我有遇到一些问题,例如切换开发板却显示下载失败,在询问老师后,发现可能是开发板有问题需要更换,在更换开发板后便可以成功下载,继续调试完善代码。
数字逻辑与EDA实验课程设计共有五次实验课,先前的四次实验,我分别学习了Quartus II 软件和 DE2-115 开发板的使用,组合逻辑电路设计、仿真与实现,时序逻辑电路设计与仿真,有限状态机的设计,最后这次课程设计将先前所学综合至一起,为数字逻辑与EDA实验画上句号,也为自己的系列实验课程交上答卷。
十:致谢
在五次的数字逻辑与EDA实验课程的进行中,我遇到过许多问题,例如:代码运行环境设置有误、代码语法有误、仿真参数设置有误、代码下载至开发板有误等导致运行出错的问题,在多次询问老师以及自己再调试,已将所有遇到的问题解决,并学习到许多知识,我可以熟练使用Quartus II 软件和 DE2-115 开发板,并且对数字逻辑与EDA的课程知识有了自己的理解与实践。
在此,特别感谢赵老师的悉心指导。
❤️❤️❤️忙碌的敲代码也不要忘了浪漫鸭!
🌞我们好久不见,EDA课程是我很喜欢的一门课,愿你也会喜欢并做的不错!
最近有许多蛮开心的小幸运,你呢?文章来源:https://www.toymoban.com/news/detail-401345.html
文章来源地址https://www.toymoban.com/news/detail-401345.html
到了这里,关于【EDA课程设计】FPGA交通信号灯的设计(含动画视频、超详细思路/步骤分析、完整代码与效果详解)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!