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

📄 ints.lst

📁 压缩包中包括多个常用的汇编
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V6.12  INTS                                                                   09/11/2005 11:06:57 PAGE 1   


C51 COMPILER V6.12, COMPILATION OF MODULE INTS
OBJECT MODULE PLACED IN E:\C51PRJ\INTS\INTS.OBJ
COMPILER INVOKED BY: d:\keil\c51\BIN\C51.EXE E:\C51PRJ\INTS\INTS.C DB SB OE

stmt level    source

   1          /****************************************************************************/
   2          /*                                                                          */
   3          /*                Copyright (c) 2005, 老树工作室                            */
   4          /*                     All rights reserved.                                 */
   5          /*                                                                          */
   6          /*      http://www.saintone.net      Email:hxm0902@163.com                  */
   7          /*      QQ:112431149                 Tel:010-62966630                       */
   8          /*                                                                          */
   9          /****************************************************************************/
  10          /****************************************************************************/
  11          /* 文件名:ints.c                                                           */
  12          /* 版  本:Version 1.0                                                      */
  13          /* 描  述:51中断编程演示代码                                               */
  14          /*                                                                          */
  15          /* 作  者:spot                                                             */
  16          /* 函  数:                                                                 */
  17          /*         com_command_receive                                              */
  18          /*         com_int_proc                                                     */
  19          /*         com_send_command                                                 */
  20          /*         ext0_int_proc                                                    */
  21          /*         ext1_int_proc                                                    */
  22          /*         system_init                                                      */
  23          /*         time0_over_int                                                   */
  24          /*                                                                          */
  25          /* 历史记录:                                                               */
  26          /*  spot          2005-07-10     Creat Inital version. (Version 1.0)        */
  27          /****************************************************************************/
  28          
  29          #include <reg52.h>
  30          #include <absacc.h>
  31          #include <intrins.h>
  32          #include <string.h>
  33          
  34          #define MAX_RINTL        16   /* 串口接收缓冲区长度   */
  35          typedef unsigned char u_char;
  36          typedef unsigned int  u_int;
  37          
  38          u_char pint_buf[MAX_RINTL];   /* 串口接收缓冲区       */
  39          u_char pint_read;             /* 串口缓冲区读指针     */
  40          u_char pint_write;            /* 串口缓冲区写指针     */
  41          u_char psend_int;             /* 串口发送允许标志     */
  42          
  43          u_int ext1_count;             /* 外部中断1中断计数    */
  44          u_char timer_count;           /* 定时计数             */
  45          bit   timer_int;              /* 定时标志             */
  46          
  47          char idata str_test[18]   = "MCS51 INTERRUPTS:";
  48          char idata str_ext0[15]   = "EXT0 INTERRUPT";
  49          char idata str_timer0[17] = "TIMER0 INTERRUPT";
  50          char str_hello[6]   = "HELLO";
  51          char str_world[6]   = "WORLD";
  52          
  53          /* 函数声明 */
  54          void ext0_int_proc(void); /* 外部中断0中断服务程序,使用第2组寄存器 */
  55          
