北邮数电实验 - PS2键盘 - 图文

更新时间:2024-01-25 02:02:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

数字电路与逻辑设计实

实验名称:姓名:学号:班级:验报告

PS2键盘接口设计

金小敏

2011年1月12日

一、实验任务

设计制作一个PS/2 键盘接口控制器。 (a)基本功能

按照PS/2 键盘接口标准设计一个控制器,接收PS/2 键盘发送的数据,用数码 管和8×8 点阵显示接收到的键值。

其中0~9 用数码管显示,A~Z用8×8 点阵显示,接收到其他键值则不显示。 (b)拓展功能

(i)实现显示汉字、符号:按F3显示汉字“中”、按F4显示汉字“国”、按F5显示心型符号;

(ii)实现音乐播放控制:按F1开始播放音乐、按F2停止播放音乐。

二、系统设计 (a)设计思路

系统总的分为输入输出两大部分。输入即为PS2键盘,输出有显示输出:8×8点阵、数码管,声音输出。

根据PS2的协议,PS2按键的输出包含扫描码和断码,本次实验只使用扫描码。将扫描码解码出来后,即可作为不同的判断条件来控制输出。

输出包括数码管显示、点阵显示和声音输出。将其设计为:0~9按键时只有数码管显示对应数字,点阵熄灭;A~Z时只有点阵显示,数码管熄灭;按F1时,开始播放音乐并且点阵显示音乐符号“?”;按F2时,停止播放音乐并且点阵熄灭;按F3时显示汉字“中”;按F4显示汉字“国”;按F5显示“?”。

程序设计为四大模块:解码模块、显示模块、分频模块、音乐模块。

(b)总体框图

(i)系统模块

键盘输入

PS2解码模块 显示模块 音乐模块 分频模块

(ii)状态转移图

(c)分块设计:

(1)PS2解码模块 ①输入输出框图:

ret SCANCODE(8解码位) p_clk 模块 p_dat

ret:选择信号

p_clk:PS2键盘时钟信号 p_dat:PS2键盘数据信号 ②原理及算法:

从键盘/鼠标发送到主机的数据在时钟信号的下降沿当时钟从高变到低的时候被读取从主机发送到键盘/鼠标的数据在上升沿当时钟从低变到高的时候被读取不管通讯的方向怎样键盘/鼠标总是产生时钟信号。一次数据组成为:1位起始位(总为0),8位数据位(低位在前),1位奇校验位,1位停止位(总为1)。

键盘接收数据的格式 1个起始位 8个数据位 1个奇偶校验位 1个停止位 1个应答位 总是逻辑0 (LSB)低位在前 奇校验 总是逻辑1 仅用在主机对设备的通讯中 由于本次实验只用到扫描码,所以只要接收第一段数据即可。建立一个process,以p_clk位触发信号,将其中的8位数据位保存起来即可(起始位、奇校验位、停止位均不解码),由于8位数据是从低到高的顺序,所以在解码时需要进行移位操作。解码完后将8位数据(已经按从高到低排好)作为输出。 (2)显示模块 ①输入输出框图:

col row a_to_g cat 显示 ret 模块 datain

clkshow ret:选择信号

datain:数据输入(即解码后的数据) clkshow:点阵扫描时钟

col:点阵行控制 row:点阵列控制 a_to_g:数码管段控制 cat: 数码管片选

②原理及算法简介:

由解码模块解码输出的8位数据及时PS2键盘的各个按键的扫描码,按照PS2协议中的关于各个按键的编码即可以对不同的按键进行区分,PS2有3套编码,但是第二套扫编码码最为常用,本次实验所用键盘是按第二套编码。

例如在第二套编码中,“A”的扫描码编码为1CH、“1”的扫描码编码为16H,所以在使用数码管显示0~9时,使用case-when语句即可。在使用点阵显示26个字母是,使用点阵进行扫描,设计原理如下图结构。

扫描显示26个字母与2个汉字以及2个符号,将他们的扫面数据存放在一个3维数组中,由于编码的量比较大,所以采用软件编码的办法,找了一款“字模”软件,来进行编码,其中的一些需要人工的修改一下。软件截图如下:

(3)分频模块

①输入输出框图:

频 showclk 模

块 clk

clk:时钟输出(50MHz)

showclk:分频输出(为8*8点阵扫描分频,音乐模块的多个分频在音乐模块内完成) ②原理及算法简介:

