[原创] 【Perf-V评测】计时器与点阵模块显示

jinglixixi   2021-5-7 16:47 楼主

前面我们介绍了对I/O功能的使用并实现一些数字电路的功能模拟,但并没有涉及计数器等时序电路的内容,这次就将计时、计数器的内容及点阵模块的显示驱动合起来进行介绍。

1.计时/计数器

计时/计数器的实现离不开系统时钟的使用,若程序每执行一次变进行一次增值处理便是计数器,若考虑到程序每次运行的耗时并与计数器结合起来便是计时器。

其设计的思想就是:对系统单次执行时间进行计数,当达到限值T时,即达到预期的延时时间,若此时计数即可作为计时器来使用。在驱动点阵模块显示时,就是通过延时来使人们看清动态刷新中的显示内容。

 

 

2.点阵模块显示驱动

这里使用的点阵模块是LG7088BH,其资料比较少见,经实测其引脚排列关系如图1所示。

image.png 图1 LG7088BH引脚分布

在驱动点阵模块显示时,是使用Arduino接口所提供的引脚,并使用D2~D9来控制点阵模块的行控制,而使用D10~13来控制列处理。当然,在考虑到引脚资源紧缺的情况下,可以3-8译码器来辅助控制。

有人会问为什么不使用D0和D1,经实际测试这2个引脚未能点亮点阵模块。

在连接固定引脚的情况下,可实现点的显示,见图2所示。在列引脚固定接低电平的,而依次点亮各行的情况下,则显示出一条直线,见图3所示。

image.png 图2 点的显示

 

image.png 图3 线的显示

若设计一个状态机,使其有8个状态,且对应一行点阵显示的话,则可在状态机的运行过程中实现点阵模块的刷新显示。

实现直线显示的程序如下:

module led(clk, rst_n, sw, pio_led  );

        input clk;

        input rst_n;

        input sw;

        output reg  [12:0] pio_led;

        reg [25:0] cnt;

        reg [3:0] state;

        parameter T = 0_100000;//10_000000;

        always @ (posedge clk or negedge rst_n)

        begin

            if(!rst_n)

             begin

                pio_led <= 13'd0;

                cnt <= 0;

                state <= 0;

             end

          else if(sw)

            begin

                case(state)

                    0: begin

                        pio_led <= 13'b1000_000_000_100;

                        if(cnt == T)

                            begin

                                cnt <= 0;

                                state <= 1;

                            end

                        else

                            begin

                                cnt <= cnt + 1;

                                state <= 0;

                            end

                        end

                    1: begin

                            pio_led <= 13'b1000_000_001_000;

                            if(cnt == T)

                                begin

                                    cnt <= 0;

                                    state <= 2;

                                end

                            else

                                begin

                                    cnt <= cnt + 1;

                                    state <= 1;

                                end

                            end

                    2: begin

                                pio_led <= 13'b1000_000_010_000;

                                if(cnt == T)

                                    begin

                                        cnt <= 0;

                                        state <= 3;

                                    end

                                else

                                    begin

                                        cnt <= cnt + 1;

                                        state <= 2;

                                    end

                         end

                         

                    3: begin

                                    pio_led <= 13'b1000_000_100_000;

                                    if(cnt == T)

                                        begin

                                            cnt <= 0;

                                            state <= 4;

                                        end

                                    else

                                        begin

                                            cnt <= cnt + 1;

                                            state <= 3;

                                        end

                         end

                    4: begin

                                        pio_led <= 13'b1000_001_000_000;

                                        if(cnt == T)

                                            begin

                                                cnt <= 0;

                                                state <= 5;

                                            end

                                        else

                                            begin

                                                cnt <= cnt + 1;

                                                state <= 4;

                                            end

                        end

                    5: begin

                            pio_led <= 13'b1000_010_000_000;

                            if(cnt == T)

                                begin

                                    cnt <= 0;

                                    state <= 6;

                                end

                            else

                                begin

                                    cnt <= cnt + 1;

                                    state <= 5;

                                end

                      end

                    6: begin

                          pio_led <= 13'b1000_100_000_000;

                          if(cnt == T)

                              begin

                                  cnt <= 0;

                                  state <= 7;

                              end

                          else

                              begin

                                  cnt <= cnt + 1;

                                  state <= 6;

                              end

                          end

                    7: begin

                          pio_led <= 13'b1001_000_000_000;

                          if(cnt == T)

                              begin

                                  cnt <= 0;

                                  state <= 0;

                              end

                          else

                              begin

                                  cnt <= cnt + 1;

                                  state <= 7;

                              end

                          end

                endcase  

            end

        end

endmodule

要实现字符的显示,可借助工具软件来提取字模,其提取方式如图4所示。

image.png 图4 提取字模

以“1”的字模为例,其字模为:

0x00, 0x00,0x00,0x60, 0x20,0x20, 0x70,0x00,

转换为二进制数即可看出效果:

image.png

image.png

image.png

若配合开关SW1~ SW4的控制,则可切换显示的内容。

直线显示动画:

本帖最后由 jinglixixi 于 2021-5-9 00:46 编辑
  • VID_20210507_101353.gif

回复评论 (3)

LG7088BH的资料确实少,不过一般是先看手册把矩阵的8根行线和8根列线的分别对应引脚关系看明白就行

点赞  2021-5-7 21:44
引用: 火辣西米秀 发表于 2021-5-7 21:44 LG7088BH的资料确实少,不过一般是先看手册把矩阵的8根行线和8根列线的分别对应引脚关系看明白就行

然!

点赞  2021-5-8 09:07

卧槽,verilog,完全没看懂

默认摸鱼,再摸鱼。2022、9、28
点赞  2021-5-8 09:36
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复