微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 没看懂串口通信这段代码,纠结了很久啊

没看懂串口通信这段代码,纠结了很久啊

时间:10-02 整理:3721RD 点击:
process(uart_clk,rst,rxds) -- --主控时序、组合进程              ----数据接收
  variable ff2: integer range 0 to 8;--
  begin
   if rst='0' then
    r_state<=r_start;finish<='0';--判断复位状态
    elsif uart_clk'event and uart_clk='1' then --上升沿有效
    case r_state is
     when r_start=>--等待起始位
        if rxds='0' then
         r_state<=r_shift; ff2:=0;   
        else
         r_state<=r_start; ff2:=0; start<='0';
        end if;
     when r_shift=>
      case temp_state is
       when 0=>
        
        test0(ff2)<=rxds;
        ff2:=ff2+1;
        start<='0';
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         if special_temp1="10101010" and test0="01010101" then
          temp_state<=2;
         else
          temp_state<=1;
         end if;
        end if;
       when 1=>
        test1(ff2)<=rxds;
        ff2:=ff2+1;
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         temp_state<=2;
        end if;
       when 2=>
        mode(ff2)<=rxds;
        ff2:=ff2+1;
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         if test1="10101010" and mode="01010101" then
          temp_state<=2;
         else
          temp_state<=3;
         end if;
        end if;
       when 3=>
        freq_temp0(ff2)<=rxds;
        ff2:=ff2+1;
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         if mode="10101010" and freq_temp0="01010101" then
          temp_state<=2;
         else
          temp_state<=4;
         end if;
        end if;
       when 4=>
        freq_temp1(ff2)<=rxds;
        ff2:=ff2+1;
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         if freq_temp0>"00001100" then
          temp_state<=5;
          sw<='0';
         else
          temp_state<=5;
          sw<='1';
         end if;
        end if;
       when 5=>
        freq_temp2(ff2)<=rxds;
        ff2:=ff2+1;
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         temp_state<=6;
        end if;
       when 6=>
        freq_temp3(ff2)<=rxds;
        ff2:=ff2+1;
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         temp_state<=7;
        end if;
       when 7=>
        freq_temp4(ff2)<=rxds;
        ff2:=ff2+1;
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         temp_state<=8;
        end if;
       when 8=>
        freq_temp5(ff2)<=rxds;
        ff2:=ff2+1;
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         temp_state<=9;
        end if;
       when 9=>
        att_temp(ff2)<=rxds;
        ff2:=ff2+1;
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         temp_state<=10;
        end if;
       when 10=>
        special_temp0(ff2)<=rxds;
        ff2:=ff2+1;
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         if att_temp="10101010" and special_temp0="01010101" then
          temp_state<=2;
         else
         temp_state<=11;
         end if;
        end if;
       when 11=>
        special_temp1(ff2)<=rxds;
        ff2:=ff2+1;
        
        if ff2=ff then
         ff2:=0;
         r_state<=r_start;
         if special_temp0="10101010" and special_temp1="01010101" then
          temp_state<=2;
         else
          temp_state<=0;
          start<='1';
         end if;
        end if;
      end case;
     when others=>  r_state<=r_start;
    end case;
   end if;
end process;

不难啊,就一个状态机,接收一帧的数据,8bit,你找个串口的协议看看就懂了

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top