码迷,mamicode.com
首页 > 其他好文 > 详细

FPGA六位共阳极数码管动态显示

时间:2014-10-23 09:16:32      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   ar   sp   div   log   ad   

  1 `timescale 1ns/1ps
  2 module adc_dis(
  3                clk ,
  4                     rst_n ,       
  5                sm_seg ,
  6                     sm_bit
  7                     );
  8                     
  9 input clk;//50HZ
 10 input rst_n;
 11 output[7:0] sm_seg;//段选
 12 output[5:0] sm_bit;//位选
 13 
 14 reg [7:0] sm_seg;
 15 reg [5:0] sm_bit;
 16 reg [31:0] count;
 17 reg [31:0] count2;
 18 reg [3:0] i;//数码管位数
 19 reg clk1, clk2;
 20 reg [3:0]ge,shi,bai,qian,wan,swan;
 21 reg [7:0] ge_reg,shi_reg,bai_reg,qian_reg,wan_reg,swan_reg;
 22 
 23 parameter//共阳极
 24         led_GYA0 = 8hc0,     //0  
 25         led_GYA1 = 8hf9,     //1 26         led_GYA2 = 8ha4,     //2 27         led_GYA3 = 8hb0,     //3 28         led_GYA4 = 8h99,     //4 29         led_GYA5 = 8h92,     //5 30         led_GYA6 = 8h82,     //6 31         led_GYA7 = 8hf8,     //7 32         led_GYA8 = 8h80,     //8 33         led_GYA9 = 8h90;     //9 34 
 35 /****************分频1S*****************/        
 36 always@(posedge clk or negedge rst_n) begin
 37 if(!rst_n) begin //同步复位
 38            clk2  <= 1b0;
 39            count2 <= 32b0;
 40            end
 41      else if(count2 == 32d249999)begin //高低电平转换 5*10^7*20ns=10^9ns=1s
 42           clk2 <= ~clk2;
 43           count2 <= 32b0;
 44           end
 45      else begin
 46           count2 <= count2 + 1b1; //计数
 47           end
 48  end
 49         
 50 /******************计数*********************/
 51 always@(posedge clk2 or negedge rst_n) begin//个位处理
 52 if(!rst_n) begin
 53               ge <= 4b0000;
 54               shi <= 4b0000;
 55               bai <= 4b0000;
 56               qian <= 4b0000;
 57               wan <= 4b0000;
 58               swan <= 4b0000; 
 59               end
 60 else if(ge == 4b1010) begin //个位等于10
 61                        ge  = 4b0000;
 62                        shi = shi + 1b1;
 63                        if(shi == 4b1010) begin//十位等于10
 64                                           shi = 4b0000;
 65                                           bai = bai + 1b1;
 66                                           if(bai == 4b1010) begin//百位等于10
 67                                                              bai  = 4b0000;
 68                                                              qian = qian + 1b1;
 69                                                              if(qian == 4b1010) begin//千位等于10
 70                                                                                  qian = 4b0000;
 71                                                                                  wan  = wan + 1b1;
 72                                                                                  if(wan == 4b1010) begin//万位等于10
 73                                                                                                     wan  = 4b0000;
 74                                                                                                     swan = swan + 1b1;
 75                                                                                                     if(swan == 4b1010) begin//十万位等于10
 76                                                                                                                         ge <= 4b0000;
 77                                                                                                                         shi <= 4b0000;
 78                                                                                                                         bai <= 4b0000;
 79                                                                                                                         qian <= 4b0000;
 80                                                                                                                         wan <= 4b0000;
 81                                                                                                                         swan <= 4b0000; 
 82                                                                                                                         end
 83                                                                                                     end 
 84                                                                                  end
 85                                                               end 
 86                                         end
 87                       end
 88 else  begin
 89       ge <= ge + 1b1;
 90       end
 91         
 92 end
 93                           
 94 /***************编码*******************/
 95 always@(posedge clk2 or negedge rst_n) begin
 96 case(ge)
 97       4b0000: ge_reg <= led_GYA0;
 98       4b0001: ge_reg <= led_GYA1;
 99       4b0010: ge_reg <= led_GYA2;
100       4b0011: ge_reg <= led_GYA3;
101       4b0100: ge_reg <= led_GYA4;
102       4b0101: ge_reg <= led_GYA5;
103       4b0110: ge_reg <= led_GYA6;
104       4b0111: ge_reg <= led_GYA7;
105       4b1000: ge_reg <= led_GYA8; 
106       4b1001: ge_reg <= led_GYA9;
107       default: ge_reg <= led_GYA0; 
108 endcase
109       
110 case(shi)
111       4b0000: shi_reg <= led_GYA0;
112       4b0001: shi_reg <= led_GYA1;
113       4b0010: shi_reg <= led_GYA2;
114       4b0011: shi_reg <= led_GYA3;
115       4b0100: shi_reg <= led_GYA4;
116       4b0101: shi_reg <= led_GYA5;
117       4b0110: shi_reg <= led_GYA6;
118       4b0111: shi_reg <= led_GYA7;
119       4b1000: shi_reg <= led_GYA8; 
120       4b1001: shi_reg <= led_GYA9;
121       default: shi_reg <= led_GYA0; 
122 endcase
123 
124 case(bai)
125       4b0000: bai_reg <= led_GYA0;
126       4b0001: bai_reg <= led_GYA1;
127       4b0010: bai_reg <= led_GYA2;
128       4b0011: bai_reg <= led_GYA3;
129       4b0100: bai_reg <= led_GYA4;
130       4b0101: bai_reg <= led_GYA5;
131       4b0110: bai_reg <= led_GYA6;
132       4b0111: bai_reg <= led_GYA7;
133       4b1000: bai_reg <= led_GYA8; 
134       4b1001: bai_reg <= led_GYA9;
135       default: bai_reg <= led_GYA0;
136 endcase
137       
138 case(qian)
139       4b0000: qian_reg <= led_GYA0;
140       4b0001: qian_reg <= led_GYA1;
141       4b0010: qian_reg <= led_GYA2;
142       4b0011: qian_reg <= led_GYA3;
143       4b0100: qian_reg <= led_GYA4;
144       4b0101: qian_reg <= led_GYA5;
145       4b0110: qian_reg <= led_GYA6;
146       4b0111: qian_reg <= led_GYA7;
147       4b1000: qian_reg <= led_GYA8; 
148       4b1001: qian_reg <= led_GYA9;
149       default: qian_reg <= led_GYA0;
150 endcase
151       
152 case(wan)
153       4b0000: wan_reg <= led_GYA0;
154       4b0001: wan_reg <= led_GYA1;
155       4b0010: wan_reg <= led_GYA2;
156       4b0011: wan_reg <= led_GYA3;
157       4b0100: wan_reg <= led_GYA4;
158       4b0101: wan_reg <= led_GYA5;
159       4b0110: wan_reg <= led_GYA6;
160       4b0111: wan_reg <= led_GYA7;
161       4b1000: wan_reg <= led_GYA8; 
162       4b1001: wan_reg <= led_GYA9;
163       default: wan_reg <= led_GYA0;
164 endcase
165       
166 case(swan)
167       4b0000: swan_reg <= led_GYA0;
168       4b0001: swan_reg <= led_GYA1;
169       4b0010: swan_reg <= led_GYA2;
170       4b0011: swan_reg <= led_GYA3;
171       4b0100: swan_reg <= led_GYA4;
172       4b0101: swan_reg <= led_GYA5;
173       4b0110: swan_reg <= led_GYA6;
174       4b0111: swan_reg <= led_GYA7;
175       4b1000: swan_reg <= led_GYA8; 
176       4b1001: swan_reg <= led_GYA9;
177       default: swan_reg <= led_GYA0;
178 endcase
179 end
180         
181 /****************分频1MS*****************/        
182 always@(posedge clk or negedge rst_n) begin
183 if(!rst_n) begin //同步复位
184            clk1  <= 1b0;
185            count <= 1b0;
186            end
187 else if(count == 32d24999)begin //高低电平转换 25000*20=500000ns=0.5ms
188                            clk1 <= ~clk1;
189                            count <= 1b0;
190                            end
191 else begin
192      count <= count + 1b1; //计数
193      end
194 end
195 
196 /************数码管位数循环****************/    
197 always@(posedge clk1 or negedge rst_n) begin
198 
199 if(!rst_n) begin //同步复位
200            i <= 4b0000;
201            end
202 else if(i == 4b0101) begin 
203                       i <= 4b0000;
204                       end
205 else begin
206      i <= i + 1b1;
207      end
208 end
209 
210 /************数码管显示****************/
211 always@(posedge clk1 or negedge rst_n) begin  
212         case(i)
213             4b0000: begin sm_seg <= ge_reg;    sm_bit <= 6b11_1110;  end
214             4b0001: begin sm_seg <= shi_reg;   sm_bit <= 6b11_1101;  end
215             4b0010: begin sm_seg <= bai_reg;   sm_bit <= 6b11_1011;  end
216             4b0011: begin sm_seg <= qian_reg;  sm_bit <= 6b11_0111;  end
217             4b0100: begin sm_seg <= wan_reg;   sm_bit <= 6b10_1111;  end
218             4b0101: begin sm_seg <= swan_reg;  sm_bit <= 6b01_1111;  end
219             default: begin sm_seg <= led_GYA0;  sm_bit <= 6b11_1111;  end 
220         endcase
221    end         
222      
223 endmodule

 

FPGA六位共阳极数码管动态显示

标签:style   blog   color   os   ar   sp   div   log   ad   

原文地址:http://www.cnblogs.com/chasing/p/4044889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!