由于点阵显示不需要十分精确的分频,只要满足人的视觉暂留即可,所以采用如下的算法,相对来说比较高效,不需要通过一般地以计数来分频的算法,变该算法的分频为2的幂数分频。程序如下

process(clk)

variable count : std_logic_vector(19 downto 0):=X\begin

if(rising_edge(clk))then count:=count+1; end if;

clkshow<=count(10); end process;

(4)音乐模块

①输入输出框图:

乐 clk 模 beep 块 cs

clk:时钟输入(50MHz) cs:选择信号

beep:蜂鸣器输出 ②原理及算法简介:

蜂鸣器演奏音乐基本都是单音频率,它不包含相应幅度的谐波频率,也就是说不能象电子琴那样能奏出多种音色的声音。因此蜂鸣器奏乐只需弄清楚两个概念即可,也就是“音调”和“节拍”。音调表示一个音符唱多高的频率,节拍表示一个音符唱多长的时间。在音乐中所谓“音调”,其实就是我们常说的“音高”。在音乐中常把中央C上方的A 音定为标准音高,其频率f=440Hz。当两个声音信号的频率相差一倍时,也即f2=2f1 时,则称f2 比f1 高一个倍频程, 在音乐中1(do)与1,2(ruai)与.2??正好相差一个倍频程,在音乐学中称它相差一个八度音。在一个八度音内,有12 个半音。以1—i 八音区为例, 12 个半音是:1—#1、#1—2、2—#2、#2—3、3—4、4—#4,#4—5、5 一#5、#5—6、6—#6、#6—7、7—i。这12 个音阶的分度基本上是以对数关系来划分的如果我们只要知道了这十二个音符的音高,也就是其基本音调的频率,我们就可根据倍频程的关系得到其他音符基本音调

的频率。

采用分频的办法产生不同的频率,再对对应的乐曲进行编码。 例如乐曲《仙剑问情》编码如下(以0,0结束):

MUSIC:RAM:=(13,8,12,8,13,32,13,8,12,8,13,32,13,8,12,8,13,8,16,8,15,8,13,8,12,32,11,8,12,8,13,32,13,8,12,8,13,32,13,8,12,8,13,8,17,8,16,8,15,8,13,32,13,8,15,8,16,32,16,8,21,8,16,32,15,8,13,8,13,8,12,8,12,32,12,32,11,8,12,8,13,32,13,8,15,8,13,32,13,8,15,8,13,32,13,8,11,8,11,8,12,8,12,32,12,32,13,8,12,8,13,32,13,8,12,8,13,32,13,8,12,8,13,8,16,8,15,8,16,40,21,8,16,40,21,8,15,8,16,8,21,8,17,8,16,8,15,8,13,8,15,8,16,32,16,32,16,32,16,8,15,8,16,32,16,32,16,32,13,8,15,8,16,8,21,8,16,32,16,32,16,32,15,32,15,32,15,32,13,8,15,8,16,32,16,8,21,8,15,40,13,8,12,32,12,32,15,32,12,32,13,40,16,8,15,32,12,32,13,32,13,32,12,32,13,8,12,8,11,32,11,32,11,32,12,8,11,8,6,32,11,32,12,32,13,32,15,40,16,8,13,32,11,32,12,32,12,32,13,32,15,32,16,40,21,8,15,32,13,32,12,32,12,32,15,32,12,32,13,40,16,8,15,32,13,32,15,32,15,32,16,32,21,32,22,32,22,32,16,40,15,8,15,32,15,16,16,32,21,32,23,32,22,32,21,32,15,32,16,32,16,32,16,32,0,0)

三、仿真波形及波形分析:

对PS2解码模块进行仿真,输出为数码管的各个段。ps2_data输入为数字2,其扫描码为1EH,即00011110,在串口通信中数据从高到低,所以ps2_data在ps2_clk的第二个下降沿后输入为01111000。

仿真结果如下图所示,输出为a_to_g(7 downto 0)=01011011,数码管输出数字2,仿真结果与实际相符。

在仿真时要将ret先拉高,然后拉低作为开关信号,ps2_clk的第一个下降沿后是起始信号

四、源程序 见附页

五、功能说明:

功能1:实现按键盘阿拉伯数字0~9在数码管上显示如下图:

功能2:实现按PS2键盘字母A~Z在8*8点阵上显示如下图

功能3:实现按PS2按F3、F4、F5在8*8点整上显示汉字图形如下图 汉字“中”

