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

📄 main.lst

📁 很经典的单片机程序
💻 LST
字号:
C166 COMPILER V5.04, MAIN                                                                  10/01/2008 12:25:59 PAGE 1   


C166 COMPILER V5.04, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN Main.OBJ
COMPILER INVOKED BY: D:\Keil\C166\BIN\C166.EXE Main.c BROWSE MOD167 DEBUG

 stmt lvl     source

    1         #include <XC167.h>
    2         #include <stdio.h> 
    3         #include <stdlib.h>  
    4         #include <absacc.h> //宏定义,可以对某个绝对地址的存储器直接访问
    5         #include <Intrins.h>//内联函数
    6         #include <math.h>
    7         #include <main.h> 
    8         
    9         //DPR    起始地址  0x00 0000  空间  16KByte   CS0
   10         //FPGA   起始地址  0x01 0000  空间  64KByte   CS1
   11         //Flash  起始地址  0x10 0000  空间  1MByte        CS2
   12         //SRAM   起始地址  0x08 0000  空间  512KByte  CS3
   13         
   14         //DPR 0x00 1FFF: CPU side interrupt mailbox
   15         //DPR 0x00 1FFE:  X6 side interrupt mailbox
   16         //可以读双方的interrupt box,只能写对方的interrupt box
   17         #define DPR MARRAY(int, 0x000000)
   18         #define SEM MVAR(int, 0x000000)
   19         #define DPR_X6Mailbox  MVAR(unsigned char, 0x003FFE)
   20         #define DPR_CPUMailbox MVAR(unsigned char, 0x003FFF) 
   21         
   22         #define FPGA_TX MARRAY(int, 0x010000)//TX 32K
   23         #define FPGA_RX MARRAY(int, 0x018000)//RX 32K
   24         
   25         unsigned char buffer[15];
   26         
   27         void Delay(unsigned int US) 
   28         {
   29  1              while(US!=0)
   30  1                US--;
   31  1      }
   32         
   33         //初始化系统
   34         void init(void)
   35         {
   36  1        //Port9 Data Register 
   37  1              P9  = 0x03;    
   38  1        //Port9 Direction Ctrl. Register: 0 input, 1 output
   39  1              DP9 = DP9|0x03;
   40  1        
   41  1        //Port2 输入为标准TTL电平  
   42  1              PICON_P2HIN = 0;
   43  1              //Port2 Direction Ctrl. Register: 0 input, 1 output
   44  1              //P2_13: P1_X/INT-EV  Input
   45  1              //P2_14: P1_X/INT-CI  Input
   46  1              //P2_15: D1_INT       Input
   47  1              DP2 = DP2 & 0x1F;
   48  1      
   49  1        //Port 7 P7_P4: SEM DPR 旗语逻辑,设定为输出
   50  1        //P7_P4  = 1;  
   51  1        //DP7 = DP7 | 0x10;   
   52  1      }
   53         
   54         /*------------CRC16校验码的产生与校对-------------*/
   55         //对buffer[0]~buffer[dataLength-1]的字符计算CRC16校验码 
