
基于VHDL的FPGA与DS18B20温度传感器读写设计 Quartus工程源码及文档说明.rar
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
本资源包含使用Quartus平台和VHDL语言开发的FPGA项目代码,用于实现与DS18B20数字温度传感器的数据交互功能,并附带详细文档。
VHDL设计用于FPGA读取DS18B20温度传感器的Quartus工程源码及文档说明如下:
```vhdl
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ds18B20 is
port(
clk : in std_logic; -- 50MHz时钟信号输入
rst_n: in std_logic; -- 复位信号输入
one_wire : inout std_logic; -- DS18B20数据线接口
dataout : out std_logic_vector(7 downto 0); -- 数码管数据输出端口
en : out std_logic_vector(3 downto 0) -- 数码管位选信号端口
);
end ds18B20;
architecture Behavioral of ds18B20 is
signal dataout_buf:std_logic_vector(3 downto 0); -- 数据输出缓冲寄存器
signal count:std_logic_vector(17 downto 0); -- 分频计数信号
signal cnt_scan:std_logic_vector(17 downto 0); -- 数码管扫描显示计数信号
-- 定义时钟频率转换信号及变量
signal clk_1us:std_logic;-- 生成的1MHz时钟输出
signal cnt_1us:integer range 0 to 750002;-- 计算得到的延时时长(微秒)
signal cnt_1us_clear:std_logic;
TYPE STATE_TYPE is (S00,S0,S1,S2,S3,S4,S5,S6,S7, WRITE0,WRITE1,WRITE00,WRITE01,READ0,READ1,READ2,READ3); -- 状态机定义
signal state: STATE_TYPE; -- 初始化状态为复位状态
-- One-Wire总线缓存寄存器及温度值缓冲变量声明
signal one_wire_buf:std_logic;
signal temperature_buf:std_logic_vector(15 downto 0);
signal DS18B20_DATA_buf:std_logic_vector(15 downto 0);
signal DS18B20_DATA_buf_temp:std_logic_vector(15 downto 0);
-- 子状态寄存器及有效位声明
signal step:integer range 0 to 50;
signal bit_valid:integer range 0 to 15;
-- 辅助信号定义
signal one_wire_in:std_logic;
signal t_buf:std_logic_vector(15 downto 0);
signal t_buf_temp:std_logic_vector(15 downto 0);
-- 计数器变量
signal cnt:integer range 0 to 50;
begin
-- 分频器实现部分,将输入的50MHz时钟信号转换为1MHz输出
process (clk, rst_n)
begin
if rising_edge(clk) then
if(rst_n=0) then
cnt <= 0;
else
if(cnt = 49)then
cnt <= 0;
else
cnt <= cnt + 1;
end if;
end if;
end Process;
```
这里仅展示了时钟分频器的部分代码,完整的VHDL源码包含了更多逻辑实现细节。
全部评论 (0)


