Hardware Reference
In-Depth Information
20 set_min: std_logic_vector(7 downto 0) := "00110000"; --30 min
21 set_hour: std_logic_vector(7 downto 0) := "00010011"; --13 h
22 set_date: std_logic_vector(7 downto 0) := "00100101"; --date 25
23 set_month:std_logic_vector(7downto0):="00010010"); --month12
24 port (
25 --Clock and control ports:
26 clk, rst, wr, rd: in std_logic;
27 --I2C ports:
28 SCL, CH_RSTn: out std_logic;
29 SDA: inout std_logic;
30 --Display ports (test circuit):
31 ssd_1sec: out std_logic_vector(6 downto 0); --units of seconds
32 ssd_10sec: out std_logic_vector(6 downto 0); --tens of seconds
33 ssd_1min: out std_logic_vector(6 downto 0); --units of minutes
34 ssd_10min: out std_logic_vector(6 downto 0); --tens of minutes
35 ssd_1hour: out std_logic_vector(6 downto 0); --units of hours
36 ssd_10hour: out std_logic_vector(6 downto 0)); --tens of hours
37 end entity;
38 -------------------------------------------------------------------------
39 architecture moore_fsm of RTC_with_I2C_bus is
40
41
--FSM-related declarations:
42
type state is (
43
--common states:
44
idle, start, slave_addr_wr, ack1, stop, hold,
45
--write-only states:
46
initial_addr_wr, ack2, wr_data, ack3,
47
--read-only states:
48
initial_addr_rd, ack4, restartL, restartR, slave_addr_rd, ack5,
49
rd_sec, ack6, rd_min, ack7, rd_hour, no_ack);
50
signal pr_state, nx_state: state;
51
52
--Auxiliary-register-related declarations:
53
signal i, i_reg: natural range 0 to 8;
54
signal j, j_reg: natural range 0 to 7;
55
56
--Other declarations:
57
signal i2c_clk: std_logic;
58
signal sec: std_logic_vector(7 downto 0);
59
signal min: std_logic_vector(7 downto 0);
60
signal hour: std_logic_vector(7 downto 0);
61
type data_array is array (0 to 6) of std_logic_vector(7 downto 0);
62
constantdata_out:data_array:=(set_control,set_subsec,set_sec,
63
set_min, set_hour, set_date, set_month);
64
65 begin
66
67
CH_RSTn <= not rst; --chip reset
68
69
--i2c_clk (100kHz):
70
process (clk)
71
variable count: natural range 0 to fclk/(2*data_rate);
72
begin
73
if rising_edge(clk) then
74
count := count + 1;
75
if count=fclk/(2*data_rate) then
Search WWH ::




Custom Search