马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 孫悟 于 2012-8-6 23:31 编辑
想要请问个uart接收的问题
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_unsigned.all;
- entity uart is
- port(
- clk_in_325hz : in std_logic;--153600hz由50MHZ分頻
- rxd_in: in std_logic;
- rxd_out:out std_logic_vector(7 downto 0)
- );
- end uart;
- architecture a of uart is
- type state is(idle,check,rec);
- signal check_ck,rec_ck,rec_re,rec_cc,ok:std_logic;
- signal check_re: std_logic_vector(1 downto 0):="00";
- signal recv,recv_sig : std_logic_vector(8 downto 0):="000000000";
- signal rxd_ck,rxd_ck_sig : std_logic_vector(3 downto 0):="0000";
- signal sta : state;
- begin
- process(sta,rxd_in,check_re,rec_re)
- begin
- case sta is
- when idle=>--等待初始位元
- recv_sig<="000000000";
- if rxd_in='0' then
- sta<=check;
- else
- sta<=idle;
- end if;
- when check=>--確認初始位元是不是雜訊
- check_ck<='1';
- case check_re is
- when "01"=>
- check_ck<='0';
- sta<=rec;
- when "10"=>
- check_ck<='0';
- sta<=idle;
- when others=> null;
- end case;
- when rec=>--接收資料
- rec_ck<='1';
- if rec_re='1' then
- sta<=idle;
- rec_ck<='0';
- elsif ok='1' then
- rxd_out<=recv(7 downto 0);
- sta<=idle;
- rec_ck<='0';
- end if;
- end case;
- end process;
- process(clk_in_325hz,check_ck,rec_ck)
- variable rxd_ck_st : integer range 0 to 4:=0;
- variable rec_st : integer range 0 to 8:=0;
- variable rec_ck_st: integer range 0 to 9:=0;
- begin
- if check_ck='1' then--確認初始位元是不是雜訊
- if clk_in_325hz'event and clk_in_325hz='1' then--1153600的上延
- if rxd_ck_st/=4 then--讓他記數4次,採樣4次確認是不是起始位元
- rxd_ck_st:=rxd_ck_st+1;
- rxd_ck<=rxd_in & rxd_ck_sig(3 downto 1);
- else
- if rxd_ck="0000" then--4次之後判斷回傳結果
- check_re<="01";
- rxd_ck_st:=0;
- else
- check_re<="10";
- rxd_ck_st:=0;
- end if;
- end if;
- end if;
- end if;
- if rec_ck='1' then
- if clk_in_325hz'event and clk_in_325hz='1' then
- rec_st:=rec_st+1;
- if rec_st=8 then --讓他記數8次,第8次的時候剛好再中間,共取9次,8個資料1個停止
- recv<=rxd_in & recv_sig(8 downto 1);
- rec_st:=0;
- rec_ck_st:=rec_ck_st+1;
- elsif rec_ck_st=9 then--取完第9個判斷第9個是不是停止位元,之後回傳
- if recv(8)='1' then
- ok<='1';
- rec_ck_st:=0;
- else
- rec_re<='1';
- rec_ck_st:=0;
- end if;
- end if;
- end if;
- end if;
- end process;
- end a;
复制代码 这样写烧进实验板没有反应,这我的写法有错吗(?),9600bps的,先谢谢 |