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

📄 seg71.v.bak

📁 这是一个很不错的CPLD数码管测试程序,从这个程序个大家得很多启发
💻 BAK
字号:
/*
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)
begin
	if(!rst) begin
		cnt_scan<=0;
		en<=8'b1111_1110;
	 end
	else begin
		cnt_scan<=cnt_scan+1;
		if(cnt_scan==16'hffff) begin //按一定频率送出COM使能信号
			en[7:1]<=en[6:0];
			en[0]<=en[7];
		 end
	 end
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=7;
	 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 + -