Input wire reset_n
Input wire clk
Input wire baud_sel //输出速率选择,1为高速(每个时钟输出一个)0为低速(16个时钟输出一个)
Input wire[2:0] mode //模式选择输入
Output reg [6:0] led_8 //7未共阴级数码管显示输出
Reg [3:0] div //输出速率分频
Reg [12:0] out_reg //序列数值存储
Reg [3:0] out_cnt //序列串行输出计数器。每次序列数值都在计数器为11时更新即前一个序列数串行输出完毕
//输出速率
Always@(posedge clk or negedge reset_n )
Begin
If(!reset_n)
Div <=‘h0
Else if(baud_sel)
Div<=‘hf
Else
Div<=div+’h1
End
//序列串行输出计数器,向下递减
//输出序列数据产生
Always@(posedge clk or negedge reset_n )
Begin
If(!reset_n)
out_cnt <=‘hc
else if(Div=’hf)
out_cnt<= out_cnt –‘h1
else
out_cnt<= out_cnt
end
//输出序列数据产生
Always@(posedge clk or negedge reset_n )
Begin
If(!reset_n)
out_reg <= ‘h0
else if(out_cnt==’hc)
Case(mode)
3’h0 : out_reg<= ‘h191c
3’h1 : out_reg<= ‘h1922
3’h2 : out_reg<= ‘h1949
3’h3 : out_reg<= ‘h196d
3’h4 : out_reg<= ‘h1992
3’h5 : out_reg<= ‘h19b6
3’h6 : out_reg<= ‘h19db
3’h7 : out_reg<=‘h19ff
Endcase
Else
Out_reg<={1’h0, out_reg[12:1]} //out_reg 的低位先串行输出
End
Assign out =out_reg[0]
// 数码管显示模式
Always@(posedge clk or negedge reset_n )
Begin
If(!reset_n)
led_8<= ‘h0 //复位时关闭数码管显示
else if(out_cnt==’hc) //一个序列数据输出完毕时更新数码管显示
Case(mode)
3’h0 : led_8 <= ‘h3f
3’h1 : led_8 <= ‘h06
3’h2 : led_8 <= ‘h5b
3’h3 : led_8 <= ‘h4f
3’h4 : led_8 <= ‘h66
3’h5 : led_8 <= ‘h6b
3’h6 : led_8 <= ‘h7d
3’h7 : led_8<= ‘h07
Endcase
Else
led_8 <=led_8
End
Endmodule
一位一位的输出么?
sbit BIT_OUTPUT = P1^0void BitsOutput(unsigned char temp)//从最高位移出
{
char count = 8
while(count--)
{
if((temp & 0x80) == 0x80)
BIT_OUTPUT = 1
else
BIT_OUTPUT = 0
temp <<= 1
}
}
void BitsOutput(unsigned char temp)//从最低位移出
{
char count = 8
while(count--)
{
if((temp & 0x01) == 0x01)
BIT_OUTPUT = 1
else
BIT_OUTPUT = 0
temp >>= 1
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)