C51 COMPILER V6.12  INTS                                                                   09/11/2005 11:06:57 PAGE 2   

  56          void time0_over_int(void);/* 定时器0中断服务程序 ,使用第1组寄存器  */
  57          
  58          void ext1_int_proc(void); /* 外部中断1中断服务程序,使用第2组寄存器 */
  59          
  60          void com_int_proc(void);  /* 串口中断服务程序,使用第3组寄存器      */
  61          
  62          void system_init(void);   /* 系统上电初始化 */
  63          
  64          void send_message(char str_message[]);/* 单片机串口发出消息 */
  65          /* 声明结束 */
  66          
  67          /* 外部中断0中断服务程序,使用第2组寄存器 */
  68          void ext0_int_proc(void) interrupt 0 using 2
  69          {
  70   1          EX0 = 0;       /* 关闭外部中断0 */
  71   1          send_message(str_ext0);
  72   1          EX0 = 1;       /* 开启外部中断0 */
  73   1      }
  74          
  75          /* 定时器0中断服务程序 ,使用第1组寄存器 */
  76          void time0_over_int(void) interrupt 1 using 1
  77          {
  78   1          TF0=0;
  79   1          timer_int=1;
  80   1          TH0 = -(46080 / 256);
  81   1          TL0 = -(46080 % 256);
  82   1      }
  83          
  84          /* 外部中断1中断服务程序,使用第2组寄存器 */
  85          void ext1_int_proc(void) interrupt 2 using 2
  86          {
  87   1          ext1_count++;
  88   1      
  89   1          if (ext1_count >= 3000)
  90   1          {
  91   2              ext1_count = 0;
  92   2              P1 = ~P1;
  93   2          }
  94   1      }
  95          
  96          /* 串口中断服务程序,使用第3组寄存器 */
  97          void com_int_proc(void) interrupt 4 using 3
  98          {
  99   1          u_char temp;
 100   1          u_char temp1;
 101   1      
 102   1          if (TI == 1)                /* 是发送中断       */
 103   1          {
 104   2              TI = 0;
 105   2              psend_int = 1;          /* 可以发送         */
 106   2          }
 107   1      
 108   1          if (RI == 1)                /* 是接收中断       */
 109   1          {
 110   2              RI = 0;                 /* 清串口接收中断   */
 111   2              temp1 = SBUF;
 112   2              temp  = pint_write + 1; /* 判断是否可以写入 */
 113   2              if (temp == MAX_RINTL)
 114   2              {
 115   3                  temp=0;
 116   3              }
 117   2      
C51 COMPILER V6.12  INTS                                                                   09/11/2005 11:06:57 PAGE 3   

 118   2              if (temp != pint_read)
 119   2              {
 120   3                  pint_buf[pint_write] = temp1; /* 读取数据 */
 121   3                  pint_write = temp;
 122   3              }
 123   2          }
 124   1      }
 125          
 126          /* 串口发送一个字节 */
 127          void com_send_command(char onebyte)
 128          {
 129   1          psend_int = 0;
 130   1          SBUF = onebyte;
 131   1          while (psend_int != 1);
 132   1      }
 133          
 134          /* 串口接收数据处理 */
 135          void com_command_receive(void)
 136          {
 137   1          u_char var1,var2;
 138   1          
 139   1          var2 = pint_read;
 140   1          if (var2 != pint_write)
 141   1          {
 142   2              var1=pint_buf[var2];
 143   2              var2=var2+1;
 144   2      
 145   2              if (var2 >= MAX_RINTL)
 146   2                  var2=0;
 147   2      
 148   2              pint_read=var2;
 149   2      
 150   2              if (var1 == 0x0A)    /* 收到0x0A */
 151   2              {
 152   3                  send_message(str_hello); /* 发送字符串HELLO */                
 153   3                  return;
 154   3              }
 155   2              if (var1 ==0x0D)     /* 收到0x0D */
 156   2              {
 157   3                  send_message(str_world); /* 发送字符串WORLD */               
 158   3                  return;
 159   3              }
 160   2          }
 161   1      }
 162          
 163          /* 系统上电初始化 */
 164          void system_init(void)
 165          {
 166   1          u_char loop;
 167   1      
 168   1          EA = 0;         /* CPU关中断      */
 169   1          timer_int = 0;
 170   1          timer_count = 0;
 171   1          
 172   1          pint_read  = 0; /* 串口缓冲读指针 */
 173   1          pint_write = 0; /* 串口缓冲写指针 */
 174   1      
 175   1          SCON = 0x48;
 176   1          PCON = 0x80;
 177   1          TMOD = 0x21;    /*定时器0方式1,定时器1方式2 */
 178   1          TCON = 0x54;

⌨️ 快捷键说明

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