LED流水灯
/*
file name: top_cpld.v
author: akadiao
data:2022.09.27
log: led light
*/
module top_cpld(
input clk, //50Hz
input rst_n,
output [7:0] led
);
//寄存器
reg[31:0] timer;
reg[7:0] led_r;
assign led = led_r;
always @(posedge clk or negedge rst_n)//时钟上升沿 复位下降沿
if(~rst_n)
timer <= 0;//复位 计数器清零
else if(timer == 32'd99_999_999)
timer <= 0;//计数器清零
else
timer <= timer + 1'b1;//计数器+1
always @(posedge clk or negedge rst_n)
if(~rst_n)
led_r <= 8'b0000_0000;//4LED全灭
else if(timer == 32'd24_999_999)//计数器计时1s
led_r <= 8'b0000_0011;//LED1 2 点亮
else if(timer == 32'd49_999_999)//计数器计时2s
led_r <= 8'b0000_1100;//LED3 4点亮
else if(timer == 32'd74_999_999)//计数器计时3s
led_r <= 8'b0011_0000;//LED5 6点亮
else if(timer == 32'd99_999_999)
led_r <= 8'b1100_0000;//LED7 8点亮
else
led_r <= led_r;
endmodule
根据8位LED灯与EPM240引脚I/O对应关系
配置CPLD引脚:
Hardware SetupUSB-Blaster[USB-0]JTAG Mode
下载工程:
LED点阵显示
LED点阵电路:
00IC-EPM240 开发板采用的点阵型号是 10788。8×8LED 点阵共有 16 个引脚,分别控制 8 行和 8 列,行列共同决定其中一个 LED 的亮灭。图中 ROW 为行,L 为列,当行为高电平列为低电平的时候 LED 亮。 因此,点亮对应LED时,将行坐标置高电平,列坐标置低电平即可。
例
显示“牛”字:
采用不断刷新的方式显示
/*
file name: top_cpld.v
author: akadiao
data:2022.10.09
log: led lattice
*/
module top_cpld(
input clk, //50Hz
input rst_n,
output [15:0] H_
);
//寄存器
reg[31:0] timer;
reg[15:0] led_H;
assign H_ = led_H;
always @(posedge clk or negedge rst_n)//时钟上升沿 复位下降沿
if(~rst_n)
timer <= 0;//复位 计数器清零
else if(timer == 32'd00_140_000)
timer <= 0;//计数器清零
else
timer <= timer + 1'b1;//计数器+1
always @(posedge clk or negedge rst_n)
if(~rst_n)
led_H <= 16'b1111_1111_0000_1111;
else if(timer == 32'd00_020_000)
led_H <= 16'b1111_1111_1110_1111;//竖
else if(timer == 32'd00_040_000)
led_H <= 16'b0000_0100_1000_0001;//横1
else if(timer == 32'd00_070_000)
led_H <= 16'b0010_0000_0000_0001;//横2
else if(timer == 32'd00_100_000)
led_H <= 16'b0000_0010_1111_1011;
else if(timer == 32'd00_120_000)
led_H <= 16'b0000_1000_1111_1110;
else
led_H <= led_H;
endmodule