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

📄 calculator.lst

📁 基于51单片机的1602显示的计算器
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   CALCULATOR                                                            09/29/2007 20:36:00 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE CALCULATOR
OBJECT MODULE PLACED IN calculator.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE calculator.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /********************************************************************************/
   2          /*     Project: 计算器(Calculator)                 版本号:V1。0                */
   3          /*                                                                                                                                                      */
   4          /*                                                                                                                                                              */
   5          /*     Designed By: whoami                         CPU:AT89S51 or C51           */
   6          /*                                                                                                                                                              */
   7          /*                                                                                                                                                              */
   8          /*     键盘布局如下:                                                                                                                   */
   9          /*     K2(0)  K4(1)  K6(2)  K8(3)  K10(8)  K12(9)  K14(.)  K16(+)               */ 
  10          /*     K3(4)  K5(5)  K7(6)  K9(7)  K11(-)  K13(*)  K15(/)  K17(=)               */
  11          /*                                                                                                                                                              */
  12          /*         功能描述:                                                                                                                           */
  13          /*             可以运算+,-,*,/等计算,运算的长度可以自行设定                                 */
  14          /*                 修改 Max_disp_buff 即可。                                                                                    */
  15          /*                                                                                                                                                              */
  16          /*     http://www.mculover.net                                                                                                  */
  17          /*     http://www.mculover.net/bbs                    湘灵电子版权所有          */
  18          /*                                                                                                                                                              */
  19          /*     转载请保留以上信息,谢谢合作     !                                                                                      */
  20          /*                                                                                                                                                          */
  21          /********************************************************************************/
  22          
  23          #include <reg51.h>
  24          #include <math.h>
  25          #include <stdlib.h>
  26          
  27          #define key_yes         0x18 //MENU_yes
  28          #define key_left    0x14 //<-
  29          #define key_right   0x12 //->
  30          #define key_no          0x11 //NO_back
  31          
  32          #define key_1           0x28 //1
  33          #define key_2           0x24 //2
  34          #define key_3           0x22 //3
  35          #define key_add     0x21 //+
  36          
  37          #define key_4           0x48 //4
  38          #define key_5       0x44 //5
  39          #define key_6           0x42 //6
  40          #define key_sub         0x41 //-
  41          
  42          #define key_7           0x88 //7
  43          #define key_8           0x84 //8
  44          #define key_9           0x82 //9
  45          #define key_0           0x81 //0
  46          
  47          #define mul                     key_left
  48          #define div                     key_right
  49          
  50          #define uchar unsigned char
  51          #define countend        40
  52          #define countsub        5
  53          #define L 10
  54          bit keyflag = 0;
  55          