C166 COMPILER V5.04, MAIN                                                                  10/01/2008 12:25:59 PAGE 2   

   56         //check=1 => 用生成的校验码与buffer[dataLength]和buffer[dataLength+1]进行比较,
   57         //判断接收到的CRC16与本程序生成的校验码是否一致
   58         //check=0 => 用生成的校验码写入buffer[dataLength]和buffer[dataLength+1]中,
   59         //发送给接收设备
   60         /*-------------------------------------------------*/
   61         bit CRC16(unsigned int dataLength,unsigned char check)
   62         {
   63  1              unsigned int CheckSum;
   64  1              unsigned int j;
   65  1              unsigned char lowCRC;
   66  1              unsigned char highCRC;
   67  1              unsigned short i;
   68  1              
   69  1              CheckSum = 0xFFFF;
   70  1              for (j=0; j<dataLength; j++)
   71  1              {
   72  2                      CheckSum = CheckSum^(unsigned int)buffer[j];
   73  2                      for(i=8; i>0; i--)
   74  2                      {
   75  3                         //MODBUS 生成多项式0xA001: x^16+x^15+x^14+1
   76  3                         //PROFIBUS 生成多项式 0x1DCF:x^16+x^12+x^11+x^10+x^8+x^7+x^6+x^3+x^2+x+1
   77  3                              if(CheckSum & 0x0001)
   78  3                                      CheckSum = (CheckSum>>1)^0xA001;
   79  3                              else
   80  3                                      CheckSum >>= 1;
   81  3                      }       
   82  2              }
   83  1              highCRC = (unsigned char)(CheckSum>>8);
   84  1              CheckSum =CheckSum <<8;
   85  1              lowCRC = (unsigned char)(CheckSum >>8);
   86  1              if(check==1)
   87  1                      {
   88  2                              if((buffer[dataLength+1]==highCRC) &(buffer[dataLength]==lowCRC))
   89  2                                      return 1;
   90  2                              else return 0;  
   91  2                      } 
   92  1              else
   93  1                      {
   94  2                              buffer[dataLength] = lowCRC;
   95  2                              buffer[dataLength+1] = highCRC;
   96  2                              return 1;       
   97  2                      } 
   98  1      }
   99         
  100         void main (void)
  101         {
  102  1              unsigned char dataRX[16];
  103  1              int temp;
  104  1              int i,data[16];
  105  1      
  106  1              init();
  107  1              while (1) 
  108  1              {
  109  2                      if(P2_P14==0)
  110  2                      {
  111  3                         //向FPGA写数据:无数据域固定长度的帧:(SYN=33bit) SD1=10H  DA SA FC FCS1 ED=16H 
  112  3                              FPGA_TX[0] = SD1;
  113  3                              FPGA_TX[1] = 0xAB;
  114  3                              FPGA_TX[2] = 0x19;
  115  3                              FPGA_TX[3] = 0x20;
  116  3                              FPGA_TX[4] = 0xE4;
  117  3                              FPGA_TX[5] = ED;
C166 COMPILER V5.04, MAIN                                                                  10/01/2008 12:25:59 PAGE 3   

  118  3                      }
  119  2                      if(P2_P13==0)     //从FPGA接收数据
  120  2              {
  121  3                          for (i =0; i<4; i++)
  122  3                              {
  123  4                                  temp = FPGA_RX[i];
  124  4                                  dataRX[i*2]  = (unsigned char)(temp  & 0x00FF); 
  125  4                                  dataRX[i*2+1]= (unsigned char)(temp>>8 & 0x00FF);
  126  4                              }
  127  3                      P9  = ~P9;  
  128  3                      Delay(10000);      
  129  3              }
  130  2      /*------------采用旗语方式对DPR操作-------------*/
  131  2                //申请独占DPR,SEM = 0;--->> 使能P7_P4 SEM标志位 
  132  2      //      P7_P4  = 0;  
  133  2      //      DP7    = DP7 | 0x10;
  134  2      //      SEM    = 0;
  135  2      //      _nop_();
  136  2      
  137  2                 //回读SEM设置,如果为0,申请独占成功,可进行读写操作
  138  2      //      if (SEM ==0)
  139  2      //     {
  140  2      //              DPR[0]= 0xAB;
  141  2      //              DPR[1]= 0x54;
  142  2      //              DPR[2]= 0x36;
  143  2      //              DPR[3]= 0x89;            
  144  2      //
  145  2      //                      //释放独占权
  146  2      //                      SEM = 1;
  147  2      //                      P7_P4  = 1;  
  148  2      //                      DP7 = DP7 | 0x10; 
  149  2      //              }
  150  2      /*------------采用中断方式对DPR操作----------------*/
  151  2                 if(P2_P15==0)
  152  2                 {
  153  3                      //      if(DPR_CPUMailbox==0x11)  
  154  3                              DPR[0]= 0xAB;
  155  3                      DPR[1]= 0x54;
  156  3                      DPR[2]= 0x36;
  157  3                      DPR[3]= 0x89;   
  158  3                 }
  159  2              for (i =0;i<4;i++)
  160  2                      data[i]=DPR[i];
  161  2              
  162  2         }
  163  1      }
  164         


MODULE INFORMATION:   INITIALIZED  UNINITIALIZED
  CODE SIZE        =         380     --------
  NEAR-CONST SIZE  =    --------     --------
  FAR-CONST SIZE   =    --------     --------
  HUGE-CONST SIZE  =    --------     --------
  XHUGE-CONST SIZE =    --------     --------
  NEAR-DATA SIZE   =          31     --------
  FAR-DATA SIZE    =    --------     --------
  XHUGE-DATA SIZE  =    --------     --------
  IDATA-DATA SIZE  =    --------     --------
  SDATA-DATA SIZE  =    --------     --------
  BDATA-DATA SIZE  =    --------     --------
  HUGE-DATA SIZE   =    --------     --------
C166 COMPILER V5.04, MAIN                                                                  10/01/2008 12:25:59 PAGE 4   

  BIT SIZE         =    --------     --------
  INIT'L SIZE      =    --------     --------
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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