📄 6位led动态显示程序(c程序).txt
字号:
module seg71(clk,rst,dataout,en);
input clk,rst;
output[7:0] dataout;
output[5:0] en;
reg[7:0] dataout;
reg[5:0] en;
reg[2:0] cnt_scan;
reg[4:0] dataout_buf;
always@(posedge clk or negedge rst)
begin
if(!rst) //reset if rst
begin
cnt_scan<=3'b000;
end
else if(cnt_scan == 3'b110)
begin
cnt_scan <= 3'b000;
end
else
begin
cnt_scan<=cnt_scan+1'b1;
end
end
always @(cnt_scan)
begin
case(cnt_scan[2:0])
3'b000 :
en = 6'b11_1111;
3'b001 :
en = 6'b11_1110;
3'b010 :
en = 6'b11_1101;
3'b011 :
en = 6'b11_1011;
3'b100 :
en = 6'b11_0111;
3'b101 :
en = 6'b10_1111;
3'b110 :
en = 6'b01_1111;
default :
en = 6'b11_1111;
endcase
end
always@(en) //
begin
case(en)
6'b11_1110:
dataout_buf=0;
6'b11_1101:
dataout_buf=1;
6'b11_1011:
dataout_buf=2;
6'b11_0111:
dataout_buf=3;
6'b10_1111:
dataout_buf=4;
6'b01_1111:
dataout_buf=5;
default:
dataout_buf=17;
endcase
end
always@(dataout_buf)
begin
dataout= 8'b11111111;
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;
default:
dataout=8'b1111_1111;
endcase
end
endmodule
此程序在P89V51RD2与EPM7128SLI-10联合开发板上调试通过,P89V51RD2程序如下:
#include <reg51f.h>
sbit P3_6 = P3^6;
sbit P3_7 = P3^7;
int count = 0;
void time1_ISR(void) interrupt 1
{
P3_6 = !P3_6;
TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;
count = count + 1;
}
void main()
{
P3_6 = 1;
P3_7 = 0;
TMOD = 0x01;
TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
do{
if (count == 6000)
P3_7 = 1;
} while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -