⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 project1.vhd

📁 FPGA DS18B20 测试温度 VHDL源码
💻 VHD
字号:
--此FPGA芯片的设计完成于2007年6月,同月使用Cyclone EP1C3T144C8芯片测试通过,显示温度--正常。

--此芯片在一周的课外时间内设计完成,时间仓促,如有疏漏之处,还请大家指正。

--VHDL代码如下:

--Author:   杨谦
--Department:东南大学 电气工程学院
--Email:     yangqiannj@163.com
--Mobile:    13915997062
--Date:       2007.6.3
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
USE ieee.std_logic_arith.all;


ENTITY Project1 IS
 PORT
 (   CLK:IN STD_LOGIC;--外接12MHz时钟
  
  DQ:INOUT std_logic;--IO to DS18B20
  TEMP_OUT0:OUT std_logic_vector(3 downto 0);--小数后一位的输出
  TEMP_OUT1:OUT std_logic_vector(7 downto 0);--十位和个位温度显示
  TEMP_OUT2:OUT std_logic  --符号
 );
END Project1;


ARCHITECTURE block_name_architecture OF Project1 IS
SIGNAL count_int : std_logic_vector(7 downto 0);
SIGNAL fen : std_logic_vector(5 downto 0);
SIGNAL num         : std_logic_vector(13 downto 0);
SIGNAL T1         : std_logic_vector(7 downto 0);--个位和十位
SIGNAL T0         : std_logic_vector(3 downto 0);--小数点后的
SIGNAL SIGN0        :   std_logic;--符号
BEGIN
PROCESS(CLK)--7 Digital Counter
BEGIN
--WAIT UNTIL rising_edge(CLK);