C51 COMPILER V7.50   CALCULATOR                                                            09/29/2007 20:36:00 PAGE 2   

  56          #define  Key_con        P3      //定义44键盘的连接口线
  57          
  58          #define  Lcd_Data       P0          //定义数据端口
  59          #define  TH0_TL0        (65536-5000)//设定中断的间隔时长
  60          
  61          #define  Max_disp_buff  10      //定义最大的显示位数
  62          
  63          sbit  RS = P2 ^ 0;       //定义和LCM的连接端口
  64          sbit  RW = P2 ^ 1;
  65          sbit  E = P2 ^ 2;
  66          sbit  Busy = P0 ^ 7;
  67          
  68          unsigned char Key_value, Time_delay;
  69          static float left_value = 0;
  70          static float right_value = 0;
  71          
  72          //开机画面预定义
  73          unsigned char code welcome[] = {"Welcome to :    "};
  74          unsigned char code website[] = {"wumingshens Zone"};
  75          unsigned char code designed[]= {"Designed By:    "};
  76          unsigned char code whoami[]  = {"      wumingshen"};
  77          
  78          //定义数组变量
  79          unsigned char code keycodes[16]={'0','1','2','3','4','5','6','7','8','9','.','+','-','*','/','=',};
  80          unsigned char number[Max_disp_buff + 1];//定义按键数字的缓冲大小
  81          
  82          extern unsigned char keyscan(void);
  83          
  84          //函数声明 
  85          void Delay(unsigned char x);//延时处理
  86          void Delay_1ms(unsigned char t);//延时子程序,延时 1MS*t S
  87          unsigned char Read_key(void);//按键处理,返回按键的值
  88          unsigned char Test_key(void);//按键检测函数
  89          void Read_Busy(void);//读忙信号判断
  90          void Write_Comm(unsigned char lcdcomm); //写指令函数
  91          void Write_Data(unsigned char lcddata);//写数据函数
  92          void Init_LCD_Cal(void);//初始化LCD
  93          void Init_LCD_Logo(void);//初始化LCD
  94          void Init_Timer0(void);//定时器0初始化
  95          void Display (char *buf); //显示函数
  96          void Display_Logo(unsigned char code *DData);//显示LOGO
  97          void Digit_input_calcul(void);//字符输入
  98          void Fun_calculator(unsigned int fuhao);//运算函数
  99          void Calculator_output(float value);//输出计算结果函数
 100          void Show_logo(void);//显示开机画面
 101          
 102          /******************************************************************************/
 103          void Delay(unsigned char x)//延时处理
 104          {
 105   1              Time_delay = x;
 106   1      
 107   1              while(Time_delay != 0);
 108   1      }
 109          
 110          /******************************************************************************/
 111          void Delay_1ms(unsigned char t)//延时子程序,延时 1MS*t S
 112          {
 113   1              unsigned char a;
 114   1              while(--t != 0)
 115   1              {
 116   2                      for(a = 0; a < 125; a++);
 117   2              }
C51 COMPILER V7.50   CALCULATOR                                                            09/29/2007 20:36:00 PAGE 3   

 118   1      }
 119          
 120          /**************此函数具有长按加速功能******************/
 121          
 122          unsigned char keyscan(void)
 123          {
 124   1              unsigned char i,code_l,code_h[4] = {0xfe,0xfd,0xfb,0xf7};
 125   1              static unsigned char keycounter = 0;
 126   1              Key_con = 0xF0;
 127   1              if((Key_con & 0xF0)!= 0xF0)
 128   1              {
 129   2              Delay_1ms(20);
 130   2                      if((Key_con & 0xf0)!= 0xF0)
 131   2                      { 
 132   3                              for(i = 0; i<4; i++)
 133   3                              {
 134   4                                  Key_con = code_h[i];
 135   4                              if((Key_con & 0xF0) != 0XF0)
 136   4                              {
 137   5                                      code_l = (Key_con & 0xF0) | 0x0F;
 138   5                                              if(keyflag)//不是第一次按下则执行以下程序
 139   5                                              {
 140   6                                                      keycounter++;//计数器加1
 141   6                                                      if(keycounter == countend)
 142   6                                                      {
 143   7                                                              keycounter -= countsub;//到一百了再减去
 144   7                                                              return ((~code_h[i])+(~code_l));
 145   7                                                      }
 146   6                                                      else    
 147   6                                                      {return 0;}  //没有到100则返回0
 148   6                                              }
 149   5                                              else  //第一次按下则执行以下程序
 150   5                                      {
 151   6                                                      keyflag = 1;  //置标志位
 152   6                                                      return ((~code_h[i])+(~code_l));
 153   6                                              }
 154   5                              }        
 155   4                              }
 156   3                      }
 157   2              }
 158   1              else
 159   1              {
 160   2                      keyflag = 0;keycounter = 0;return (0);
 161   2              }
 162   1      }
 163          
 164          /******************************************************************************/
 165          unsigned char Read_key(void)//按键处理,返回按键的值
 166          {
 167   1              unsigned char  key;
 168   1              key = keyscan();
 169   1              switch(key)
 170   1              {
 171   2                      case key_yes:   Key_value = keycodes[15];       break;  //=
 172   2                      case mul        :       Key_value = keycodes[13];       break;  //*
 173   2                      case div    :   Key_value = keycodes[14];       break;  ///
 174   2                      case key_no :   Key_value = keycodes[10];       break;  //.
 175   2      
 176   2                      case key_1  :   Key_value = keycodes[1];        break;  //1
 177   2                      case key_2  :   Key_value = keycodes[2];        break;  //2
 178   2                      case key_3  :   Key_value = keycodes[3];        break;  //3
 179   2                      case key_add:   Key_value = keycodes[11];       break;  //+
C51 COMPILER V7.50   CALCULATOR                                                            09/29/2007 20:36:00 PAGE 4   

 180   2      
 181   2                      case key_4  :   Key_value = keycodes[4];        break;  //4
 182   2                      case key_5  :   Key_value = keycodes[5];        break;  //5
 183   2                      case key_6  :   Key_value = keycodes[6];        break;  //6
 184   2                      case key_sub:   Key_value = keycodes[12];       break;  //-
 185   2      
 186   2                      case key_7  :   Key_value = keycodes[7];        break;  //7
 187   2                      case key_8  :   Key_value = keycodes[8];        break;  //8
 188   2                      case key_9  :   Key_value = keycodes[9];        break;  //9
 189   2                      case key_0  :   Key_value = keycodes[0];        break;  //0
 190   2                      default:                Key_value = 0x00;                       break;
 191   2              }
 192   1              //while(key != 0x00){;}
 193   1              return Key_value;
 194   1      }
 195          
 196          /******************************************************************************/
 197          void Timer0_int(void) interrupt 1 using 1//定时0中断处理
 198          {
 199   1              //      调整出入栈的时间,在精度不高的场合可不要!
 200   1              TR0 = 0;
 201   1          TL0 += (TH0_TL0 + 9) % 256;
 202   1          TH0 += (TH0_TL0 + 9) / 256 + (char)CY;
 203   1          TR0 = 1;
 204   1      
 205   1              if(Time_delay != 0)//延时函数用
 206   1              {
 207   2                      Time_delay--; 
 208   2              }
 209   1      
 210   1              Read_key();//读取键盘的值
 211   1      }
 212          
 213          /******************************************************************************/
 214          unsigned char Test_key(void)//按键检测函数
 215          {
 216   1              unsigned char mykey;
 217   1      
 218   1              while((mykey = Key_value) == 0x00);//等待 
 219   1      
 220   1              return mykey;
 221   1      }
 222          
 223          /******************************************************************************/
 224          void Read_Busy(void)//读忙信号判断
 225          {
 226   1              do{
 227   2                      Lcd_Data = 0xff;
 228   2                      RS = 0;
 229   2                      RW = 1;
 230   2                      E = 0;
 231   2                      Delay(2);//调用中断延时
 232   2                      E = 1;
 233   2                }while(Busy);
 234   1      }
 235          
 236          /******************************************************************************/ 
 237          void Write_Comm(unsigned char lcdcomm) //写指令函数
 238          {       
 239   1              Lcd_Data = lcdcomm;
 240   1              RS = 0;

⌨️ 快捷键说明

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