汉字“国”

心形符号

功能4:利用PS2键盘的按键控制音乐播放,播放时点阵显示音乐符号“?”,其点阵显示如下图

六、元器件清单及资源利用情况:

(1)此次实验使用了8*8点阵、数码管、PS2键盘、开发板主芯片型号为:EMP11270T144C5。 (2)利用情况:

(i)未增加音乐播放器前宏单元的使用情况 使用宏单元总数为:334个 其中:

分频模块:11个 PS2解码模块:28个

显示模块:295个

(ii)增加了音乐播放器前宏单元的使用情况 使用宏单元总数为:334个 其中:

分频模块:11个 PS2解码模块:28个

显示模块:297个 音乐模块:885个

七、故障及问题分析

问题1:对于PS2的解码的方法的选择,有2种办法,一种是使用比较高的频率去“主动”扫描发送来的数据,另一种办法就是以PS2发送的p_clk为时钟来读取发送来的数据。

解决办法:选择第二种办法,这种办法的代码相对简单,虽然不如前者的精度高,但是还是在可接受范围内的。

问题2:PS2解码时的扫描码保存问题,由于PS2键盘的串行数据一般为3帧,即扫描码和断码,如果只使用一个8位数组的话,其中的内容是变化的,并不是扫描码,如果将断码也解码的话对本次实验来说是不需要的。

解决办法:设置一个计数器以它的值的大小来确定扫描码是否解码完毕,若计数值小于8则代表还未解码完,否则解码完成,将解码结果送至相应数组即可。

问题3:8*8的点阵显示26个字母和一些其他符号,这需要比较大量的编码,如果全采取人工编码的话,工作量比较大且容易出错。

解决办法:使用用字模软件来进行编码,这样不仅节省时间并且编码出来的图形较为美观。

八、 实验总结

这次选择PS2键盘解码实验,一方面是由于在本学期的微机原理与接口技术中有关串通信的介绍,想借此机会能将理论实用化,并且在实际当中串行通信用的比较多,虽然具体细节会有所差异但是基本理论是一样的,掌握一种其他的就可以在此基础加以修改后来应用;令一方面原因是键盘在实际应用当中更加经济高效:一般会使用的还有矩阵键盘,以4*4矩阵键盘为例,采用扫描法的话要使用8个IO口,这样才能获得16个按键,但是对硬件的资源占得比较多,“性价比”不高,但是PS2键盘只需占用2个IO口就可以得到一百多个按键,基本上需要按键的地方,能满足要

求,节省很多资源。

其次是对于模块化编程的一些理解:

模块化编程将要使用的各个功能封装在一个模块中,只需对外提供输入输出接口即可。这样做的好处是能使一个比较大的工程显得条理清楚,各个模块都有自己特定的作用,便于以后查找错误或是对其中的一些功能进行修改。并且使用模块化后,编写的模块可以作为一个很通用的模块去使用,比如这次实验的PS2解码模块、音乐模块等,都可以在以后别的工程中去使用,大大减少了工作量,当然也便于自己平时对程序积累,可以将一些经常的模块保留下来,再使用时只要做简单的修改即可,这就好像日常生活中的汽车零件一样,是很通用的,可以大大提高编程效率。

还有就是对于VHDL语言的一些想法:

VHDL全称是Very-High-Speed Integrated Circuit HardwareDescription Language(超高速集成电路硬件描述语言),为什么会对VHDL语言产生一些“想法”呢?主要是在编程过程中老是摆脱不了C语言的一些思维,很难完全地使用VHDL的思维去解决问题,或者说是不能很熟练地使用VHDL。通过编写这次的实验程序,自己也对两者有了一些理解:VHDL语言是硬件描述语言,也就是说是用来描述电路的,写VHDL的时候有点像搭一个电路, 同一个时刻电路的不同部分都可以在运行,比如VHDL中的PROCESS就是并行的。 C语言是软件语言,程序的每一行是按顺序执行下来的,只能一条一条的执行,一个时刻只有一条指令在执行。也就是说编写VHDL时要多应用一些电路,特别是数字电路的思维,比如常用的芯片上的一些片选、时钟和使能等接线的思维就可以用在VHDL的编程之中。

再有就是对于CPLD(或FPGA)和单片机的区别与理解:

