源代码如下 自己把各个模块打好包 下面有个图 自己看看
LIBRARY IEEE;
USE IEEESTD_LOGIC_1164ALL;
USE IEEESTD_LOGIC_UNSIGNEDALL;
ENTITY TZKZQ IS
PORT(KEY: IN STD_LOGIC_VECTOR(1 DOWNTO 0); --按键信号
CLK_KEY: IN STD_LOGIC; --键盘扫描信号
MAX_DAYS:IN STD_LOGIC_VECTOR(4 DOWNTO 0); --本月最大天数
SEC_EN,MIN_EN,HOUR_EN,DAY_EN,MON_EN,YEAR_EN,WEEK_EN:OUT STD_LOGIC; --异步并行置位使能
HOUR_CUR:IN STD_LOGIC_VECTOR(4 DOWNTO 0);
MIN_CUR,SEC_CUR:IN STD_LOGIC_VECTOR(5 DOWNTO 0);
YEAR_CUR:IN STD_LOGIC_VECTOR(6 DOWNTO 0);
MON_CUR :IN STD_LOGIC_VECTOR(3 DOWNTO 0);
DAY_CUR :IN STD_LOGIC_VECTOR(4 DOWNTO 0);
WEEK_CUR:IN STD_LOGIC_VECTOR(2 DOWNTO 0);
SEC,MIN:BUFFER STD_LOGIC_VECTOR(5 DOWNTO 0);
HOUR:BUFFER STD_LOGIC_VECTOR(4 DOWNTO 0);
DAY :BUFFER STD_LOGIC_VECTOR(4 DOWNTO 0);
MON :BUFFER STD_LOGIC_VECTOR(3 DOWNTO 0);
YEAR:BUFFER STD_LOGIC_VECTOR(6 DOWNTO 0);
WEEK:BUFFER STD_LOGIC_VECTOR(2 DOWNTO 0));
END ENTITY TZKZQ;
ARCHITECTURE ART OF TZKZQ IS
TYPE STATETYPE IS (NORMAL,SEC_SET,MIN_SET,HOUR_SET,DAY_SET,MON_SET,
YEAR_SET,WEEK_SET);
SIGNAL MODE:STATETYPE;
BEGIN
PROCESS(KEY,CLK_KEY)
BEGIN
IF CLK_KEY'EVENT AND CLK_KEY='1' THEN
IF KEY="01" THEN
SEC_EN<='1';MIN_EN<='1';HOUR_EN<='1';
DAY_EN<='1';MON_EN<='1';YEAR_EN<='1';
WEEK_EN<='1';
CASE MODE IS
WHEN NORMAL => MODE<=SEC_SET;SEC<=SEC_CUR;SEC_EN<='0';
WHEN SEC_SET => MODE<=MIN_SET;MIN<=MIN_CUR;SEC_EN<='1';MIN_EN<='0';
WHEN MIN_SET => MODE<=HOUR_SET;HOUR<=HOUR_CUR;MIN_EN<='1';HOUR_EN<='0';
WHEN HOUR_SET=> MODE<=DAY_SET;DAY<=DAY_CUR;HOUR_EN<='1';DAY_EN<='0';
WHEN DAY_SET => MODE<=MON_SET;MON<=MON_CUR;DAY_EN<='1';MON_EN<='0';
WHEN MON_SET => MODE<=YEAR_SET;YEAR<=YEAR_CUR; MON_EN<='1';
YEAR_EN<='0';
WHEN YEAR_SET => MODE<=WEEK_SET;WEEK<=WEEK_CUR;YEAR_EN<='1';WEEK_EN<='0';
WHEN WEEK_SET => MODE<=NORMAL;
END CASE;
ELSIF KEY="10" THEN --如果按下调整键,则自加
CASE MODE IS
WHEN SEC_SET => SEC_EN<='0';
--异步并行置位使能有效
IF SEC="111011" THEN SEC<="000000";
--如果秒计数到59,返回到0重新计数
ELSE SEC<=SEC+1; --否则继续计数
END IF;
WHEN MIN_SET => MIN_EN<='0';
IF MIN="111011" THEN MIN<="000000";
ELSE MIN<=MIN+1;
END IF;
WHEN HOUR_SET=> HOUR_EN<='0';
IF HOUR="11000" THEN HOUR<="00000";
ELSE HOUR<=HOUR+1;
END IF;
WHEN DAY_SET => DAY_EN<='0';
IF DAY=MAX_DAYS THEN DAY<="00001";
ELSE DAY<=DAY+1;
END IF;
WHEN WEEK_SET=> WEEK_EN<='0';
IF WEEK="111" THEN WEEK<="001";
ELSE WEEK<=WEEK+1;
END IF;
WHEN OTHERS=>NULL;
END CASE;
END IF;
END IF;
END PROCESS;
END ARCHITECTURE ART;
LIBRARY IEEE;
USE IEEESTD_LOGIC_1164ALL;
USE IEEESTD_LOGIC_UNSIGNEDALL;
ENTITY CNT60 IS
PORT(LD: IN STD_LOGIC;
CLK: IN STD_LOGIC;
DATA: IN STD_LOGIC_VECTOR(5 DOWNTO 0);
NUM: BUFFER STD_LOGIC_VECTOR(5 DOWNTO 0);
CO: OUT STD_LOGIC);
END ENTITY CNT60;
ARCHITECTURE ART OF CNT60 IS
BEGIN
PROCESS(CLK,LD) IS
BEGIN
IF(LD='0') THEN
NUM<=DATA;
ELSIF CLK'EVENT AND CLK='1' THEN
IF NUM="111011" THEN --59
NUM<="000000";CO<='1';
ELSE
NUM<=NUM+1;CO<='0';
END IF;
END IF;
END PROCESS;
END ARCHITECTURE ART;
LIBRARY IEEE;
USE IEEESTD_LOGIC_1164ALL;
USE IEEESTD_LOGIC_UNSIGNEDALL;
ENTITY CNT60 IS
PORT(LD: IN STD_LOGIC;
CLK: IN STD_LOGIC;
DATA: IN STD_LOGIC_VECTOR(5 DOWNTO 0);
NUM: BUFFER STD_LOGIC_VECTOR(5 DOWNTO 0);
CO: OUT STD_LOGIC);
END ENTITY CNT60;
ARCHITECTURE ART OF CNT60 IS
BEGIN
PROCESS(CLK,LD) IS
BEGIN
IF(LD='0') THEN
NUM<=DATA;
ELSIF CLK'EVENT AND CLK='1' THEN
IF NUM="111011" THEN --59
NUM<="000000";CO<='1';
ELSE
NUM<=NUM+1;CO<='0';
END IF;
END IF;
END PROCESS;
END ARCHITECTURE ART;
LIBRARY IEEE;
USE IEEESTD_LOGIC_1164ALL;
USE IEEESTD_LOGIC_UNSIGNEDALL;
ENTITY CNT24 IS
PORT(LD: IN STD_LOGIC;
CLK: IN STD_LOGIC;
DATA: IN STD_LOGIC_VECTOR(4 DOWNTO 0);
NUM: BUFFER STD_LOGIC_VECTOR(4 DOWNTO 0);
CO: OUT STD_LOGIC);
END ENTITY CNT24;
ARCHITECTURE ART OF CNT24 IS
BEGIN
PROCESS(CLK,LD) IS
BEGIN
IF(LD='0') THEN
NUM<=DATA;
ELSIF CLK'EVENT AND CLK='1' THEN
IF NUM="11000" THEN --24
NUM<="00000";CO<='1';
ELSE
NUM<=NUM+1;CO<='0';
END IF;
END IF;
END PROCESS;
END ARCHITECTURE ART;
LIBRARY IEEE;
USE IEEESTD_LOGIC_1164ALL;
USE IEEESTD_LOGIC_UNSIGNEDALL;
ENTITY CNT30 IS
PORT(LD:IN STD_LOGIC;
CLK:IN STD_LOGIC;
NIAN:IN STD_LOGIC_VECTOR(6 DOWNTO 0);
YUE :IN STD_LOGIC_VECTOR(3 DOWNTO 0);
DATA:IN STD_LOGIC_VECTOR(4 DOWNTO 0);
NUM:BUFFER STD_LOGIC_VECTOR(4 DOWNTO 0);
MAX_DAYS:OUT STD_LOGIC_VECTOR(4 DOWNTO 0);
CO:OUT STD_LOGIC);
END ENTITY CNT30;
ARCHITECTURE ART OF CNT30 IS
SIGNAL TOTAL_DAYS:STD_LOGIC_VECTOR(4 DOWNTO 0);
BEGIN
PROCESS(CLK,LD) IS
VARIABLE IS_RUNNIAN:STD_LOGIC;
BEGIN
CASE NIAN IS
WHEN "0000000" => IS_RUNNIAN:='1'; --0
WHEN "0000100" => IS_RUNNIAN:='1'; --4
WHEN "0001000" => IS_RUNNIAN:='1'; --8
WHEN "0001100" => IS_RUNNIAN:='1'; --12
WHEN "0010000" => IS_RUNNIAN:='1'; --16
WHEN "0010100" => IS_RUNNIAN:='1'; --20
WHEN "0011000" => IS_RUNNIAN:='1'; --24
WHEN "0011100" => IS_RUNNIAN:='1'; --28
WHEN "0100000" => IS_RUNNIAN:='1'; --32
WHEN "0100100" => IS_RUNNIAN:='1'; --36
WHEN "0101000" => IS_RUNNIAN:='1'; --40
WHEN "0101100" => IS_RUNNIAN:='1'; --44
WHEN "0110000" => IS_RUNNIAN:='1'; --48
WHEN "0110100" => IS_RUNNIAN:='1'; --52
WHEN "0111000" => IS_RUNNIAN:='1'; --56
WHEN "0111100" => IS_RUNNIAN:='1'; --60
WHEN "1000000" => IS_RUNNIAN:='1'; --64
WHEN "1000100" => IS_RUNNIAN:='1'; --68
WHEN "1001000" => IS_RUNNIAN:='1'; --72
WHEN "1001100" => IS_RUNNIAN:='1'; --76
WHEN "1010000" => IS_RUNNIAN:='1'; --80
WHEN "1010100" => IS_RUNNIAN:='1'; --84
WHEN "1011000" => IS_RUNNIAN:='1'; --88
WHEN "1011100" => IS_RUNNIAN:='1'; --92
WHEN "1100000" => IS_RUNNIAN:='1'; --96
WHEN OTHERS => IS_RUNNIAN:='0';
END CASE;
CASE YUE IS
WHEN "0001" => TOTAL_DAYS<="11111"; --1
WHEN "0011" => TOTAL_DAYS<="11111"; --3
WHEN "0101" => TOTAL_DAYS<="11111"; --5
WHEN "0111" => TOTAL_DAYS<="11111"; --7
WHEN "1000" => TOTAL_DAYS<="11111"; --8
WHEN "1010" => TOTAL_DAYS<="11111"; --10
WHEN "1100" => TOTAL_DAYS<="11111"; --12
WHEN "0100" => TOTAL_DAYS<="11110"; --4
WHEN "0110" => TOTAL_DAYS<="11110"; --6
WHEN "1001" => TOTAL_DAYS<="11110"; --9
WHEN "1011" => TOTAL_DAYS<="11110"; --11
WHEN "0010" =>
IF (IS_RUNNIAN='1') THEN
TOTAL_DAYS<="11101";
ELSE
TOTAL_DAYS<="11100";
END IF;
WHEN OTHERS=>NULL;
END CASE;
IF(LD='0') THEN
NUM<=DATA;
ELSIF CLK'EVENT AND CLK='1' THEN
MAX_DAYS<=TOTAL_DAYS;
IF NUM=TOTAL_DAYS THEN --99
NUM<="00001";CO<='1';
ELSE
NUM<=NUM+1;CO<='0';
END IF;
END IF;
END PROCESS;
END ARCHITECTURE ART;
LIBRARY IEEE;
USE IEEESTD_LOGIC_1164ALL;
USE IEEESTD_LOGIC_UNSIGNEDALL;
ENTITY CNT7 IS
PORT(LD: IN STD_LOGIC;
CLK: IN STD_LOGIC;
DATA: IN STD_LOGIC_VECTOR(2 DOWNTO 0);
NUM: BUFFER STD_LOGIC_VECTOR(2 DOWNTO 0));
END ENTITY CNT7;
ARCHITECTURE ART OF CNT7 IS
BEGIN
PROCESS(CLK,LD) IS
BEGIN
IF(LD='0') THEN
NUM<=DATA;
ELSIF CLK'EVENT AND CLK='1' THEN
IF NUM="111" THEN --7
NUM<="000";
ELSE
NUM<=NUM+1;
END IF;
END IF;
END PROCESS;
END ARCHITECTURE ART;
LIBRARY IEEE;
USE IEEESTD_LOGIC_1164ALL;
USE IEEESTD_LOGIC_UNSIGNEDALL;
ENTITY CNT12 IS
PORT(LD: IN STD_LOGIC;
CLK: IN STD_LOGIC;
DATA: IN STD_LOGIC_VECTOR(3 DOWNTO 0);
NUM: BUFFER STD_LOGIC_VECTOR(3 DOWNTO 0);
CO: OUT STD_LOGIC);
END ENTITY CNT12;
ARCHITECTURE ART OF CNT12 IS
BEGIN
PROCESS(CLK,LD) IS
BEGIN
IF(LD='0') THEN
NUM<=DATA;
ELSIF CLK'EVENT AND CLK='1' THEN
IF NUM="1100" THEN --12
NUM<="0000";CO<='1';
ELSE
NUM<=NUM+1;CO<='0';
END IF;
END IF;
END PROCESS;
END ARCHITECTURE ART;
LIBRARY IEEE;
USE IEEESTD_LOGIC_1164ALL;
USE IEEESTD_LOGIC_UNSIGNEDALL;
ENTITY CNT99 IS
PORT(LD: IN STD_LOGIC;
CLK: IN STD_LOGIC;
DATA: IN STD_LOGIC_VECTOR(6 DOWNTO 0);
NUM: BUFFER STD_LOGIC_VECTOR(6 DOWNTO 0));
END ENTITY CNT99;
ARCHITECTURE ART OF CNT99 IS
BEGIN
PROCESS(CLK,LD) IS
BEGIN
IF(LD='0') THEN
NUM<=DATA;
ELSIF CLK'EVENT AND CLK='1' THEN
IF NUM="1100011" THEN --12
NUM<="0000000";
ELSE
NUM<=NUM+1;
END IF;
END IF;
END PROCESS;
END ARCHITECTURE ART;
eda中seltime数字钟译码模块是进行正常的示数和闹钟的示数。利用电路的共阳极数码管的特性进行10个数字和-的译码,分别利用两位16进制进行定义,更加简约方便。互联网数据分析师(英文简称EDA),有别于数据分析师,更专注于分析垂直性互联网行业的数据事物,更在意于以互联网数据为中心,引导消费行为,促进互联网商业决策。更专业于处理分析互联网平台流量分析与监控,目标用户研究。
ORG 0000H ;程序执行开始地址
LJMP START ;跳到标号START执行
ORG 0003H ;外中断0中断程序入口
LJMP REMO ;外中断0中断返回
ORG 000BH ;定时器T0中断程序入口
LJMP TIME0 ;跳至INTTO执行
ORG 0013H ;外中断1中断程序入口
RETI ;外中断1中断返回
ORG 001BH ;定时器T1中断程序入口
LJMP TIME1 ;跳至TIME1执行
ORG 0023H ;串行中断程序入口地址
RETI ;串行中断程序返回
;
TIME1: RETI
;
TIMEADD EQU 30H;30H做为软件计数缓存
DISP1 EQU 31H;31H做为第一位显示缓存
DISP2 EQU 32H;32H做为第二位显示缓存
DISP3 EQU 33H;33H做为第三位显示缓存
DISP4 EQU 34H;34H做为第四位显示缓存
SECLED EQU P10;秒点显示P10
HALFSEC EQU 35H;半秒计数缓存
UPKEY BIT P27;定义P27是UP键
SETKEY BIT P20;定义P20是SET键
BUZZ BIT P25;
;
;第1位使能P21
;第2位使能P22
;第3位使能P23
;第4位使能P24
;
ORG 0030H;
;
START:
MOV SP,#5FH;放堆栈
MOV P2,#0FFH;把P2置高
CLR P25;把p25置0
LCALL BUZZER;发出滴声
LCALL BUZZER;按键滴声
MOV TIMEADD,#0;软件计数器清零
MOV TMOD,#11H;TIME0工作于方式1,TIME1工作于方式1
MOV TH0,#3CH;
MOV TL0,#0B0H;放定时预置数15536
MOV IE,#8BH;开INT0,TIME0,TIME1
MOV IP,#02H;TIME0中断优先
SETB IT0;外部中断0为负跳变方式触发
SETB TR0;开始计数
MOV DISP1,#00H;
MOV DISP2,#00H;
MOV DISP3,#00H;
MOV DISP4,#00H;把所有显示缓存清零
MOV HALFSEC,#00H;把半秒计数缓存清零
MOV DPTR,#TAB;
SCAN:
MOV A,DISP1;把第一位显示缓存送入A
MOVC A,@A+DPTR;查表
SETB P24;
CLR P21;第一位显示使能
MOV P0,A;查表得到的7段码送给P0去显示
LCALL DELAY;延时
MOV P0,#0FFH;显示一小段时间后关掉7段显示,去显示下一位
MOV A,DISP2;
MOVC A,@A+DPTR;
SETB P21;
CLR P22;
MOV P0,A;
LCALL DELAY;
MOV P0,#0FFH;
MOV A,DISP3;
MOVC A,@A+DPTR;
SETB P22;
CLR P23;
MOV P0,A;
LCALL DELAY;
MOV P0,#0FFH;
MOV A,DISP4;
MOVC A,@A+DPTR;
SETB P23;
CLR P24;
MOV P0,A;
LCALL DELAY;
MOV P0,#0FFH;
JNB SETKEY,ADJUST;按键按下时去调整时间
;以下是进位程序
MOV A,DISP1;把第一位缓存送入A
CJNE A,#10,SCAN;如果第一位不等于10继续扫描
MOV DISP1,#00H;如果第一位等于10了就把第一位清零
INC DISP2;第二位加1
MOV A,DISP2;
CJNE A,#6,SCAN;如果第二位不等于6继续扫描
MOV DISP2,#00H;
INC DISP3;
MOV A,DISP4;
CJNE A,#2,PM;
MOV A,DISP3;
CJNE A,#4,SCAN;
MOV DISP3,#00H;
AJMP DIS4;
PM:
MOV A,DISP3;
CJNE A,#10,SCAN;
MOV DISP3,#00H;
DIS4:
INC DISP4;
MOV A,DISP4;
CJNE A,#3,SCAN;
MOV DISP4,#00H;
AJMP SCAN;
;
DELAY: ;延时子程序
MOV R7,#2
NOP
D1: MOV R6,#2
DJNZ R6,$
DJNZ R7,D1
RET
;
TAB: DB 88H,0EBH,91H,0A1H,0E2H,0A4H,84H,0E9H,80H,0A0H,0C0H,86H,9CH,83H,94H,0D4H,0FFH
;
;
;
;
;下面程序为设置时间用
ADJUST:
LCALL ADJDELAY;
JB SETKEY,SET1;
LCALL BUZZER;按键滴声
JNB SETKEY,$
CLR TR0; 暂时关闭计时
ADJ4:
SETB P21;
CLR P24;
MOV A,DISP4;
MOVC A,@A+DPTR;
MOV P0,A;显示第四位
JNB SETKEY,ADJ8;如果设置键有动作去调节第3位
JB UPKEY,ADJ4;加键是否按下
LCALL ADJDELAY;
JB UPKEY,ADJ4;延时后再检查加键是否按下
LCALL BUZZER;按键滴声
JNB UPKEY,$;等待加键松开
INC DISP4;第四位加1
MOV A,DISP4;
CJNE A,#3,ADJ4;第四位不等于3转移
MOV DISP4,#00H;第四位等于3清零
AJMP ADJ4;再去显示第四位
ADJ8:
LCALL ADJDELAY;
JB SETKEY,ADJ4;
LCALL BUZZER;按键滴声
JNB SETKEY,$;
ADJ3:
SETB P24;
CLR P23;
MOV A,DISP3;
MOVC A,@A+DPTR;
MOV P0,A;显示第三位
JNB SETKEY,ADJ7;
JB UPKEY,ADJ3;
LCALL ADJDELAY;
JB UPKEY,ADJ3;
LCALL BUZZER;按键滴声
JNB UPKEY,$;
INC DISP3;第3位加1
MOV A,DISP4;
CJNE A,#2,PM1;
MOV A,DISP3;
CJNE A,#4,ADJ3;第3位不等于4转移
MOV DISP3,#00H;第四位等于3清零
AJMP ADJ3;再去显示第四位
PM1:
MOV A,DISP3;
CJNE A,#10,ADJ3;
MOV DISP3,#00H;
AJMP ADJ3;
SET1:
LCALL BUZZER;按键滴声
LCALL BUZZER;按键滴声
JNB SETKEY,$;
NOP;
MOV HALFSEC,#00H;清零秒针
SETB TR0;
LJMP SCAN;
ADJ7:
LCALL ADJDELAY;
JB SETKEY,ADJ3;
LCALL BUZZER;按键滴声
JNB SETKEY,$;
ADJ2:
SETB P23;
CLR P22;
MOV A,DISP2;
MOVC A,@A+DPTR;
MOV P0,A;显示第二位
JNB SETKEY,ADJ6;
JB UPKEY,ADJ2;
LCALL ADJDELAY;
JB UPKEY,ADJ2;
LCALL BUZZER;按键滴声
JNB UPKEY,$;
INC DISP2;第2位加1
MOV A,DISP2;
CJNE A,#6,ADJ2;第2位不等于6转移
MOV DISP2,#00H;第2位等于6清零
AJMP ADJ2;再去显示第2位
ADJ6:
LCALL ADJDELAY;
JB SETKEY,ADJ2;
LCALL BUZZER;按键滴声
JNB SETKEY,$;
ADJ1:
SETB P22;
CLR P21;
MOV A,DISP1;
MOVC A,@A+DPTR;
MOV P0,A;显示第一位
JNB SETKEY,ADJ5;如果SET键有动作转去抖
JB UPKEY,ADJ1;
LCALL ADJDELAY;
JB UPKEY,ADJ1;
LCALL BUZZER;按键滴声
JNB UPKEY,$;
INC DISP1;第1位加1
MOV A,DISP1;
CJNE A,#10,ADJ1;第1位不等于10转移
MOV DISP1,#00H;第1位等于10清零
AJMP ADJ1;再去显示第1位
ADJ5:
LCALL ADJDELAY;
JB SETKEY,ADJ1;
AJMP SET1;
ADJDELAY:;是不是延时40MS
MOV R7,#200
D3: MOV R6,#100
DJNZ R6,$
DJNZ R7,D3
RET
BUZZER: MOV R6,255;蜂鸣子程序
BUZZ1: CPL BUZZ;
MOV R7,#80;
DJNZ R7,$;
DJNZ R6,BUZZ1;
CLR BUZZ;
RET
;以上为设置时间用
;
REMO:
RETI;
;
;
;
TIME0:; TIME0中断处理程序
MOV TH0,#3CH;
MOV TL0,#0B6H;重新放定时预置数15542,用预置数较正时间。
PUSH ACC;机器周期2
PUSH PSW;机器周期2
INC TIMEADD;软件计数器加1,机器周期1
MOV A,TIMEADD;加1后送给A,机器周期1
CJNE A,#10,T_RET;如果A不等于10跳到T_RET,机器周期2
CPL SECLED;取反秒点LED,软件计数器计时半秒,机器周期1
MOV TIMEADD,#00H;软件计数器清零,机器周期1
INC HALFSEC;秒加1,机器周期1
MOV A,HALFSEC;机器周期1
CJNE A,#120,T_RET;把秒针缓存和120比较,不等跳转T_RET,机器周期2
INC DISP1;第一位显示加1,机器周期1
MOV HALFSEC,#00H;清零秒针,机器周期1
T_RET:
POP PSW
POP ACC
RETI
END
以上就是关于数字钟设计 用VHDL语言实现 你怎么做的全部的内容,包括:数字钟设计 用VHDL语言实现 你怎么做的、eda中seltime数字钟译码模块是什么、8051单片机的数字钟汇编程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)