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

📄 chengxu.lst

📁 采用51单片机集合1602LCD控制器,可以有效的模拟出汽车的运行状态,包括速度,里程的相关信息!是绝对正确的源码,请大家放心使用和参考
💻 LST
字号:
C51 COMPILER V8.02   CHENGXU                                                               04/23/2008 13:39:24 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE CHENGXU
OBJECT MODULE PLACED IN chengxu.OBJ
COMPILER INVOKED BY: C:\Program Files\keil\C51\BIN\C51.EXE chengxu.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include<reg52.h>
   2          #include<head.h>
   3          
   4          /************************************************************/
   5          void main()
   6          {
   7   1        init(); //系统初始化
   8   1        settime();//设置时间
   9   1        TR0=1;//开定时器中断
  10   1        for(;;)
  11   1        {
  12   2         time_update();//时间更新
  13   2         x=key_board();//扫描键盘
  14   2         function_key(x);//判断键值
  15   2         lucheng_update();//里程更新
  16   2         full_day_info();//显示总共里程以及停车次数
  17   2         space_update();//速度更新
  18   2        }
  19   1      }
  20          /************************************************************/
  21           void   chushihua(void) //1602初始化
  22          { date = 0;
  23   1        xiem(0x38,0);
  24   1        delay(20); 
  25   1       xiem(0x38,0);
  26   1        delay(20); 
  27   1       xiem(0x38,0);
  28   1        delay(20)     ;
  29   1        xiem(0x38,1);  
  30   1       xiem(0x08,1);  
  31   1        xiem(0x01,1); 
  32   1        xiem(0x06,1);  
  33   1        xiem(0x0C,1);  
  34   1      }
  35            /************************************************************/
  36           void init(void) //系统初始化
  37          { 
  38   1        chushihua();
  39   1        dingshichushihua();
  40   1        xiestring(10,0,time_chushihua);
  41   1         xiechar(0,0,codee[12]);
  42   1         xiechar(1,0,codee[10]);
  43   1         xiechar(4,0,codee[0]);
  44   1         xiechar(5,0,codee[10]);
  45   1         xiechar(6,0,codee[0]);  //显示速度
  46   1        /***********************************/
  47   1         xiechar(0,1,codee[14]);
  48   1         xiechar(1,1,codee[12]);
  49   1         xiechar(2,1,codee[13]);
  50   1         xiechar(6,1,codee[(uint)((xiao_lucheng-(uint)xiao_lucheng)*10)]);
  51   1         xiechar(5,1,codee[10]);
  52   1         xiechar(4,1,codee[(uint)(xiao_lucheng)%10]);
  53   1         if((uint)(xiao_lucheng)/10!=0)
  54   1         xiechar(3,1,codee[(uint)(xiao_lucheng)/10]);//显示当前低于1公里的路程
  55   1      }