暑期电子工艺实习做的是单片机,自己平时也使用过单片机,编写过单片机解码PS2键盘的程序,所以对两者的区别也有了一定的理解:单片机可以理解为集成在单一芯片上的微型计算机系统,在加电后ROM中的程序会像计算机内存中的程序一样得到逐条的执行。CPLD(或FPGA)则是操控层次更低,所以自由度更大的芯片,提供了大量的与非门、或非门等基本数字器件,是十分灵活的。可以这样认为,利用 CPLD(或FPGA)可以自己“编”出一个单片机出来,单片机更像是已经固化的电子器件。当然不能说由此得出谁优谁劣,两者的专长不一,如果在一些简单或是对硬件资源以及速度要求不高的控制场合,选择单片机就比较合适,单片机成本低,并且单片机中已经有中断、位操作等方便的功能,所以开发相对简单。但是由于单片机硬件资源有限速度也不是很高。所以在一些对此要求较高的场合就要考虑别的器件,CPLD(或FPGA)的硬件资源相对丰富,并且运行速度快,在信号处理方面也比较强,是一个不错的选择。

最后就是一些自己体会与感悟。感觉只要坚持下来就会有所结果的,自己的程序是直到验收前一周的周末在开放实验室中调试出来的,确实花了比较多的时间,但是做出来后就很有成就感,收获不小。还有就是要懂得取舍,本来自己对于PS2的解码还要增加按2个键时(比如Ctrl+A)时,8*8点阵以不同的颜色来显示对应字母,但是时间太紧,只有舍弃,将基本功能更好地完善。

附页:

(1)顶层程序:

library IEEE;

use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity myps is port(

ret : in std_logic;--选择信号 clk : in std_logic;--输入时钟(50MHz) ps2clk : in std_logic;--PS2键盘时钟信号 ps2data : in std_logic;--PS2键盘数据信号 a_to_g : out STD_LOGIC_VECTOR (0 to 7);--数码管段信号 row:out std_logic_vector(0 to 7);--点阵列输出 col:out std_logic_vector(0 to 7);--点阵行输出 cat:out std_logic_vector(5 downto 0);--数码管片选 MMM:out std_logic--蜂鸣器输出 ); end myps;

architecture Behavioral of myps is signal clkshow,cs : std_logic;

signal dat : std_logic_vector(7 downto 0); component divclk is--分频模块声明 port(

clk : in std_logic; ------50MHZ clkshow : out std_logic );

end component;

component key is--ps2解码模块声明 port( ret : in std_logic; p_clk : in std_logic; p_dat: in std_logic; SCAN_CODE:out std_logic_vector(7 downto 0) );

end component;

component disp is--显示模块声明 port( ret : in std_logic; a_to_g:out std_logic_vector(7 downto 0); cat:out std_logic_vector(5 downto 0); row:out std_logic_vector(7 downto 0); col:out std_logic_vector(7 downto 0); datain:in std_logic_vector(7 downto 0); clkshow: in std_logic; cs:out std_logic );

end component;

component MUSIC is--音乐模块声明 PORT(CLK:IN STD_LOGIC; cs :IN STD_LOGIC; MMM:OUT STD_LOGIC );

end component;

begin

inst1: divclk port map(clk,clkshow);

inst2: key port map(ret,ps2clk,ps2data,dat);

inst3: disp port map(ret,a_to_g,cat,row,col,dat,clkshow,cs); inst4: MUSIC port map(clk,cs,MMM); end Behavioral;

(2)分频程序(为8*8点阵扫描分频) library IEEE;

use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity divclk is port(

clk : in std_logic; ------50MHZ clkshow : out std_logic---分频输出 ); end divclk;

architecture Behavioral of divclk is begin

process(clk)

variable count : std_logic_vector(19 downto 0):=X\begin

if(rising_edge(clk))then count:=count+1; end if;

clkshow<=count(10);---2^10分频 end process; end Behavioral; (3)PS2解码程序 library IEEE;

use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity key is

port( ret : in std_logic; p_clk : in std_logic; p_dat: in std_logic; SCAN_CODE:out std_logic_vector(7 downto 0) );

end key;

architecture Beh of key is

signal count: std_logic_vector(3 downto 0); signal red:std_logic;

signal Trans_Input: std_logic_vector(8 downto 0); --signal SCAN_CODE:std_logic_vector(7 downto 0); begin process begin

