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

📄 my_clock.lst

📁 8051 UART clock Example allow you to send time clock through RS232 to your PC.
💻 LST
字号:
C51 COMPILER V8.17   MY_CLOCK                                                              03/16/2009 10:25:58 PAGE 1   


C51 COMPILER V8.17, COMPILATION OF MODULE MY_CLOCK
OBJECT MODULE PLACED IN my_clock.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE my_clock.c OPTIMIZE(0,SPEED) BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "..\MPC82.H"
   2          
   3          char flag4=0;
   4          char *msg;                                      
   5          unsigned char X; 
   6          unsigned char hour=23, min=55, sec=50;
   7          unsigned char ahour=0, amin=0, asec=0;
   8          
   9          void init_uart(void);
  10          void print(unsigned char abc);
  11          void uart_msg(char *msg);
  12          void print_clock(void);
  13            
  14          main()
  15          {       
  16   1        EA=1;      //enable interrupt
  17   1        EX3=1;     //INT3 as interrupt
  18   1      
  19   1        init_uart();
  20   1              //print out menu
  21   1              msg="\r\n**********************\n\0";
  22   1              uart_msg(msg);
  23   1              msg="\r\n Press 1 => Clock !\n\0";
  24   1              uart_msg(msg);
  25   1              msg="\r\n Press 2 => Alarm Setup\n\0";
  26   1              uart_msg(msg);
  27   1              msg="\r\n**********************\n\r\0";
  28   1              uart_msg(msg);
  29   1              //wait for user input
  30   1              while(1)
  31   1               {
  32   2                      while (RI==0){}
  33   2                      RI=0; 
  34   2                      X=SBUF;
  35   2                      if (X==0x31)
  36   2                      {
  37   3                              while(1)
  38   3                              {
  39   4                                      print(hour/10+0x30);
  40   4                                      print(hour%10+0x30);
  41   4                                      print(':');
  42   4                                      print(min/10+0x30);
  43   4                                      print(min%10+0x30);
  44   4                                      print(':');
  45   4                                      print(sec/10+0x30);
  46   4                                      print(sec%10+0x30);
  47   4                                      print('\n');
  48   4                                      print('\r');
  49   4                                      Delay_ms(1000);
  50   4              
  51   4                                      sec++;          
  52   4                                      if (sec<60) continue;
  53   4                                              else {sec=0; min++;}
  54   4                                      if (min<60) continue;
  55   4                                              else {min=0; hour++;}
C51 COMPILER V8.17   MY_CLOCK                                                              03/16/2009 10:25:58 PAGE 2   

  56   4                                      if (hour<24) continue;
  57   4                                              else {sec=0; min=0; hour=0;}
  58   4                              }
  59   3                      }
  60   2                      else if (X==0x32)
  61   2                      {       
  62   3                              msg="\n\rYou are enter Alarm Setup\n\r";                                                                                                                        
  63   3                              uart_msg(msg);
  64   3                              msg="\n\rPress 1 => hour, Press 2 => min, Press3 => sec\n\r";                                                                                                                   
  65   3                              uart_msg(msg);
  66   3                        while(1)
  67   3                        {
  68   4                                while(RI==0){}
  69   4                                RI=0;
  70   4                                X=SBUF;
  71   4                                while (X==0x31)
  72   4                                {     flag4=0;
  73   5                                      ahour++;
  74   5                                      do
  75   5                                      {
  76   6                                              while(KEY1==1);
  77   6                                      }
  78   5                                      while(KEY1==1);
  79   5                                      do
  80   5                                      {
  81   6                                              while(KEY1==0);
  82   6                                      }
  83   5                                      while(KEY1==0);
  84   5                                      print_clock();
  85   5                                      if (flag4==1) break;
  86   5                                }
  87   4                                while(X==0x32)
  88   4                                {     flag4=0;
  89   5                                      amin++;
  90   5                                      do
  91   5                                      {
  92   6                                              while(KEY2==1);
  93   6                                      }
  94   5                                      while(KEY2==1);
  95   5                                      do
  96   5                                      {
  97   6                                              while(KEY2==0);
  98   6                                      }
  99   5                                      while(KEY2==0);
 100   5                                      print_clock();
 101   5                                      if (flag4==1) break;
 102   5                                }
 103   4                                while(X==0x33)
 104   4                                {     flag4=0;
 105   5                                      asec++;
 106   5                                      do
 107   5                                      {
 108   6                                              while(KEY3==1);
 109   6                                      }
 110   5                                      while(KEY3==1);
 111   5                                      do
 112   5                                      {
 113   6                                              while(KEY3==0);
 114   6                                      }
 115   5                                      while(KEY3==0);
 116   5                                      print_clock();
 117   5                                      if (flag4==1) break;
C51 COMPILER V8.17   MY_CLOCK                                                              03/16/2009 10:25:58 PAGE 3   

 118   5                                }     
 119   4                        }     //end of while(1)
 120   3                      }  //end of 0x32
 121   2                      else
 122   2                      {
 123   3                              msg="\n\rend\n\r";        
 124   3                              uart_msg(msg);
 125   3                              break;
 126   3                      }       
 127   2              }//     end of while
 128   1      }       
 129          void init_uart(void)
 130          {
 131   1       SCON=0x50;
 132   1       PCON=0x00;     //SMOD=0;
 133   1       AUXR2=0x00;//T1X12=0;
 134   1       TMOD=0x20;//setup timer1
 135   1       TH1=250;//SMOD=0;T1X12=0;Baudrate=9600
 136   1       TCON=0x40;//TR1=1, make timer 1 start
 137   1      }
 138          void print(unsigned char abc)
 139          {
 140   1       SBUF=abc;
 141   1       while(TI==0);
 142   1       TI=0;
 143   1      }
 144          void uart_msg(char *msg)
 145          {
 146   1              char *p;
 147   1              SBUF=0x00;
 148   1              for(p=msg; *p!='\0'; )
 149   1              {
 150   2                      SBUF=*p++;
 151   2                      while(TI==0);
 152   2                      TI=0;
 153   2              }
 154   1      }       
 155          void EX3_int(void) interrupt 0 using 1 
 156           {
 157   1      //use key4 to interrupt
 158   1               flag4=1;
 159   1       }
 160          void print_clock()
 161          {
 162   1                              print(ahour/10+0x30);
 163   1                              print(ahour%10+0x30);
 164   1                              print(':');
 165   1                              print(amin/10+0x30);
 166   1                              print(amin%10+0x30);
 167   1                              print(':');
 168   1                              print(asec/10+0x30);
 169   1                              print(asec%10+0x30);
 170   1                              print('\n');
 171   1                              print('\r');
 172   1                              Delay_ms(1000);
 173   1      }
*** WARNING C290 IN LINE 128 OF MY_CLOCK.C: missing return value


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    735    ----
   CONSTANT SIZE    =    196    ----
C51 COMPILER V8.17   MY_CLOCK                                                              03/16/2009 10:25:58 PAGE 4   

   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     22    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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