野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13228|回复: 2

[altera] FPGA出租车计价器设计

[复制链接]
发表于 2021-6-25 15:24:43 | 显示全部楼层 |阅读模式
/*
    *出租车计价器
    *功能:1、初始化计价 10元
           2、数码管按键切换显示价格和里程
           3、速度300m/s
           4、可以通过拨码开关进行清零和保持当前价格和里程
           5、当里程十位无数据时,不显示
           6、数码管最高位分别显示当前显示的内容字母,d显示距离,C显示价格
    *匀速状态
    *By:鱼芯工作室
    *更多请关注微信公众号:智能车杂谈
*/

module taxi_prj(clkin,rstn,led,dataout,dot,en,Key);

input clkin,rstn;
input [2:0] Key;
output led;
output[7:1] dataout;
output dot;
output[3:0] en;//COM使能输出

reg led;
reg [10:0] cnt;

reg[7:1] dataout;//各段数据输出
reg dot;//各段数据输出.
reg[3:0] en;
reg[1:0] cnt_scan;//扫描频率计数器
reg[3:0] dataout_buf;
reg [4:0] data_ten,data_ge,data_dot,init_cost;
reg [16:0] distance;
reg [16:0] cost;

gen_div U1(.clkin(clkin),.rstn(rstn),.clkout(clkout));//1ms

always@(posedge clkout or negedge rstn)
begin
    if(!rstn)  
    begin
        cnt <= 0;
        distance <= 0;
        data_ten<=0;
        data_ge<=0;
        data_dot<=0;
        init_cost <= 10;
        cost<=0;
    end
    else if(cnt == 2000)
    begin
        cnt <= 0;
        led <= ~led;
        if(Key[2]==1 || Key[1] == 1)
        begin
            if(Key[1] == 1)
            begin
                distance <= 0;
                data_ten<=0;
                data_ge<=0;
                data_dot<=0;
                init_cost <= 10;
                cost<=0;
            end
            else
            begin
                distance <= distance ;
                data_ten<=data_ten;
                data_ge<=data_ge;
                data_dot<=data_dot;
                cost<=cost;
            end            
        end
        else
        begin
                distance <= distance+300;
                data_ten<=distance/10000%10;
                data_ge<=distance/1000%10;
                data_dot<=distance/100%10;
                if(distance<=3000 && distance >0)
                begin
                    init_cost <= 10;
                    cost = init_cost *10;
                end
                else
                    cost <=init_cost *10+2*(distance-3000)/100;
        end
    end
    else cnt <= cnt + 1;
end
//segment
always@(posedge clkout or negedge  rstn)
begin
    if(!rstn)
        begin //低电平复位
            cnt_scan<=0;
        end
    else
        begin
            cnt_scan<=cnt_scan+1;
        end
end

always @(cnt_scan)//段码扫描频率
begin
  case(cnt_scan[1:0])
      2'b00 :
          en = 4'b1110;
      2'b01 :
          en = 4'b1101;
      2'b10 :
          en = 4'b1011;
      2'b11 :
          en = 4'b0111;
      default :
          en = 4'b1110;
    endcase
end

  always @ (Key[0],en) //对应COM信号给出各段数据,段码
    case(Key[0])
        1'b0:
            begin
                case(en)
                  4'b1110:
                  begin
                        dataout_buf<= 13;//输入将要显示的数字
                        dot <= 1;
                        end
                  4'b1101:
                  begin
                  if(data_ten!==0)
                  begin
                        dataout_buf<=data_ten;
                        dot <= 1;
                    end
                    else
                    begin
                            dataout_buf<=7'b1111_111;
                            dot <= 1;
                        end
                    end
                  4'b1011:
                  begin
                        dataout_buf <=  data_ge;
                        dot <= 0;
                        end
                  4'b0111:
                  begin
                        dataout_buf<=data_dot;  
                        dot <= 1;
                        end
                  default:
                        dataout_buf=1;
              endcase
          end
        1'b1:
                    begin
                            case(en)
                              4'b1110:
                              begin
                                    dataout_buf<= 12;//输入将要显示的数字
                                    dot <= 1;
                                    end
                              4'b1101:
                              begin
                                    dataout_buf<=cost/100;
                                    dot <= 1;
                                    end
                              4'b1011:
                              begin
                                    dataout_buf <= cost/10%10;
                                    dot <= 0;
                                    end
                              4'b0111:
                              begin
                                    dataout_buf<=cost%10;   
                                    dot <= 1;
                                    end
                              default:
                                    dataout_buf=1;
                          endcase
                      end
            default:dataout_buf=0;
    endcase  


always@(dataout_buf)
begin
    case(dataout_buf)  //将要显示的数字译成段码
        4'b0000://0
            dataout=7'b0000_001;
        4'b0001://1
            dataout=7'b1001_111;
        4'b0010://2
            dataout=7'b0010_010;
        4'b0011://3
            dataout=7'b0000_110;
        4'b0100://4
            dataout=7'b1001_100;
        4'b0101://5
            dataout=7'b0100_100;
        4'b0110://6
            dataout=7'b0100_000;
        4'b0111://7
            dataout=7'b0001_111;
        4'b1000://8
            dataout=7'b0000_000;
        4'b1001://9
            dataout=7'b0000_100;
            4'b1010://A
            dataout=7'b0001_000;
            4'b1011://B
                dataout=7'b1100_000;
            4'b1100://C
            dataout=7'b0110_001;
            4'b1101://D
            dataout=7'b1000_010;
            4'b1110://E
            dataout=7'b0010_000;
       default://这里仅编译了0-9这几个数字
            dataout=7'b1111_111;//全灭
     endcase
end

endmodule


回复

使用道具 举报

发表于 2021-9-30 09:01:09 | 显示全部楼层
   厉害   
回复 支持 反对

使用道具 举报

发表于 2022-3-18 20:49:27 | 显示全部楼层
收下了,大佬的就是我的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-3-29 18:03 , Processed in 0.025527 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表