共享一个“红芯电子”实现呼吸灯的源码
共享一个“红芯电子”实现呼吸灯的工程源码:
//==============================================================================
// File Name : LED_BREATHING.v
// Module Name : LED_BREATHING
// Description : This is a breathing led module
// Author : xsyan1225(红芯电子_飞哥)
// HomePage : http://shop57125352.taobao.com/
// Date : 2012/09/06
// Rev. : 0.1
//==============================================================================
// 呼吸灯
`define UD //#1
module LED_BREATHING
(
SYSCLK_50M,
RST_B,
LED
//TP
);
//==============================================================================
// Input and output declaration
//==============================================================================
input SYSCLK_50M;
input RST_B;
output LED;
//output TP;//用于测试
//==============================================================================
// Wire and reg declaration
//==============================================================================
wire SYSCLK_50M;
wire RST_B;
reg LED;
//wire TP = LED;
//==============================================================================
// Wire and reg in the module
//==============================================================================
reg TIME_CNT;
wire TIME_CNT_N;
reg PWM_WIDTH;
wire PWM_WIDTH_N;
reg PWM_ADJ;
wire PWM_ADJ_N;
wire LED_N;
//==============================================================================
// Logic
//==============================================================================
always @(posedge SYSCLK_50M or negedge RST_B)
begin
if(!RST_B)
TIME_CNT <= `UD 27'h0;
else
TIME_CNT <= `UD TIME_CNT_N;
end
// 自由计数器
assign TIME_CNT_N = TIME_CNT + 27'h1;
//------------------------------------------------------------------------------
always @(posedge SYSCLK_50M or negedge RST_B)
begin
if(!RST_B)
PWM_ADJ <= `UD 6'h0;
else
PWM_ADJ <= `UD PWM_ADJ_N;
end
// 第26位用于标识呼和吸的切换点,2^26 = 1.34秒(约等于),完成一次呼吸总时长约2.7秒
assign PWM_ADJ_N = TIME_CNT ? TIME_CNT : ~TIME_CNT ;
//------------------------------------------------------------------------------
always @(posedge SYSCLK_50M or negedge RST_B)
begin
if(!RST_B)
PWM_WIDTH <= `UD 7'h3f;
else
PWM_WIDTH <= `UD PWM_WIDTH_N;
end
//利用寄存器溢出位产生的占空比不同来驱动 LED 实现呼吸效果
//PWM_ADJ 用于控制脉宽
assign PWM_WIDTH_N = PWM_WIDTH + PWM_ADJ;
//------------------------------------------------------------------------------
always @(posedge SYSCLK_50M or negedge RST_B)
begin
if(!RST_B)
LED <= `UD 6'h3f;
else
LED <= `UD LED_N;
end
//6个灯一起呼吸
assign LED_N = {{3{PWM_WIDTH}},{3{~PWM_WIDTH}}};
endmodule
//==============================================================================
// End of file
//==============================================================================
有没有红芯电子FPGA的光盘源程序啊,传上来吧,我看了笔记还是不错的 刚才试了一下,效果很一般,没有诺基亚手机的呼吸灯做得逼真。 小气。。。 求光盘资料,谢谢! 原来是用FPGA实现的,mark
可以用的。不错,效果确实不是很好,自己改进一下,效果会好的
页:
[1]