打印

请教串口发送程序

[复制链接]
1333|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
tigris|  楼主 | 2009-3-18 09:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在看VHDL的UART实验,本人愚笨,看得不是很懂。
首先一个问题:40Mhz的时钟,要获得9600波特率。假如我发送一位数据就用一个时钟周期,那么就要获得9600Hz的时钟吗? 40M/9600=4167,我采用一个4167计数器分频,应该就可以得到时钟了吧?我那实验例子里是获得9600*8的时钟,以方便位同步。我在网上参考了一段程序,试了一下,不过发送失败了。

entity s is
    Port ( 
     clk : in std_logic;
           rst : in std_logic;
           dout : out std_logic
              );
end s;



architecture Behavioral of s is

signal div_reg : std_logic_vector(15 downto 0);--分频计数器
signal clk2: std_logic;--分频后时钟信号

constant div_par:    std_logic_vector(15 downto 0):="0001000001000110";--波特率参数,x1046,将40M分成9600hz
constant data: std_logic_vector(9 downto 0):="1010101010";--自己定义的一个数据

begin

process(clk,rst)--产生9600hz时钟
begin
    if(not rst='1')then
        div_reg<="0000000000000000";
    elsif(clk'event and clk='1')then
        if(div_reg=div_par)then
            div_reg<="0000000000000000";
            clk2<=not clk2;
        else
            div_reg<=div_reg+"0000000000000001";
        end if;
    end if;
end process;


process(clk2,rst)--发送一个十位数据(起始位是0,结束位是1)
variable count:integer range 0 to 9 :=0;

begin
    if (not rst='1') then
        count:=0;
        dout<='1';
    elsif rising_edge(clk2) then
        if  count=9 then
        dout<=data(9);
        else
        dout<=data(count);
        count:=count+1;
        end if;
    end if;
end process;


end Behavioral;

相关帖子

沙发
LMJ928| | 2009-3-18 10:01 | 只看该作者

波特率不对

你的程序是4800

使用特权

评论回复
板凳
tigris|  楼主 | 2009-3-20 09:40 | 只看该作者

不是4800吧?

我觉得是9600

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

76

主题

175

帖子

0

粉丝