原创 fpga学习日记13,驱动LED和数码管

2013-8-27 17:15 2128 17 18 分类: FPGA/CPLD 文集: 数电,FPGA学习

这算是第二个硬件试验了吧

很简单的代码

一个按键驱动8个LED 的亮灭

按键按下为低电平      LED高电平点亮

(附件为一个LED 流水灯实例和一个数码管显示实例)

 

引脚分配如下

# Copyright (C) 1991-2007 Altera Corporation
# Your use of Altera Corporation's design tools, logic functions
# and other software and tools, and its AMPP partner logic
# functions, and any output files from any of the foregoing
# (including device programming or simulation files), and any
# associated documentation or information are expressly subject
# to the terms and conditions of the Altera Program License
# Subscription Agreement, Altera MegaCore Function License
# Agreement, or other applicable license agreement, including,
# without limitation, that your use is for the sole purpose of
# programming logic devices manufactured by Altera and sold by
# Altera or its authorized distributors.  Please refer to the
# applicable agreement for further details.


# The default values for assignments are stored in the file
#  KeyToLed_assignment_defaults.qdf
# If this file doesn't exist, and for assignments not listed, see file
#  assignment_defaults.qdf

# Altera recommends that you do not modify this file. This
# file is updated automatically by the Quartus II software
# and any changes you make may be lost or overwritten.


set_global_assignment -name FAMILY "Cyclone II"
set_global_assignment -name DEVICE EP2C5T144C8
set_global_assignment -name TOP_LEVEL_ENTITY KeyToLED
set_global_assignment -name ORIGINAL_QUARTUS_VERSION 7.2
set_global_assignment -name PROJECT_CREATION_TIME_DATE "15:59:45  OCTOBER 18, 2009"
set_global_assignment -name LAST_QUARTUS_VERSION 11.0
set_global_assignment -name USE_GENERATED_PHYSICAL_CONSTRAINTS OFF -section_id eda_palace
set_global_assignment -name CYCLONEII_OPTIMIZATION_TECHNIQUE AREA
set_global_assignment -name PARTITION_NETLIST_TYPE SOURCE -section_id Top
set_global_assignment -name PARTITION_COLOR 2147039 -section_id Top
set_global_assignment -name LL_ROOT_REGION ON -section_id "Root Region"
set_global_assignment -name LL_MEMBER_STATE LOCKED -section_id "Root Region"

set_location_assignment PIN_25 -to key[0]
set_location_assignment PIN_24 -to key[1]
set_location_assignment PIN_9 -to key[2]
set_location_assignment PIN_8 -to key[3]

set_location_assignment PIN_27 -to LED[0]
set_location_assignment PIN_26 -to LED[1]
set_location_assignment PIN_7 -to LED[2]
set_location_assignment PIN_4 -to LED[3]
set_location_assignment PIN_3 -to LED[4]
set_location_assignment PIN_144 -to LED[5]
set_location_assignment PIN_143 -to LED[6]
set_location_assignment PIN_142 -to LED[7]


set_global_assignment -name VERILOG_FILE RTL/KeyToLED.v

set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top
set_global_assignment -name PARTITION_FITTER_PRESERVATION_LEVEL PLACEMENT_AND_ROUTING -section_id Top
set_global_assignment -name STRATIX_DEVICE_IO_STANDARD "3.3-V LVTTL" 

 

 

verilog源代码如下

module KeyToLED( 
input         [3:0]       key  ,
output wire   [7:0]       LED  

             );


// key 0 ctrl LED 0-7


// when key is pressed , key input low level, else key input high level
assign LED = ~{ 8{key[0]}} ;                //key value display in beep

endmodule

这里主要巧的是拼接符号{}的妙用 来完成对LED的驱动

pj.jpg

 

 

全编译

下载代码到fpga

 

默认8个led全不亮

按下按键0后 8个led全部点亮

文章评论1条评论)

登录后参与讨论

sead_cn_562752139 2015-2-25 10:46

说的挺好,谢谢!

用户1550903 2015-2-10 09:46

Good

用户421074 2013-9-14 14:43

谢谢分享!

相关推荐阅读
liang890319_284707880 2016-03-22 11:41
[博客大赛]我在搞嵌入式 我有罪
  我在搞嵌入式 我有罪 做嵌入式也有几年了 刚学习的时候书上说嵌入式的定义是以应用为中心,以计算机技术为基础,软硬件可裁剪,适应应用系统对功能、可靠性、成本、体积、功耗等严格要求的专用计...
liang890319_284707880 2015-10-22 11:57
帕萨特迈腾蒙迪欧哪个好
氵灬清风灬说:太小了,没法穿了,懒得换了 junyao00022说:............................... jd272475byp说:宝贝收到啦,衣服质量非常不错,...
liang890319_284707880 2015-10-22 11:56
二手荣威550和二手起亚k2哪个好
二手荣威550和二手起亚k2哪个好   风之乞说:衣服挺好的,就是偏小,已经更换了 梦里水乡0609说:不错 很好  不了不错  赞 四灵之首说:衣服质量不错,韵达快递不行~ ...
liang890319_284707880 2015-10-22 11:55
澳大利亚深海鱼油哪个牌子好
hgjfhgj说:不错  价格便宜  款式不错  开始买中码小了一点  免费给换的  好店家 小杰c子说:非常合适。也很有气质 天佑945说:还可以,性价比高。。。。。。。。。。 Ab...
liang890319_284707880 2015-10-19 11:03
常用DDR sdram和Flash型号
  以下是代码片段: http://blog.csdn.net/myarrow/article/details/7854863   主要是三星 现代 ...
liang890319_284707880 2013-09-29 17:00
ROM FLASH RAM
EPROM、EEPROM、FLASH的总结性区别   http://xdc0363.blog.163.com/blog/static/11546200220...
我要评论
1
17
关闭 站长推荐上一条 /2 下一条