C51 COMPILER V8.02   CHENGXU                                                               04/23/2008 13:39:24 PAGE 2   

  56             /************************************************************/
  57             void settime(void)
  58            { 
  59   1          uchar i=0,j=0;
  60   1          uchar time[4]={10,11,13,14};
  61   1         for(;;)
  62   1            {RXD=0;for(;;)
  63   2              { x=key_board();
  64   3                     if((x!=3)&&(x!=7)&&(x!=11)&&(x!=12)&&(x!=14)&&(x!=15))//注意\\和&&之间的区别
  65   3                    { 
  66   4                      function_key(x);
  67   4                      if(key==10)break;
  68   4                          xiechar(time[i++],0,codee[key]);delay(100);
  69   4                              if(i==1)hour+=key*10;
  70   4                  if(i==2)hour+=key;
  71   4                              if(i==3)minute+=key*10;
  72   4                              if(i==4)minute+=key;
  73   4                  if(i==4)i=0;
  74   4                 }
  75   3                         if(x==12)
  76   3                         {
  77   4                         xiestring(10,0,time_chushihua);
  78   4                         i=0;hour=0;minute=0;
  79   4                         }
  80   3                         if(x==15)break;
  81   3                   }
  82   2                       if(x==15)break;
  83   2                 }
  84   1              } 
  85             /************************************************************/
  86             void  xies(uint pp0)
  87           {duz();rs=1;rw=0;date=pp0;e=0;e=0;e=1;}
  88          /************************************************************/
  89          void  xiechar(uint x,uint y,uchar zifu)
  90          {y&=0x01;x&=0x1f;
  91   1      
  92   1        if (y) x |= 0x40; 
  93   1        x |= 0x80; 
  94   1        xiem(x,0);xies(zifu) ;
  95   1       }
  96             /************************************************************/
  97          void xiem(uint pp0,uint busy)reentrant
  98            {
  99   1        if(busy) duz();date=pp0;
 100   1         rs=0;rw=0;
 101   1         e=0;e=0;e=1;
 102   1        }
 103              /************************************************************/
 104                   uint duz(void)
 105          {
 106   1       uint st;
 107   1       date=0;rs=0;rw=1;e=0;delay(20);e=1;
 108   1      st=((date)&(0x80));while (st);return date;
 109   1       }
 110           /************************************************************/
 111           void  xiestring(unsigned int x,unsigned int y,unsigned char *string) //向1602写字符串
 112           {       unsigned char len;
 113   1       len = 0;
 114   1        y &= 0x1;
 115   1        x &= 0xF;
 116   1      while (string[len]!='\0') 
 117   1              {
C51 COMPILER V8.02   CHENGXU                                                               04/23/2008 13:39:24 PAGE 3   

 118   2                 if (x <0xF) 
 119   2                    {
 120   3                      xiechar(x, y, string[len]);
 121   3                     len++;
 122   3                      x++;
 123   3                     }
 124   2                              else {y=1;x=0;}
 125   2               }
 126   1      }
 127          /************************************************************/
 128            void delay(uint i)  //延时程序
 129          {uint j;
 130   1       for(;i>0;i--)
 131   1       for(j=300;j>0;j--);}
 132          /************************************************************/
 133          void dingshichushihua()  //中断初始化
 134           {
 135   1       EA=1;IT0=1;
 136   1       ET0=1;
 137   1       TH0=(65535-10000)/256;
 138   1       TL0=(65535-10000)%256; //产生50ms
 139   1       TMOD=0X01;
 140   1       }
 141          /************************************************************/
 142          void    time(void)interrupt     1//定时中断子函数
 143          {u++;
 144   1      time_for++;
 145   1      if(u==1200){u=0;minute++;}//1分钟到
 146   1      TH0=(65535-50000)/256;
 147   1      TL0=(65535-50000)%256;  
 148   1      }
 149          /************************************************************/
 150          uchar key_board(void)//非常完善的键盘程序,可以满足现在键盘的所有要求!!!
 151          {  
 152   1         uchar a,b,c,d,m,i=0,keyb,tab[4]={0x7f,0xbf,0xdf,0xef};
 153   1         uint j;a=0x7f;
 154   1         if(tt==1)
 155   1         {
 156   2          P2=P2&0x0f;
 157   2          if(P2!=0x0f)goto tiaochu;
 158   2              }
 159   1              tt=0;
 160   1              for(;;)
 161   1        {
 162   2        P2=a;a=P2;b=a;c=a;
 163   2        b=b&0x0f;c=c&0x0f;
 164   2        if(b==0x0f)
 165   2         {for(j=0;j<500;j++)
 166   3           { P2=a;a=P2;d=a;d=d&0x0f;
 167   4               if( d!=0x0f)
 168   4                { if(d==0x0e)m=0;if(d==0x0d)m=4;if(d==0x0b)m=8;if(d==0x07)m=12;tt=1;
 169   5                      goto lable;
 170   5                }
 171   4                      i++;a=tab[i];if(i==4){i=0;a=0x7f; }
 172   4                }
 173   3                tiaochu:keyb=17;return(keyb);break;
 174   3              }
 175   2                   else
 176   2         {if(c==0x0e)m=0;if(c==0x0d)m=4;if(c==0x0b)m=8;if(c==0x07)m=12;tt=1;
 177   3              lable:keyb=m+3-i;return(keyb);
 178   3              break;
 179   3         }
C51 COMPILER V8.02   CHENGXU                                                               04/23/2008 13:39:24 PAGE 4   

 180   2        }
 181   1      }
 182          /************************************************************/
 183          void function_key(uchar m)
 184          {
 185   1        switch(m)
 186   1        {
 187   2         case 0:key=7;break;
 188   2         case 1:key=8;break;
 189   2         case 2:key=9;break;
 190   2         case 3:get_bus();break;//开车
 191   2         case 4:key=4;break;
 192   2         case 5:key=5;break;
 193   2         case 6:key=6;break;
 194   2         case 7:out_bus();break;//停车
 195   2         case 8:key=1;break;
 196   2         case 9:key=2;break;
 197   2         case 10:key=3;break;
 198   2         case 11:break;
 199   2         case 12:break;
 200   2         case 13:key=0;break;
 201   2         case 15:break;
 202   2         case 17:key=10;break;
 203   2         default:break;
 204   2         }
 205   1      }
 206          /************************************************************/
 207          
 208          /************************************************************/
 209           void time_update(void)//时间更新
 210          {
 211   1      if(minute==60){hour++;minute=0;}
 212   1      if(hour==24){hour=0;minute=0;}
 213   1      xiechar(14,0,codee[minute%10]);
 214   1      xiechar(13,0,codee[minute/10]);
 215   1      xiechar(11,0,codee[hour%10]);
 216   1      xiechar(10,0,codee[hour/10]);
 217   1      }
 218          /************************************************************/
 219          void get_bus(void) //开车
 220          { 
 221   1        EX0=1;//开外部中断开始计路程
 222   1        waibu_cishu=0;
 223   1      }
 224          /************************************************************/
 225          void out_bus(void)//停车
 226          {
 227   1        int m_s,n_s;
 228   1        EX0=0; //关外部中断停止计路程
 229   1        m_s=(uint)xiao_lucheng;
 230   1        n_s=(uint)((xiao_lucheng-m_s)*10);
 231   1        tingche_cishu++;//停车次数自动加一
 232   1      }
 233          /************************************************************/
 234           void   waibu1(void)interrupt   0  //外部中断子函数
 235            {
 236   1         TR0=0;
 237   1         waibu_cishu++;
 238   1         sk=1;
 239   1         xiao_lucheng+=((double)1/10);
 240   1         if(xiao_lucheng==10)
 241   1         {xiao_lucheng=0.0;full_lucheng++;}
C51 COMPILER V8.02   CHENGXU                                                               04/23/2008 13:39:24 PAGE 5   

 242   1         TR0=1;
 243   1        }
 244          /************************************************************/
 245            void lucheng_update(void)//10以下路程
 246          {
 247   1        int m_s,n_s;
 248   1        m_s=(uint)xiao_lucheng;//取整数部分
 249   1        n_s=(uint)((xiao_lucheng-m_s)*10);//取小数部分
 250   1         xiechar(6,1,codee[n_s]);
 251   1         xiechar(4,1,codee[m_s%10]);
 252   1         if(m_s/10!=0)
 253   1         xiechar(3,1,codee[m_s/10]);
 254   1      }
 255          /************************************************************/
 256          void full_day_info(void)  //整个路程和停车次数的信息
 257          {
 258   1       if(full_lucheng/1000!=0)
 259   1       xiechar(8,1,codee[full_lucheng/1000]);
 260   1       if(full_lucheng/100%10!=0)
 261   1       xiechar(9,1,codee[full_lucheng/100%10]);
 262   1       if(full_lucheng%100/10!=0)
 263   1       xiechar(10,1,codee[full_lucheng%100/10]);
 264   1      
 265   1       xiechar(11,1,codee[full_lucheng%10]);
 266   1       if(tingche_cishu/10!=0)
 267   1       xiechar(13,1,codee[tingche_cishu/10]);
 268   1      
 269   1       xiechar(14,1,codee[tingche_cishu%10]);
 270   1       }
 271          
 272          
 273           /************************************************************/
 274           void space_update(void)  //速度更新
 275           { 
 276   1         if(sk==1)
 277   1         {zheng_space=36*20/time_for;//计算速度的整数部分
 278   2         float_space=((36*20%time_for)*10)/time_for;//计算速度的小数部分
 279   2         xiechar(6,0,codee[float_space]);
 280   2         xiechar(2,0,codee[zheng_space/100]);
 281   2         xiechar(3,0,codee[zheng_space/10%10]);
 282   2         xiechar(4,0,codee[zheng_space%10]); 
 283   2          sk=0;time_for=0; }
 284   1              
 285   1      
 286   1        }
 287          
 288          
 289             
 290          
 291          
 292          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1960    ----
   CONSTANT SIZE    =      8    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     44      29
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.

C51 COMPILER V8.02   CHENGXU                                                               04/23/2008 13:39:24 PAGE 6   


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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