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

📄 test.lst

📁 用51单片机开发的简单计算器程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.06   TEST                                                                  04/25/2008 15:35:58 PAGE 1   


C51 COMPILER V8.06, COMPILATION OF MODULE TEST
OBJECT MODULE PLACED IN test.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE test.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "calc.h"
   2          bit shift_flag;
   3          sbit sck = P2^0;
   4          sbit load = P2^1;
   5          sbit d_out = P2^2;
   6          sbit sign_led = P2^3;
   7          sbit shift_led = P2^4;
   8          float calc_res = 0;
   9          const byte kb_table[16] = {     
  10              1, 2, 3, '+',
  11              4, 5, 6, '-',
  12              7, 8, 9, '*',
  13              's', 0, '.', '='
  14          };
  15          const byte s_kb_table[16] = {
  16              1, 2, 3, 's',
  17              4, 5, 6, '-',
  18              7, 8, 9, 'C',
  19              '/', 0, '.', '='
  20          };
  21          byte current_digs[4] = {0x7f,0x7f,0x7f,0x7f};
  22          
  23          float sqrt(float val){
  24   1          float root = val/2;
  25   1          float check, n, m;
  26   1          check=root*root;
  27   1          n = 0; m = val;
  28   1          while (check-val<-0.0001 || check-val>0.0001){
  29   2              if (check > val){
  30   3                  m = root;
  31   3                  root = (root + n) / 2;
  32   3              } else {
  33   3                  n = root;
  34   3                  root = (root + m) / 2;
  35   3              }
  36   2              check = root * root;
  37   2          }
  38   1          return root;
  39   1      }
  40          
  41          /**
  42           * kb_scan will scan the keyboad (4*4) at the port: kb_port, and return
  43           * the key value, according to key value tables.
  44           */
  45          byte kb_scan(){
  46   1              #define kb_port P3
  47   1          #define READ_MSK 0x0f
  48   1          byte col_val = 0x0f;
  49   1          byte scan_msk = 0x10;
  50   1          byte test_msk = 0x01;
  51   1          byte i = 0;
  52   1          byte j = 0;
  53   1          byte result = 0;
  54   1          while(col_val == 0x0f){
  55   2              kb_port = READ_MSK; // read on lower 4 bits.
C51 COMPILER V8.06   TEST                                                                  04/25/2008 15:35:58 PAGE 2   

  56   2              col_val = kb_port;
  57   2              col_val &= READ_MSK;
  58   2          }
  59   1          for (i=0; i<4; i++){        // scanning row i.
  60   2              kb_port = (~scan_msk);    // activate one row only.
  61   2              col_val = kb_port;
  62   2              col_val &= READ_MSK;
  63   2                      test_msk = 0x01;
  64   2              for (j=0; j<4; j++){    // scanning col j.
  65   3                  if ((col_val & test_msk) == 0){
  66   4                      // have input on this col.
  67   4                      result = ((shift_flag==1) ? s_kb_table[j*4+i]:kb_table[j*4+i]);
  68   4                      goto start_wait;
  69   4                  }
  70   3                  test_msk <<=1;
  71   3              }
  72   2              scan_msk <<= 1;
  73   2          }
  74   1      start_wait:
  75   1          while(col_val != 0x0f){
  76   2              kb_port = READ_MSK; // read on lower 4 bits.
  77   2              col_val = kb_port;
  78   2              col_val &= READ_MSK;
  79   2          }
  80   1              return result;
  81   1      }
  82          /**
  83           * send_word will send two byte of data using SCK, LOAD and D_OUT 3
  84           * ports to MAX7219 numeric LED driver. The first byte shall be address
  85           * while the second byte will the data.
  86           */
  87          void send_word(byte addr, byte val){
  88   1          byte i;
  89   1          byte comm_msk = 0x80;
  90   1          load = 0;       // pull down load/cs to begin communication.
  91   1          sck = 0;        // pull down CLOCK to prepare for communication.
  92   1          for (i=0; i<8; i++){
  93   2              sck = 0;    // pull down to prepare data.
  94   2              _nop_();     // delay will be needed on Dallas MCUs.
  95   2              d_out = (((addr&comm_msk)==0)?0:1);
  96   2              sck = 1;    // pull up to send one bit.
  97   2              comm_msk >>= 1;
  98   2          }
  99   1          comm_msk = 0x80;
 100   1          for (i=0; i<8; i++){
 101   2              sck = 0;    // pull down to prepare data.
 102   2              _nop_();     // delay will be needed on Dallas MCUs.
 103   2              d_out = (((val&comm_msk)==0)?0:1);
 104   2              sck = 1;    // pull up to send one bit.
 105   2              comm_msk >>= 1;
 106   2          }
 107   1          load = 1;
 108   1      }
 109          /**
 110           * led_init will configure the MAX7219 to a proper state:
 111           *     dig.1~dig.4 decode B mode
 112           *     scanning from dig.1 to dig.4
 113           *     intensity set to 1/2.
 114           *     blank display for dig.1 to dig.3
 115           *     0 display for dig.4 (most right)
 116           */
 117          void led_init(){
C51 COMPILER V8.06   TEST                                                                  04/25/2008 15:35:58 PAGE 3   

 118   1          send_word(0x0c, 0x00);  // stop display.
 119   1          //send_word(0x09, 0xff);  // write to decode mode, setting to mode B
 120   1          send_word(0x0b, 0x03);  // scan dig.1 to dig.4
 121   1          send_word(0x0a, 0x0a);  // set intensity to 21/32
 122   1          /*
 123   1          // set dig.1 to dig.3 to BLANK.
 124   1          send_word(0x01, 0x7f);
 125   1          send_word(0x02, 0x7f);
 126   1          send_word(0x03, 0x7f);
 127   1          // set dig.4 to 0
 128   1          send_word(0x04, 0x80);
 129   1          */
 130   1          send_word(0x0c, 0x01);  // start display.
 131   1      }
 132          /**
 133           * showing copyright string on the numeric LEDs: JUdE
 134           */
 135          void show_copyright(){
 136   1          send_word(0x09, 0x00);  // disable decoding.
 137   1          send_word(0x01, 0x38);  // lighting B.C.D for J
 138   1          send_word(0x02, 0x3e);  // lighting B.C.D.E.F for U
 139   1          send_word(0x03, 0x30);  // lighting B.C.D.E.G for d
 140   1          send_word(0x04, 0xcf);  // lighting A.D.E.F.G and DP for E.
 141   1          send_word(0x09, 0xff);  // enable decoding.
 142   1      }
 143          /**
 144           * showing a float value on the numeric LEDs
 145           * CAUTION: used only for FOUR digs.
 146           * redesign is required for LCD display.
 147           */
 148              #define CLEAN {send_word(0x01,0x7f);\
 149                  send_word(0x01,0x7f);\
 150                  send_word(0x01,0x7f);\
 151                  send_word(0x01,0x7f);}
 152              #define SHOW_ERROR send_word(0x01, 0x0b)   // show E on left.
 153          void show_float(float val){
 154   1          char dp_shift = 0;
 155   1          long int val_int = 0;
 156   1          int tmp = 0;
 157   1          char i;
 158   1          byte digs[4];
 159   1          bit minus_sign = 0;
 160   1          bit pre_zero_flag = 0;
 161   1          if (val >= 10000){      // overflow the whole 4 digs.
 162   2              CLEAN;
 163   2              SHOW_ERROR;
 164   2          }
 165   1          while (val < 100){      // smaller than unified region.
 166   2              val *=10;
 167   2              dp_shift ++;
 168   2          }
 169   1          while (val >= 1000){    // larger than unified region.
 170   2              val /=10;
 171   2              dp_shift --;
 172   2          }
 173   1          // round the last digit.
 174   1          val_int = (long int)(val*100);
 175   1          tmp = val_int - (val_int/10)*10;
 176   1          val_int = (val_int/10)*10;
 177   1          if (tmp>=5)
 178   1              val_int += 10;
 179   1          val = val_int /100.0;
C51 COMPILER V8.06   TEST                                                                  04/25/2008 15:35:58 PAGE 4   

 180   1          // get every digits.
 181   1          minus_sign = (val<0)?1:0;
 182   1          for (i=3; i>=0; i--){
 183   2              digs[i] = (byte)((val-(int)val)*10);
 184   2              val /= 10;
 185   2          }
 186   1          // set the decimal point
 187   1          digs[2-dp_shift] |= 0x80;
 188   1          // show every dig here.
 189   1          for (i=0; i<4; i++){

⌨️ 快捷键说明

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