wait until(p_clk'event and p_clk='0');---等待ps_clk的下降沿 if (ret='1') then count <=\选择信号为1则不执行解码 red<='0';

else if (p_dat='0' and red='0') then red <='1'; else if (red ='1')then

if count <\未解码完毕 count<=count+1;

Trans_Input(7 downto 0)<=Trans_Input(8 downto 1);--移位操作 Trans_Input(8)<=p_dat;

else SCAN_CODE<=Trans_Input(7 downto 0);---将解码好的数据赋予 red <='0'; --- SCAN_CODE count<=\end if; end if; end if; end if;

end process; end Beh;

(4)显示模块程序 library IEEE;

use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity disp is

port( ret : in std_logic; a_to_g:out std_logic_vector(0 to 7); row:out std_logic_vector(0 to 7); col:out std_logic_vector(0 to 7); cat:out std_logic_vector(5 downto 0); datain:in std_logic_vector(7 downto 0); clkshow:in std_logic; cs:out std_logic ); end disp;

architecture Beh of disp is Type Showbuf is Array( 0 to 7 ) of std_logic_vector( 7 downto 0); Type Conbuf is array( 0 to 30) of showbuf;--定义3维数组存放各

---图形

signal I : integer range 0 to 7;---列显示计数器

signal J : integer range 0 to 30;--对应不同字母图形 CONSTANT col_buf:Showbuf :=

(\11110\使相应的列可显示

CONSTANT show : ConBuf :=( --字母A~Z和图形的编码 (

\,使开始时点阵熄灭 \ \ \ \ \ \ \ ), (

\\\\\\\\), (

\\\\\\\\), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\

\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\

\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\

\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\\\\\\\\ ), (

\乐符--F1~F2--27 \\\

\\\\ ), (

\“中”--F3--28 \\\\\\\ ), (

\“国”--F4--29 \\\\\\\), (

\心形符号--F5--30 \\\\\\\) ); begin

process(datain,ret) begin

cat<=\case datain IS when X\ when X\ when X\ when X\ when X\

when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\ when X\,奏乐 when X\,停止奏乐 when X\,显示汉字“中” when X\,显示汉字“国” when X\“显示心形符号” when others => a_to_g<=\点阵、数码管均熄灭 end case; end process;

Process( J)---点阵显示 Begin

If ( clkshow'event and clkshow ='1') then if(I=9)then I<=0; else

row<=show(J)(I);--列扫描 col<=col_buf(I);--行扫描 I<=I+1;

End if; end if;

End process; end Beh;

(5)音乐模块程序 library ieee;

use ieee.std_logic_1164.all; entity music is

port(clk:in std_logic; cs :in std_logic; mmm:out std_logic); end entity;

architecture bhv of music is

type ram is array(0 to 325) of integer range 0 to 1000; signal

music:ram:=(13,8,12,8,13,32,13,8,12,8,13,32,13,8,12,8,13,8,16,8,15,8,13,8,12,32,11,8,12,8,13,32,13,8,12,8,13,32,13,8,12,8,

13,8,17,8,16,8,15,8,13,32,13,8,15,8,16,32,16,8,21,8,16,32,15,8,13,8,13,8,12,8,12,32,12,32,11,8,12,8,13,32,13,8,15,8,13,32,13,8,15,

8,13,32,13,8,11,8,11,8,12,8,12,32,12,32,13,8,12,8,13,32,13,8,12,8,13,32,13,8,12,8,13,8,16,8,15,8,16,40,21,8,16,40,21,8,15,8,16,8,21,

8,17,8,16,8,15,8,13,8,15,8,16,32,16,32,16,32,16,8,15,8,16,32,16,32,16,32,13,8,15,8,16,8,21,8,16,32,16,32,16,32,15,32,15,32,15,32,13,

8,15,8,16,32,16,8,21,8,15,40,13,8,12,32,12,32,15,32,12,32,13,40,16,8,15,32,12,32,13,32,13,32,12,32,13,8,12,8,11,32,11,32,11,32,12,8,

11,8,6,32,11,32,12,32,13,32,15,40,16,8,13,32,11,32,12,32,12,32,13,32,15,32,16,40,21,8,15,32,13,32,12,32,12,32,15,32,12,32,13,40,16,8,

15,32,13,32,15,32,15,32,16,32,21,32,22,32,22,32,16,40,15,8,15,32,15,16,16,32,21,32,23,32,22,32,21,32,15,32,16,32,16,32,16,32,0,0);--音乐数据《仙剑问情》 signal yindiao:integer range 0 to 1000; signal clk_pai:std_logic; signal

clk77,clk66,clk55,clk44,clk33,clk22,clk11,clk7,clk6,clk5,clk4,clk3,clk2,clk1,clkg,clkf,clke,clkd,clkc,clkb,clka:std_logic; begin

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<3010 then counter0:=counter0+1; else counter0:=0; clk77<=not clk77; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<3378 then counter0:=counter0+1; else counter0:=0; clk66<=not clk66; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<3791 then counter0:=counter0+1; else counter0:=0; clk55<=not clk55; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<4255 then counter0:=counter0+1; else counter0:=0; clk44<=not clk44; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<4509 then counter0:=counter0+1; else counter0:=0; clk33<=not clk33; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<5061 then counter0:=counter0+1; else counter0:=0; clk22<=not clk22; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<5682 then counter0:=counter0+1; else counter0:=0; clk11<=not clk11; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<6017 then counter0:=counter0+1; else counter0:=0; clk7<=not clk7; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<6757 then counter0:=counter0+1; else counter0:=0; clk6<=not clk6; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<7587 then counter0:=counter0+1; else counter0:=0; clk5<=not clk5; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<8518 then counter0:=counter0+1; else counter0:=0; clk4<=not clk4; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<9025 then counter0:=counter0+1; else counter0:=0; clk3<=not clk3; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<10121 then counter0:=counter0+1; else counter0:=0; clk2<=not clk2; end if;

end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<11364 then counter0:=counter0+1; else counter0:=0; clk1<=not clk1; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<12048 then counter0:=counter0+1; else counter0:=0; clkg<=not clkg; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(cs) then if counter0<13514 then counter0:=counter0+1; else counter0:=0; clkf<=not clkf; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<15152 then counter0:=counter0+1; else counter0:=0; clke<=not clke;

end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<17007 then counter0:=counter0+1; else counter0:=0; clkd<=not clkd; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<18051 then counter0:=counter0+1; else counter0:=0; clkc<=not clkc; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<20243 then counter0:=counter0+1; else counter0:=0; clkb<=not clkb; end if; end if;

end process;

process(cs)

variable counter0:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter0<22727 then counter0:=counter0+1; else counter0:=0;

clka<=not clka; end if; end if;

end process;

process(cs)--1/32pai

variable counter:integer range 0 to 10000000; begin

if rising_edge(clk) then if counter<156250 then counter:=counter+1; else counter:=0;

clk_pai<=not clk_pai; end if; end if;

end process;

process(clk_pai)

variable nnn:integer range 0 to 64; variable num:integer range 0 to 1000; begin

if rising_edge(clk_pai) then nnn:=nnn+1;

if music(num)/=0 then

if nnn<=music(num+1) then yindiao<=music(num); else num:=num+2; nnn:=0; end if;

else num:=0; end if; end if;

end process;

process(cs) begin

if(cs='0') then mmm<='0';

else if rising_edge(clk) then case yindiao is

when 1=>mmm<=clka;--低音的哆 when 2=>mmm<=clkb; when 3=>mmm<=clkc; when 4=>mmm<=clkd; when 5=>mmm<=clke; when 6=>mmm<=clkf; when 7=>mmm<=clkg; when 11=>mmm<=clk1;

when 12=>mmm<=clk2; when 13=>mmm<=clk3; when 14=>mmm<=clk4; when 15=>mmm<=clk5; when 16=>mmm<=clk6; when 17=>mmm<=clk7; when 21=>mmm<=clk11; when 22=>mmm<=clk22; when 23=>mmm<=clk33; when 24=>mmm<=clk44; when 25=>mmm<=clk55; when 26=>mmm<=clk66; when 27=>mmm<=clk77; when 0 =>null;

when others=>null; end case; end if; end if;

end process;

end architecture;

when 12=>mmm<=clk2; when 13=>mmm<=clk3; when 14=>mmm<=clk4; when 15=>mmm<=clk5; when 16=>mmm<=clk6; when 17=>mmm<=clk7; when 21=>mmm<=clk11; when 22=>mmm<=clk22; when 23=>mmm<=clk33; when 24=>mmm<=clk44; when 25=>mmm<=clk55; when 26=>mmm<=clk66; when 27=>mmm<=clk77; when 0 =>null;

when others=>null; end case; end if; end if;

end process;

end architecture;

本文来源:https://www.bwwdw.com/article/47yw.html

Top