




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
北京邮电大学 数字电路与逻辑设计实验报告 实验题目 掷骰子游戏电路的设计与实现 学生姓名 班级 学号 序号 目录 一 设计课题的任务要求 二 系统设计 三 仿真波形及波形分析 四 源程序 五 功能说明及资源利用情况 六 故障及问题分析 七 总结和结论 一 设计课题的任务要求 设计并实现一个掷骰子游戏电路 基本要求 1 电路可供甲乙二人游戏 游戏者甲使用的按键为 BTN0 游戏者乙使 用的按键为 BTN1 2 每按一次按键 代表掷一次骰子 可随机得到 1 6 范围内的两个数 字 3 甲乙按键产生的随机数字分别用数码管 DISP0 DISP1 DISP2 DISP3 显 示 并用 DISP7 显示比赛局数 比赛结束用 8 8 点阵显示获胜方 并伴有声 音效果 4 具体游戏规则如下 1 第一局比赛 甲乙依次各按一次按键 按 键所得两数之和为 7 或 11 者胜 若无 人取胜 则进行第二局比赛 2 第 二局比赛 甲乙每人各按一次按键 按键所得二数之和与第一局比赛相同者获 胜 若无人获胜 则进行第三局比赛 重复进行步骤 2 直到出现胜者为止 3 游戏局数最多进行六局 在第六局比赛时 若重复进行步骤 2 仍未 出现胜者 以按键所得两数之和最大者为获胜方 提高要求 1 增加多人游戏的功能 数码管可分时记录显示每个游戏者 的骰子点数 2 点阵显示增加游戏开机动画 结束动画 并伴有乐曲播放 3 自拟其它功能 二 二 系统设计 1 设计思路 按照实验要求 使用状态机分别表示游戏的不同状态 使用 分频器来控制时钟 控制器实现具体的游戏规则 8 8LED 点阵来显示胜负 数 码管显示局数和甲乙掷出的随机数 随机数用一到六的循环产生 在编译时采 用元件例化来生成各自的模块 流程图如下 2 总体框图 3 分块设计 分别包括分频器 防抖器 随机数的产生 判断器 译码器和显示器 防抖器分频器 显示 输入 控制器 等模块 综合起来实现所要求的功能 分频器 防抖器 随机数的产生 判断器 译码器 显示器 三 仿真波形及波形分析 根据甲先乙后的顺序进行仿真如下 从仿真中可以看出随机数的产生 若时间轴向后移可以将游戏看得更加 清楚 四 源程序 分频器 library ieee use ieee std logic 1164 all entity fenpingqi is port clk in std logic clktmp out std logic end fenpingqi architecture a of fenpingqi is signal tmp integer range 0 to 499 0 signal clktmp1 std logic begin p3 process clk frequent time begin if clk event and clk 1 then if tmp 499 then tmp 0 clktmp1 not clktmp1 else tmp tmp 1 end if end if end process p3 clktmp clktmp1 end a 防抖器 library ieee use ieee std logic 1164 all entity fangdouqi is port clk btn1 btn2 in std logic btn1 en btn2 en out std logic end fangdouqi architecture a of fangdouqi is signal tempcount1 integer range 0 to 5 0 signal tempcount2 integer range 0 to 5 0 begin p5 process clk btn1 btn2 begin if clk event and clk 1 then if btn1 1 then if tempcount1 5 then tempcount1 tempcount1 else tempcount1 tempcount1 1 end if if tempcount1 4 then btn1 en 1 else btn1 en 0 end if else tempcount1 0 end if if btn2 1 then if tempcount2 5 then tempcount2 tempcount2 else tempcount2 tempcount2 1 end if if tempcount2 4 then btn2 en 1 else btn2 en 0 end if else tempcount2 0 end if end if end process p5 end a 计数器 library ieee use ieee std logic 1164 all entity jishuqi is port clktmp in std logic randnum2 out integer range 1 to 12 randnum out integer range 1 to 12 end jishuqi architecture a of jishuqi is signal randnum1 integer range 1 to 12 signal randnum3 integer range 1 to 12 begin p4 process clktmp counter1 begin if clktmp event and clktmp 1 then if randnum1 6 then randnum1 1 else randnum1 randnum1 1 end if if randnum3 7 then randnum3 1 else randnum3 randnum3 1 end if end if if randnum3 7 then randnum2 1 else randnum2 randnum3 end if randnum randnum1 end process p4 end a 掷骰子结果的产生 library ieee use ieee std logic 1164 all entity creaters is port clk in std logic clktmp in std logic btn1 en btn2 en in std logic randnum randnum1 in integer range 1 to 12 count in integer range 0 to 5 sgn11 sgn22 out std logic a1 a2 b1 b2 out integer range 1 to 12 a3 a4 b3 b4 out integer range 1 to 12 end creaters architecture a of creaters is signal a11 a22 b11 b22 integer range 1 to 12 1 signal a33 a44 b33 b44 integer range 1 to 12 signal sgn1 sgn2 std logic 0 begin p1 process a11 a22 a33 sgn1 sgn2 b11 b22 b33 btn1 en btn2 en clktmp begin if clktmp event and clktmp 1 then if sgn1 1 and sgn2 1 then sgn1 0 sgn2 0 end if if btn1 en 1 and sgn1 0 then sgn1 1 a11 randnum get rand num a22 randnum1 a33 randnum1 randnum if count 0 then a44 randnum1 randnum end if end if if btn2 en 1 and sgn1 1 and sgn2 0 then sgn2 1 b11 randnum b22 randnum1 b33 randnum1 randnum if count 0 then b44 randnum1 randnum end if end if end if a1 a11 a2 a22 a3 a33 b1 b11 b2 b22 b3 b33 a4 a44 b4 b44 sgn11 sgn1 sgn22 sgn2 end process p1 end a 判断器 library ieee use ieee std logic 1164 all entity panduanqi is port sgn1 sgn2 in std logic clk in std logic a3 a4 b3 b4 in integer range 1 to 12 disp77 out integer range 1 to 6 count1 out integer range 0 to 5 winsgn out std logic vector 1 downto 0 end panduanqi architecture a of panduanqi is signal count integer range 0 to 5 0 signal disp7 integer range 0 to 5 1 begin p7 process clk a3 a4 b3 b4 sgn1 sgn2 judgment begin if clk event and clk 1 then if sgn1 1 and sgn2 1 then 规定甲先掷乙后掷 if count 0 then if a3 11 or a3 7 then winsgn 10 disp7 disp7 1 count 0 elsif b3 11 or b3 7 then winsgn 01 disp7 disp7 1 count 0 else count count 1 end if elsif count 5 then if a3 11 or a3 7 then winsgn 10 elsif b3 11 or b3 7 then winsgnb3 then winsgn 10 else winsgn 01 end if disp7 disp7 1 count 0 else if a3 a4 then winsgn 10 disp7 disp7 1 count 0 elsif b3 b4 then winsgn 01 disp7 disp7 1 count 0 else count count 1 end if end if end if end if count1 count if disp7 7 then disp77 1 else disp77 disp7 end if end process p7 end a 译码器 library ieee use ieee std logic 1164 all entity yimaqi is port clktmp in std logic a1 a2 b1 b2 in integer range 1 to 12 disp7 in integer range 1 to 6 num out std logic vector 6 downto 0 cat out std logic vector 5 downto 0 end yimaqi architecture a of yimaqi is signal tempcat std logic vector 5 downto 0 signal tempnum integer range 0 to 6 1 signal num1 std logic vector 6 downto 0 signal cycle integer range 0 to 4 0 begin p6 process clktmp translate the num1 to right num begin if clktmp event and clktmp 1 then if cycle 4 then cycle 0 else cycle tempnum a1 tempcat tempnum a2 tempcat tempnum b1 tempcat tempnum b2 tempcat tempnum disp7 tempcatnum1num1num1num1num1num1num1 1011111 end case num num1 cat tempcat end process p6 end a 显示器 library ieee use ieee std logic 1164 all entity xianshiqi is port clk in std logic winsgn in std logic vector 1 downto 0 row out std logic vector 7 downto 0 col out std logic vector 7 downto 0 end xianshiqi architecture a of xianshiqi is signal cyc integer range 0 to 7 0 signal row1 std logic vector 7 downto 0 signal col1 std logic vector 7 downto 0 begin p8 process clk begin if clk event and clk 1 then if cyc 7 then cyc 0 else cycrow1 01111111 col1row1 10111111 col1row1 11011111 col1row1 11101111 col1row1 11110111 col1row1 11111011 col1row1 11111101 col1row1 11111110 col1row1 01111111 col1row1 10111111 col1row1 11011111 col1row1 11101111 col1row1 11110111 col1row1 11111011 col1row1 11111101 col1row1 11111110 col1 11111111 end case else end if end if row row1 col col1 end process p8 end a 五 功能说明及资源利用情况 分频器对固有频率分频提供给控制器 译码器 显示器合适的时钟 防抖 器通过改变频率有效防止毛刺出现 使整个系统工作更加稳定 计数器及骰子 结果的产生通过一到六的循环 同时在时钟作用下取数实现骰子
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 新能源汽车研发团队绩效奖励补充协议
- 2025年高级按摩考试题及答案
- 警察专业面试题及答案解析
- 下肢蜂窝织炎护理查房
- 消防安全检查培训教学课件
- 幼儿园泥工培训活动
- 妊高症病人的观察及护理
- 2025至2030中国贯叶连翘提取物行业产业运行态势及投资规划深度研究报告
- 2025至2030直接驱动主轴行业发展趋势分析与未来投资战略咨询研究报告
- 公司金融产品汇报
- 《最优化方法》研究生配套教学课件
- 危险源辨识以风险评价登记表格范例
- EN61238-1额定电压36kV电力电缆用压接和机械连接器 试验方法和要求
- 专利法全套ppt课件(完整版)
- 自动插件机操作指导书
- 2020年全球森林资源评估
- 培智三年级上册生活数学全册教案
- 高考作文卷面书写
- 三效并流蒸发器的换热面积计算
- 船舶驾驶台资源管理bridge team management
- 心律失常介入培训教材课后练习及答案
评论
0/150
提交评论