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

📄 calendar.vhd

📁 系统功能 带有约会提醒功能的电子日历
💻 VHD
字号:
------------------------------------------------------------------------------------ Company: -- Engineer: -- -- Create Date:    22:01:28 06/13/2007 -- Design Name: -- Module Name:    calendar - Behavioral -- Project Name: -- Target Devices: -- Tool versions: -- Description: ---- Dependencies: ---- Revision: -- Revision 0.01 - File Created-- Additional Comments: ------------------------------------------------------------------------------------library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;---- Uncomment the following library declaration if instantiating---- any Xilinx primitives in this code.--library UNISIM;--use UNISIM.VComponents.all;ENTITY calendar IS	PORT(clk1	: IN STD_LOGIC;	     setctr1		: IN STD_LOGIC_VECTOR(1 DOWNTO 0);--等于00-年;01--月;10-日;11--开启日历计时	     setdata		: IN STD_LOGIC_VECTOR(7 DOWNTO 0);	     alarmset		: IN STD_LOGIC_VECTOR(1 DOWNTO 0);--00-开启闹钟;01-关闭;10-约会月;11-约会日。	     alarmdata		: IN STD_LOGIC_VECTOR(7 DOWNTO 0);--闹钟设定数据	     sound_stop		: IN STD_LOGIC;  -- = '1', stop alarm sound,喇叭可有一键停止它。	     sound		: OUT STD_LOGIC; --控制喇叭	     yearshow1		: OUT STD_LOGIC_VECTOR(6 DOWNTO 0);--LED显示年	     yearshow2		: OUT STD_LOGIC_VECTOR(6 DOWNTO 0);--LED显示年	     monthshow1		: OUT STD_LOGIC_VECTOR(6 DOWNTO 0);	     monthshow2		: OUT STD_LOGIC_VECTOR(6 DOWNTO 0);	     dayshow1		: OUT STD_LOGIC_VECTOR(6 DOWNTO 0);	     dayshow2		: OUT STD_LOGIC_VECTOR(6 DOWNTO 0));	END calendar;ARCHITECTURE Behavioral OF calendar ISCOMPONENT freqdiv	PORT(a	: IN STD_LOGIC;	     b	: OUT STD_LOGIC);END COMPONENT;COMPONENT freqdiv_100hz	PORT(a	: IN STD_LOGIC;	     b	: OUT STD_LOGIC);END COMPONENT;COMPONENT disp_coder	PORT(a	: IN STD_LOGIC_VECTOR(3 DOWNTO 0);	     b	: OUT STD_LOGIC_VECTOR(6 DOWNTO 0));END COMPONENT;SIGNAL clk		: STD_LOGIC;SIGNAL yearout1		: STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL yearout10	: STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL monthout1	: STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL monthout10	: STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL dayout1		: STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL dayout10		: STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL alarmmonth	: STD_LOGIC_VECTOR(7 DOWNTO 0);SIGNAL alarmday		: STD_LOGIC_VECTOR(7 DOWNTO 0);SIGNAL monthcheck	: STD_LOGIC_VECTOR(1 DOWNTO 0);SIGNAL daycheck		: STD_LOGIC_VECTOR(2 DOWNTO 0);SIGNAL disp_month	: STD_LOGIC_VECTOR(7 DOWNTO 0);SIGNAL disp_day		: STD_LOGIC_VECTOR(7 DOWNTO 0);SIGNAL sound_pulse	: STD_LOGIC;BEGINclk_for_user	: freqdiv PORT MAP(clk1, clk);--得秒脉冲alarm_pulse	: freqdiv_100hz PORT MAP(clk1, sound_pulse);--得驱动喇叭的脉冲,频率高些。浪费资源-可以合用freqdivmonthchk : PROCESS(monthout10, monthout1)		BEGIN		IF(monthout10 = "0000") THEN			IF(monthout1 = "0100" OR monthout1 = "0110" OR monthout1 = "1001") THEN				monthcheck <= "00";--4,6,9  30天			ELSIF(monthout1 = "0001" OR monthout1 = "0011" OR monthout1 = "0101" OR monthout1 = "0111" OR monthout1 = "1000") THEN				monthcheck <= "01";--1,3,5,7 ,8 --31天			ELSIF((yearout10(0) = '0' AND yearout1(1 DOWNTO 0) = "00") OR (yearout10(0) = '1' AND yearout1(1 DOWNTO 0) = "10")) THEN				monthcheck <= "11"; --leapyear  --闰年			ELSE				monthcheck <= "10"; --common 			END IF;		ELSIF(monthout10 = "0001") THEN			IF(monthout1 = "0001") THEN				monthcheck <= "00";			ELSE					monthcheck <= "01";			END IF;		END IF;	END PROCESS;								daychk : PROCESS(dayout10, dayout1)		BEGIN		IF(dayout10 = "0010" AND dayout1 = "1000") THEN			daycheck <= "010";  --28天		ELSIF(dayout10 = "0010" AND dayout1 = "1001") THEN			daycheck <= "011";  --29天		ELSIF(dayout10 = "0011" AND dayout1 = "0000") THEN			daycheck <= "000";  --30天		ELSIF(dayout10 = "0011" AND dayout1 = "0001") THEN			daycheck <= "001";  --31天		ELSE			daycheck <= "111";		END IF;	END PROCESS;					countday1 : PROCESS(clk, setctr1, setdata)		BEGIN		IF(setctr1 = "10") THEN			dayout1 <= setdata(3 DOWNTO 0);		ELSIF(clk'event AND clk = '1' AND setctr1 = "11") THEN			IF(monthcheck = "10" AND daycheck = "010") THEN				dayout1 <= "0001";			ELSIF(monthcheck = "11" AND daycheck = "011") THEN				dayout1 <= "0001";			ELSIF(monthcheck = "00" AND daycheck = "000") THEN				dayout1 <= "0001";			ELSIF(monthcheck = "01" AND daycheck = "001") THEN					dayout1 <= "0001";			ELSIF(dayout1 = "1001") THEN			       dayout1<=(others=>'0');			     else			       dayout1 <= dayout1 + 1;		        END IF;		END IF;	END PROCESS;												countday10 : PROCESS(clk, setctr1, setdata)		BEGIN		 IF(setctr1 = "10") THEN			dayout10 <= setdata(7 DOWNTO 4);		ELSIF(clk'event AND clk = '1' AND setctr1 = "11")	THEN			IF(monthcheck = "10" AND daycheck = "010") THEN			   dayout10 <= "0000";			ELSIF(monthcheck = "11" AND daycheck = "011") THEN			   dayout10 <= "0000";			ELSIF(monthcheck = "00" AND daycheck = "000") THEN			   dayout10 <= "0000";			ELSIF(monthcheck = "01" AND daycheck = "001") THEN			   dayout10 <= "0000";			ELSIF(monthcheck = "10" AND daycheck = "010") THEN			   dayout10 <= "0000";			ELSIF(dayout1 = "1001") THEN			   dayout10 <= dayout10 + 1;			END IF;		END IF;	    END PROCESS;								countmonth1 : PROCESS(clk, setctr1, setdata)		BEGIN 		IF(setctr1 = "01") THEN --错			monthout1 <= setdata(3 DOWNTO 0);		ELSIF(clk'event AND clk = '1' AND setctr1 = "11") THEN		   IF(monthcheck = "10" AND daycheck = "010") THEN			monthout1 <= monthout1 + 1;  --28天		   ELSIF(monthcheck = "11" AND daycheck = "011") THEN			monthout1 <= monthout1 + 1;  --29天		   ELSIF(monthcheck = "00" AND daycheck = "000") THEN  --30天			IF(monthout1 = "1001") THEN				monthout1 <= "0000";			ELSE 				monthout1 <= monthout1 + 1;  			END IF;		   elsif(monthcheck="01" and daycheck="001") then--31天		      IF(monthout1 = "0010") THEN				monthout1 <= "0000";			ELSE 				monthout1 <= monthout1 + 1;  			END IF;	            END IF;		END IF;	    END PROCESS;										countmonth10 : PROCESS(clk, setctr1, setdata)		BEGIN 		IF(setctr1 = "01") THEN--错			monthout10 <= setdata(7 DOWNTO 4);		ELSIF(clk'event AND clk = '1' AND setctr1 = "11") THEN		   IF(monthcheck = "00" AND daycheck = "000") THEN			IF(monthout1 = "1001") THEN				monthout10 <= "0001";			END IF;		   ELSIF(monthcheck = "01" AND daycheck = "001") THEN		         IF(monthout1 = "0010") THEN			     monthout10 <= "0000";		         END IF;		   END IF;		END IF;		END PROCESS;											countyear1 : PROCESS(clk, setctr1, setdata)		BEGIN		IF(setctr1 = "00") THEN--错			yearout1 <= setdata(3 DOWNTO 0);		ELSIF(clk'event AND clk = '1' AND setctr1 = "11") THEN		   IF(monthcheck = "01" AND daycheck = "001") THEN			IF(monthout1 = "0010") THEN			    IF(yearout1 = "1001") THEN				yearout1 <= "0000";			    ELSE				yearout1 <= yearout1 + 1;			    END IF;			END IF;		    END IF;	         END IF;	   END PROCESS;								countyear10 : PROCESS(clk, setctr1, setdata)		BEGIN				IF(setctr1 = "00") THEN--错			yearout10 <= setdata(7 DOWNTO 4);		ELSIF(clk'event AND clk = '1' AND setctr1 = "11") THEN									   IF(monthcheck = "01" AND daycheck = "001") THEN--31 天			IF(monthout1 = "0010") THEN			   IF(yearout1 = "1001")THEN			     IF(yearout10 = "1001") THEN				yearout10 <= "0000";			     ELSE				yearout10 <= yearout10 + 1;			   END IF;			 end if;		        END IF;		    END IF;		END IF;	  END PROCESS;alarm : PROCESS(alarmset, sound_stop)--设置闹钟,由alarmset与alarmdata配合。		  BEGIN                --00-开启闹钟;01-关闭;10-约会月;11-约会日。			IF(alarmset = "10") THEN				alarmmonth <= alarmdata;			ELSIF(alarmset = "11") THEN --陈输代码错。				alarmday <= alarmdata;			ELSIF(alarmset = "00" AND sound_stop = '0') THEN			   IF(monthout10 = alarmmonth(7 DOWNTO 4) AND monthout1 = alarmmonth(3 DOWNTO 0) AND dayout10 = alarmday(7 DOWNTO 4) AND dayout1 = alarmday( 3 DOWNTO 0)) THEN				sound <= sound_pulse;			   END IF;			END IF;	END PROCESS;			  disp1ay_choose : PROCESS(alarmset)			 BEGIN		     		        IF(alarmset = "10" OR alarmset = "11") THEN				disp_month <= alarmmonth;				disp_day <= alarmday;			ELSE				disp_month(7 DOWNTO 4) <= monthout10;				disp_month(3 DOWNTO 0) <= monthout1;				disp_day(7 DOWNTO 4) <= dayout10;  --有错				disp_day(3 DOWNTO 0) <= dayout1;  --有错			END IF;		END PROCESS;



			     	show1 : disp_coder PORT MAP(yearout10, yearshow1);		show2 : disp_coder PORT MAP(yearout1, yearshow2);---有错		show3 : disp_coder PORT MAP(disp_month(7 DOWNTO 4), monthshow1);		show4 : disp_coder PORT MAP(disp_month(3 DOWNTO 0), monthshow2);		show5 : disp_coder PORT MAP(disp_day(7 DOWNTO 4), dayshow1);		show6 : disp_coder PORT MAP(disp_day(3 DOWNTO 0), dayshow2);						END Behavioral;

⌨️ 快捷键说明

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