IF rising_edge(CLK) THEN
    fen<=fen+1;
  IF (fen>=20 OR fen<0) THEN 
  count_int <= count_int+1;
  fen<="000000";
  END IF;
   --D<=count_int;
   IF (num>=11200 OR num<=0) THEN--11000
    num<="00000000000000";
   END IF;
   IF (count_int>=70 OR count_int<0) THEN
   count_int<="00000000";
   num<=num+1;
   --S<=num;
   END IF;
            IF (num>=0 AND num<=6) THEN--Reset
            DQ<='0';
            END IF;
   IF (num>=7 AND num<=13) THEN--Present
            DQ<='Z';
            END IF;
            --Start OF SKIP 1100 1100    Start at 14
   IF (num=16 OR num=17 OR num=20 OR num=21) THEN--SKip Write 1
                IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
            END IF;
   IF (num=14 OR num=15 OR num=18 OR num=19) THEN--SKip Write 0
                IF (count_int>=0 AND count_int<=60) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=61 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
            END IF;
           --Stop OF SKIP
           --Start OF Convert--0100 0100 Start at 22
           --                    22,23,25,26,27,29 
   IF (num=22 OR num=23 OR num=25 OR num=26 OR num=27 OR num=29) THEN--Convert Write 0
                IF (count_int>=0 AND count_int<=60) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=61 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
            END IF;
   IF (num=24 OR num=28) THEN--Convert Write 1
                IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
            END IF;   
   --End OF Convert
   IF (num>=11100 AND num<=11106) THEN--Reset
            DQ<='0';
            END IF;
   IF (num>=11108 AND num<=11113) THEN--Present
            DQ<='Z';
            END IF;
   --Start OF SKIP 1100 1100    Start at 114
   IF (num=11116 OR num=11117 OR num=11120 OR num=11121) THEN--SKip Write 1
                IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
            END IF;
   IF (num=11114 OR num=11115 OR num=11118 OR num=11119) THEN--SKip Write 0
                IF (count_int>=0 AND count_int<=60) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=61 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
            END IF;
           --Stop OF SKIP
   --Start OF READ SCRATCHPAD--1011 1110 Start at 22
           --                    22,28 
   IF (num=11122 OR num=11128) THEN--Convert Write 0
                IF (count_int>=0 AND count_int<=60) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=61 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
            END IF;
   IF (num=11123 OR num=11124 OR num=11125 OR num=11126 OR num=11127 OR num=11129) THEN--Convert Write 1
                IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
            END IF;   
   --End OF READ SCRATCHPAD
   --Start OF Read Temperature
   IF (num=11131) THEN  --1
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T0(0)<='0';
      END IF;
      IF (DQ='1') THEN
      T0(0)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11132) THEN  --2
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T0(1)<='0';
      END IF;
      IF (DQ='1') THEN
      T0(1)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11133) THEN  --3
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T0(2)<='0';
      END IF;
      IF (DQ='1') THEN
      T0(2)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11134) THEN  --4
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T0(3)<='0';
      END IF;
      IF (DQ='1') THEN
      T0(3)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11135) THEN  --5
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T1(0)<='0';
      END IF;
      IF (DQ='1') THEN
      T1(0)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11136) THEN  --6
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T1(1)<='0';
      END IF;
      IF (DQ='1') THEN
      T1(1)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11137) THEN  --7
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T1(2)<='0';
      END IF;
      IF (DQ='1') THEN
      T1(2)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11138) THEN  --8
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T1(3)<='0';
      END IF;
      IF (DQ='1') THEN
      T1(3)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11139) THEN  --9
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T1(4)<='0';
      END IF;
      IF (DQ='1') THEN
      T1(4)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11140) THEN  --10
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T1(5)<='0';
      END IF;
      IF (DQ='1') THEN
      T1(5)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11141) THEN  --11
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T1(6)<='0';
      END IF;
      IF (DQ='1') THEN
      T1(6)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11142) THEN  --12
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      T1(7)<='0';
      END IF;
      IF (DQ='1') THEN
      T1(7)<='1';
                  END IF;
    END IF;
   END IF;
   IF (num=11143) THEN  --13
       IF (count_int>=0 AND count_int<=6) THEN
                     DQ<='0';
                END IF;
    IF (count_int>=7 AND count_int<=70) THEN
                     DQ<='Z';
                END IF; 
    IF (count_int=12) THEN
                     IF (DQ='0') THEN
      SIGN0<='0';
      END IF;
      IF (DQ='1') THEN
      SIGN0<='1';
                  END IF;
    END IF;
   END IF;
   --End OF Read Temperature
   IF (num>=11145 OR num<=11146) THEN
   
   case T0 is   --个位的显示
      when "0000" => TEMP_OUT0<="0000";--0   
      when "0001" => TEMP_OUT0<="0001";--1
   when "0010" => TEMP_OUT0<="0001";--1
   when "0011" => TEMP_OUT0<="0010";--2
   when "0100" => TEMP_OUT0<="0011";--3
   when "0101" => TEMP_OUT0<="0011";--3
   when "0110" => TEMP_OUT0<="0100";--4
   when "0111" => TEMP_OUT0<="0100";--4
   when "1000" => TEMP_OUT0<="0101";--5
   when "1001" => TEMP_OUT0<="0110";--6
   when "1010" => TEMP_OUT0<="0110";--6
   when "1011" => TEMP_OUT0<="0111";--7
   when "1100" => TEMP_OUT0<="1000";--8
   when "1101" => TEMP_OUT0<="1000";--8
   when "1110" => TEMP_OUT0<="1001";--9
   when "1111" => TEMP_OUT0<="1001";--9
   when others => TEMP_OUT0<="1111";
     end case;
   case T1 is
   when "00000000" => TEMP_OUT1<="00000000";--0
   when "00000001" => TEMP_OUT1<="00000001";--1
   when "00000010" => TEMP_OUT1<="00000010";--2
   when "00000011" => TEMP_OUT1<="00000011";--3
   when "00000100" => TEMP_OUT1<="00000100";--4
   when "00000101" => TEMP_OUT1<="00000101";--5
   when "00000110" => TEMP_OUT1<="00000110";--6
   when "00000111" => TEMP_OUT1<="00000111";--7
   when "00001000" => TEMP_OUT1<="00001000";--8
   when "00001001" => TEMP_OUT1<="00001001";--9
   when "00001010" => TEMP_OUT1<="00001010";--10
   when "00001011" => TEMP_OUT1<="00010001";--11
   when "00001100" => TEMP_OUT1<="00010010";--12
   when "00001101" => TEMP_OUT1<="00010011";--13
   when "00001110" => TEMP_OUT1<="00010100";--14
   when "00001111" => TEMP_OUT1<="00010101";--15
   when "00010000" => TEMP_OUT1<="00010110";--16
   when "00010001" => TEMP_OUT1<="00010111";--17
   when "00010010" => TEMP_OUT1<="00011000";--18
   when "00010011" => TEMP_OUT1<="00011001";--19

   when "00010100" => TEMP_OUT1<="00100000";--20
   when "00010101" => TEMP_OUT1<="00100001";--21
   when "00010110" => TEMP_OUT1<="00100010";--22
   when "00010111" => TEMP_OUT1<="00100011";--23
   when "00011000" => TEMP_OUT1<="00100100";--24

   when "00011001" => TEMP_OUT1<="00100101";--25
   when "00011010" => TEMP_OUT1<="00100110";--26

   when "00011011" => TEMP_OUT1<="00100111";--27
   when "00011100" => TEMP_OUT1<="00101000";--28
   when "00011101" => TEMP_OUT1<="00101001";--29
   when "00011110" => TEMP_OUT1<="00110000";--30
   when "00011111" => TEMP_OUT1<="00110001";--31
   when "00100000" => TEMP_OUT1<="00110010";--32
   when "00100001" => TEMP_OUT1<="00110011";--33
   when "00100010" => TEMP_OUT1<="00110100";--34

   when "00100011" => TEMP_OUT1<="00110101";--35
   when "00100100" => TEMP_OUT1<="00110110";--36
   when "00100101" => TEMP_OUT1<="00110111";--37
   when "00100110" => TEMP_OUT1<="00111000";--38
   when "00100111" => TEMP_OUT1<="00111001";--39
   when "00101000" => TEMP_OUT1<="01000000";--40
   when "00101001" => TEMP_OUT1<="01000001";--41
   when "00101010" => TEMP_OUT1<="01000010";--42
   when "00101011" => TEMP_OUT1<="01000011";--43
   when "00101100" => TEMP_OUT1<="01000100";--44
   when "00101101" => TEMP_OUT1<="01000101";--45
   when "00101110" => TEMP_OUT1<="01000110";--46
   when "00101111" => TEMP_OUT1<="01000111";--47
   when "00110000" => TEMP_OUT1<="01001000";--48
   when "00110001" => TEMP_OUT1<="01001001";--49
   when "00110010" => TEMP_OUT1<="01010000";--50
   when "00110011" => TEMP_OUT1<="01010001";--51
   when "00110100" => TEMP_OUT1<="01010010";--52
   when "00110101" => TEMP_OUT1<="01010011";--53
   when "00110110" => TEMP_OUT1<="01010100";--54
   when "00110111" => TEMP_OUT1<="01010101";--55
   when others => TEMP_OUT1<="11111111";
   end case;
   TEMP_OUT2<=SIGN0;
   END IF;
END IF;

END PROCESS;


END block_name_architecture;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -