⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 这是自己用一个单片机做的计算器
💻 C
字号:
//******************************头文件***************************************
  #include <reg52.h>
  #include <stdio.h>
  #include <string.h>
  #include <intrins.h>
  #include <absacc.h>
  #include <main.h>
//*********************************初始变量**********************************
 xdata  uchar opention_i[8];     //键盘输入整数存储区
 xdata  uchar opention_f[8];     //键盘输入小数存储区
 xdata  uchar mkey; 
 float float_a1=0;
 float float_a2=0;
 xdata  uchar float_count=0,int_count=0;

main()
{	uchar add,dec,all,del;
    uchar opention_do=0;
	uchar float_c;
	uchar recive1=1;
	uchar tmr,i;
	uchar opention_ti[8];                  //为实现输出暂设此缓存

   for(tmr=0;tmr<0xffff;tmr++);	           // 等待 BC728x 完成复位
	   wr_7281(0x12);                    //设置7281工作方式
       wr_7281(0x80);

   while (1)
        {  
            if(!key)	                        //有键值
	          { wr_7281(0x93);
	            mkey= receive();		        //键值
              } 
			if(mkey==14)           //小数点输入
              { float_c=1;
			    mkey=16;
			   }
		    if(mkey==15)           //求结果
              {
			    opention_do=1;
			    mkey=16;
			   }
			//***********************************接接收键值**************************
            if(recive1==1 && float_c==0 && mkey<10)    //输入整数部分
              {
                opention_i[int_count]=mkey;
                int_count++;
				for(i=0;i<int_count;i++)   //交换输入顺序
                   {
                      opention_ti[int_count-i]=opention_i[i];
                    }	 
				setdisplay(opention_ti,int_count );
				mkey=16;
               }
            if(recive1==1 && float_c==1 && mkey!=14 && mkey<10 ) //输入整数部分
               {
                 opention_f[float_count]=mkey;
                 float_count++;
				 opention_i[int_count]=mkey;
                 int_count++;
				 for(i=0;i<int_count;i++)   //交换输入顺序
                    {
                      opention_ti[int_count-i]=opention_i[i];
                     }
				  wr_7281(0x18);                       //设置成显示小数
                  wr_7281(p_float[float_count-1]);     //显示小数点	 
				  setdisplay(opention_ti,int_count);
				  mkey=16;
                }
			//*************************************键盘输入何种算法**************************
            if(mkey==10)  //加法
              { mkey=16;
                float_a1=add_all(opention_i,opention_f,int_count);
                out_data[0]=0;
                setdisplay(out_data,1 );
                add=1;
                float_c=0;
               }
            if(mkey==11)  //减法
               { mkey=16;
                 float_a1=add_all(opention_i,opention_f,int_count);
                 out_data[0]=0;
                 setdisplay(out_data,1 );
                 dec=1;
                 float_c=0;
                }
             if(mkey==12)  //乘法
               { mkey=16;
                float_a1=add_all(opention_i,opention_f,int_count);
                out_data[0]=0;
                setdisplay(out_data,1 );
                all=1;
                float_c=0;
                }
              if(mkey==13)  //除法
                 { mkey=16;
                   float_a1=add_all(opention_i,opention_f,int_count);
                   out_data[0]=0;
                   setdisplay(out_data,1 );
                   del=1;
                   float_c=0;
                 }
			  //****************************************进入运算******************************
              if(opention_do==1 && add==1)
                 { opention_do=0;
				   float_c=0;
				   add=0;
                   float_a1=add_all(opention_i,opention_f,int_count);
                   f_data=float_a1+float_a2;
                   LED_OUT() ;
                  }
               if(opention_do==1 && dec==1)
                  { opention_do=0;
					float_c=0;
				    dec=0;
                    float_a1=add_all(opention_i,opention_f,int_count);
                    f_data=float_a1-float_a2;
                    LED_OUT() ;
                   }
               if(opention_do==1 && all==1)
                  { opention_do=0;
					float_c=0;
				    all=0;
                    float_a1=add_all(opention_i,opention_f,int_count);
                    f_data=float_a1*float_a2;
                    LED_OUT() ;
                   }
                if(opention_do==1 && del==1)
                   {  opention_do=0;
				      float_c=0;
				      del=0;
                      float_a1=add_all(opention_i,opention_f,int_count);
                      f_data=float_a1/float_a2;
                      LED_OUT() ;
                    }

            }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -