基于xilinx ego1开发板的基础运算计算器

最近学校数电课程要弄大作业,作者作为一个FPGA的纯新手,只得选择这个看起来最好欺负的选题。但是仍然有很多地方有缺陷,不过好消息是看着像大学生写的,通俗易懂,全篇无需注释你就能看懂,话不多说,上代码。





module calcultor(
    input clk,
    input wire reset,            
    input wire btn_add,           
    input wire btn_sub,           
    input wire btn_mul,           
    input wire btn_div,           
    input wire btn_eq,            
    input[15:0] sw,
      
    output[7:0] seg,
    output[7:0] seg1,
    output[7:0] an 
    
);
    reg[18:0] divclk_cnt = 0;
    reg [7:0] op1;         
    reg [7:0] op2;         
    reg divclk = 0;
    reg [20:0] result;
    
    reg [7:0]op;
    reg[7:0] seg=0;
    reg[7:0] seg1=0;
    reg[7:0] an=8'b00000001;
    reg[20:0] disp_dat=0;
    reg[20:0] data=0;
    reg[2:0] disp_bit=0;
    parameter maxcnt = 50000;
    
    always@(posedge clk)
    begin
        if(divclk_cnt==maxcnt)
        begin
            divclk=~divclk;
            divclk_cnt=0;
        end
        else
        begin
            divclk_cnt=divclk_cnt+1'b1;
        end
    end
    always@(posedge reset)
    begin
        op1=8'b0;
        op2=8'b0;
        disp_dat=21'b0;
        
    end
        
    always@(posedge divclk) begin
        op1=sw[7:0];
        
       
              
        op2=sw[15:8];
        
        if(btn_add)
        result=op1+op2;
        if(btn_sub)
        result=op1-op2;
        if(btn_mul)
        result=op1*op2;
        if(btn_div)
        result=op1/op2;
        
        
        if(disp_bit >= 7)
            disp_bit=0;
         else
            disp_bit=disp_bit+1'b1;
         case (disp_bit)
            3'b000 :
            begin
                disp_dat=result;
                if(disp_dat>9999)
                    data=(((disp_dat%10000)%1000)%100)%10;
                if(disp_dat>999 && disp_dat<10000)
                    data=((disp_dat%1000)%100)%10;
                if(disp_dat>99 && disp_dat<1000)
                    data=(disp_dat%100)%10;
                if(disp_dat>9 && disp_dat<100)
                    data=d
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

is_he

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值