1. 程式人生 > >FPGA學習之數碼管(封裝)顯示時間

FPGA學習之數碼管(封裝)顯示時間

rtu 環境 tro gb2312 配置 fpga 模塊 rtl 顯示時間

一、實驗目的:學習數碼管封裝以及顯示時間
二、實驗環境:FPGA開發板AX301,Quartus ii
三、實驗介紹:將數碼管顯示模塊封裝起來,同時通過不斷讀取RTC時鐘的時分秒值,將之顯示在數碼管。實驗時,將實時時間的時分秒寫入程序,運行程序後可以看到數碼管顯示的時間會不斷的刷新。
四、源碼

module smg_interface_demo
(
    input CLK,
     input RSTn,
     output  RST,
    output SCLK,
    inout SIO,
     output [7:0]SMG_Data,
     output [5:0]Scan_Sig
);

    
/******************************/ wire [23:0]Number_Sig; exp13_demo U1 ( .CLK( CLK ), .RSTn( RSTn ), .Number_Sig(Number_Sig), .RST( RST ), .SCLK( SCLK ), .SIO( SIO ) ); /******************************/ smg_interface U2 ( .CLK( CLK ), .RSTn( RSTn ), .Number_Sig( Number_Sig),
// .Number_Sig( Number_Sig ), // input - from U1 .SMG_Data( SMG_Data ), // output - to top .Scan_Sig( Scan_Sig ) // output - to top ); /******************************/ endmodule

module exp13_demo  //將DS1302的時分秒顯示在六位數碼管上
(
    CLK, RSTn,
     Number_Sig,
     //Second_data0, Second_data1, Mini_data0,Mini_data1,Hour_data0,Hour_data1,
    
// LED, RST, SCLK, SIO ); input CLK; input RSTn; output RST; output SCLK; inout SIO; // output [3:0]LED; // output [19:0]showdata; output [23:0] Number_Sig; // output [7:0]Row_Scan_Sig; // output [5:0]Column_Scan_Sig; // output [3:0]Second_data0; // output [3:0]Second_data1; // output [3:0]Mini_data0; // output [3:0]Mini_data1; // output [3:0]Hour_data0; // output [3:0]Hour_data1; /*******************************/ /******************************/ parameter T100MS = 23d4_999_999; /******************************/ reg [22:0]C1; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) C1 <= 23d0; else if( C1 == T100MS ) C1 <= 23d0; else C1 <= C1 + 1b1; /*******************************************************/ reg [3:0]i; reg [7:0]isStart; reg [7:0]rData; //reg [3:0]rLED; reg [3:0]rSecond_data0; reg [3:0]rSecond_data1; reg [3:0]rMini_data0; reg [3:0]rMini_data1; reg [3:0]rHour_data0; reg [3:0]rHour_data1; reg [23:0]rNum; reg [23:0]rNumber; // always @ ( posedge CLK or negedge RSTn ) // if( !RSTn ) // begin // i <= 4‘d0; // rNum <= 24‘d0; // rNumber <= 24‘d0; // end // else // case( i ) // // 0: // if( C1 == T100MS ) begin rNum[3:0] <= rNum[3:0] + 1‘b1; i <= i + 1‘b1; end // // 1: // if( rNum[3:0] > 4‘d9 ) begin rNum[7:4] <= rNum[7:4] + 1‘b1; rNum[3:0] <= 4‘d0; i <= i + 1‘b1; end // else i <= i + 1‘b1; // // 2: // if( rNum[7:4] > 4‘d9 ) begin rNum[11:8] <= rNum[11:8] + 1‘b1; rNum[7:4] <= 4‘d0; i <= i + 1‘b1; end // else i <= i + 1‘b1; // // 3: // if( rNum[11:8] > 4‘d9 ) begin rNum[15:12] <= rNum[15:12] + 1‘b1; rNum[11:8] <= 4‘d0; i <= i + 1‘b1; end // else i <= i + 1‘b1; // // 4: // if( rNum[15:12] > 4‘d9 ) begin rNum[19:16] <= rNum[19:16] + 1‘b1; rNum[15:12] <= 4‘d0; i <= i + 1‘b1; end // else i <= i + 1‘b1; // // 5: // if( rNum[15:12] > 4‘d9 ) begin rNum[19:16] <= rNum[19:16] + 1‘b1; rNum[15:12] <= 4‘d0; i <= i + 1‘b1; end // else i <= i + 1‘b1; // // 6: // if( rNum[19:16] > 4‘d9 ) begin rNum[23:20] <= rNum[23:20] + 1‘b1; rNum[19:16] <= 4‘d0; end // else i <= i + 1‘b1; // // 7: // if( rNum[23:20] > 4‘d9 ) begin rNum <= 24‘d0; i <= i + 1‘b1; end // else i <= i + 1‘b1; // // 8: // begin rNumber <= rNum; i <= 4‘d0; end // // endcase /*******************************************************/ always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) begin i <= 4d0; isStart <= 8d0; rData <= 8d0; rNum <= 24d0; rNumber <= 24d0; //rLED <= 4‘d0; end else case( i ) 0: if( Done_Sig ) begin isStart <= 8d0; i <= i + 1b1; end else begin isStart <= 8b1000_0000; rData <= 8h00; end 1: if( Done_Sig ) begin isStart <= 8d0; i <= i + 1b1; end else begin isStart <= 8b0100_0000; rData <= { 4d2, 4d0 }; end //HOUR 2: if( Done_Sig ) begin isStart <= 8d0; i <= i + 1b1; end else begin isStart <= 8b0010_0000; rData <= { 4d0, 4d6 }; end//MINITU 3: if( Done_Sig ) begin isStart <= 8d0; i <= i + 1b1; end//SECOND else begin isStart <= 8b0001_0000; rData <= { 4d2, 4d2 }; end 4: //if( Done_Sig ) begin rLED <= Time_Read_Data[3:0];rSecond_data0<= Time_Read_Data[3:0];rSecond_data1<= Time_Read_Data[7:4]; isStart <= 8‘d0; i <= 4‘d4; end if( Done_Sig ) begin rNum[7:4]<=Time_Read_Data[7:4];rNum[3:0]<=Time_Read_Data[3:0];rSecond_data0<= Time_Read_Data[3:0];rSecond_data1<= Time_Read_Data[7:4]; isStart <= 8d0; i <= i + 1b1; end else begin isStart <= 8b0000_0001; end 5: if( Done_Sig ) begin rNum[15:12]<=Time_Read_Data[7:4];rNum[11:8]<=Time_Read_Data[3:0];rMini_data0<= Time_Read_Data[3:0];rMini_data1<= Time_Read_Data[7:4]; isStart <= 8d0; i <= i + 1b1; end else begin isStart <= 8b0000_0010; end 6: if( Done_Sig ) begin rNum[23:20]<=Time_Read_Data[7:4];rNum[19:16]<=Time_Read_Data[3:0];rHour_data0<= Time_Read_Data[3:0];rHour_data1<= Time_Read_Data[7:4]; isStart <= 8d0; i <= i + 1b1; end else begin isStart <= 8b0000_0100; end 7: if(i==7) begin rNumber <= rNum;i<= 4d4;end endcase /********************************************/ wire Done_Sig; wire [7:0]Time_Read_Data; ds1302_module U1 ( .CLK( CLK ), .RSTn( RSTn ), .Start_Sig( isStart ), .Done_Sig( Done_Sig ), .Time_Write_Data( rData ), .Time_Read_Data( Time_Read_Data ), .RST( RST ), .SCLK( SCLK ), .SIO( SIO ) ); /********************************************/ // assign LED = rLED; // assign Second_data0 = rSecond_data0; // assign Second_data1 = rSecond_data1; // assign Mini_data0 = rMini_data0; // assign Mini_data1 = rMini_data1; // assign Hour_data0 = rHour_data0; // assign Hour_data1 = rHour_data0; //assign Number_Sig = rSecond_data0+rSecond_data1*10+rMini_data0*100+rMini_data1*1000+rHour_data0*10000+rHour_data1*100000; // assign //assign Number_Sig[23:20] = rHour_data1; // assign Number_Sig[19:16] = rHour_data0; // assign Number_Sig[15:12] = rMini_data1; // assign Number_Sig[11:8] = rMini_data0; // assign Number_Sig[7:4] = rSecond_data1; // assign Number_Sig[3:0] = rSecond_data0; //assign Number_Sig={rHour_data1,rHour_data0,rMini_data1,rMini_data0,rSecond_data1,rSecond_data0}; //assign Number_Sig = 24‘d123456; assign Number_Sig = rNumber; /*********************************************/ endmodule
module smg_interface
(
    input CLK,
     input RSTn,
     input [23:0]Number_Sig,
     output [7:0]SMG_Data,
     output [5:0]Scan_Sig
);

    /******************************************/
     
     wire [3:0]Number_Data;
     
     smg_control_module U1
     (
        .CLK( CLK ),
         .RSTn( RSTn ),
         .Number_Sig( Number_Sig ),    // input - from top
         .Number_Data( Number_Data )   // output - to U2
     );
     
     /******************************************/
     
    smg_encode_module U2
     (
         .CLK( CLK ),
          .RSTn( RSTn ),
          .Number_Data( Number_Data ),   // input - from U2
          .SMG_Data( SMG_Data )          // output - to top
     );
     
     /*******************************************/
     
     smg_scan_module U3
     (
         .CLK( CLK ),
          .RSTn( RSTn ),
          .Scan_Sig( Scan_Sig )  // output - to top
     );
     
     /*******************************************/
     
     

endmodule

五、RTL圖

技術分享

技術分享技術分享

技術分享

六、總結

前幾次編譯下載程序總是顯示異常,最後發現是PIN管腳問題,以後需要註意檢查硬件配置是否正確。

FPGA學習之數碼管(封裝)顯示時間