⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 seg71.v

📁 这是一个很不错的CPLD数码管测试程序,从这个程序个大家得很多启发
💻 V
字号:
/*
7段数码管测试实验1:以动态扫描方式在8位数码管“同时”显示0--7
实验的目的是向用户介绍多个数码管动态显示的方法。
动态显示的方法是,按一定的频率轮流向各个数码管的COM端送出低电平,同时送出对应的数据给各段。
*/


module seg71(clk,rst,dataout,en);

input clk,rst;
output[7:0] dataout;
output[7:0] en;//COM使能输出
reg[7:0] dataout;//各段数据输出
reg[7:0] en;

reg[15:0] cnt_scan;//扫描频率计数器
reg[4:0] dataout_buf;

always@(posedge clk or negedge  rst)
begin
	if(!rst) begin
		cnt_scan<=0;
		
	 end
	else begin
		cnt_scan<=cnt_scan+1;
		end
end

always @(cnt_scan)
begin
   case(cnt_scan[15:13])
       3'b000 :
          en = 8'b1111_1110;
       3'b001 :
          en = 8'b1111_1101;
       3'b010 :
          en = 8'b1111_1011;
       3'b011 :
          en = 8'b1111_0111;
       3'b100 :
          en = 8'b1110_1111;
       3'b101 :
          en = 8'b1101_1111;
       3'b110 :
          en = 8'b1011_1111;
       3'b111 :
          en = 8'b0111_1111;
       default :
          en = 8'b1111_1110;
    endcase
end

always@(en) //对应COM信号给出各段数据
begin
	case(en)
		8'b1111_1110:
			dataout_buf=0;
		8'b1111_1101:
			dataout_buf=1;
		8'b1111_1011:
			dataout_buf=2;
		8'b1111_0111:
			dataout_buf=3;	
		8'b1110_1111:
			dataout_buf=4;
		8'b1101_1111:
			dataout_buf=5;
		8'b1011_1111:
			dataout_buf=6;
		8'b0111_1111:
			dataout_buf=7;
		default: 
			dataout_buf=8;
	 endcase
end

always@(dataout_buf)
begin
	case(dataout_buf)
		4'b0000:
			dataout=8'b0000_0011;
		4'b0001:
			dataout=8'b1001_1111;
		4'b0010:
			dataout=8'b0010_0101;
		4'b0011:
			dataout=8'b0000_1101;
		4'b0100:
			dataout=8'b1001_1001;
		4'b0101:
			dataout=8'b0100_1001;
		4'b0110:
			dataout=8'b0100_0001;
		4'b0111:
			dataout=8'b0001_1111;
		4'b1000:
			dataout=8'b0000_0001;
		4'b1001:
			dataout=8'b0001_1001;
		4'b1010:
			dataout=8'b0001_0001;
		4'b1011:
			dataout=8'b1100_0001;
		4'b1100:
			dataout=8'b0110_0011;
		4'b1101:
			dataout=8'b1000_0101;
		4'b1110:
			dataout=8'b0110_0001;
		4'b1111:
			dataout=8'b0111_0001;
	 endcase
end

endmodule 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -