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

📄 main.lst

📁 DS8007 双智能卡读卡DEMO源代码。
💻 LST
字号:
C51 COMPILER V7.20   MAIN                                                                  03/19/2008 11:13:14 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE main.c LARGE OMF2 OPTIMIZE(9,SIZE) BROWSE INCDIR(C:\Program F
                    -iles\Keil\C51\INC\Dallas) VARBANKING DEBUG

line level    source

   1          /*---------------------------------------------------------------------------
   2           *  Copyright (C) 2004 Dallas Semiconductor Corporation, All Rights Reserved.
   3           * 
   4           *  Permission is hereby granted, free of charge, to any person obtaining a
   5           *  copy of this software and associated documentation files (the "Software"),
   6           *  to deal in the Software without restriction, including without limitation
   7           *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
   8           *  and/or sell copies of the Software, and to permit persons to whom the
   9           *  Software is furnished to do so, subject to the following conditions:
  10           * 
  11           *  The above copyright notice and this permission notice shall be included
  12           *  in all copies or substantial portions of the Software.
  13           * 
  14           *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15           *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16           *  MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17           *  IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
  18           *  OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19           *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20           *  OTHER DEALINGS IN THE SOFTWARE.
  21           * 
  22           *  Except as contained in this notice, the name of Dallas Semiconductor
  23           *  shall not be used except as stated in the Dallas Semiconductor
  24           *  Branding Policy.
  25           * ---------------------------------------------------------------------------
  26           */
  27          
  28          #include <stdio.h>
  29          #include <reg5000.h>
  30          #include <absacc.h>
  31          #include <stdlib.h>
  32          #include <string.h>
  33          #include "ds8007.h"
  34          #include "LCD_Funct.h"
  35          
  36          #define CPU_CRYSTAL 11059000//18432000*2
  37          #define BAUD_RATE 57600//115200
  38          #define BAUDDOUBLE 1
  39          
  40          
  41          void serialSetup()
  42          {
  43   1              TMOD=0x21;              // Timer 1: 8-bit auto-reload from TH1, Timer 0: 16-bit
  44   1              TH1 = 0xFE;
  45   1      
  46   1      #if (BAUDDOUBLE == 1)
  47   1              PCON|=0x80;             // Turn on baud rate doubler SMOD_0
  48   1      #else
                      PCON&=0x7F;             // Turn off baud rate doubler SMOD_0
              #endif
  51   1      
  52   1              TCON=0x50;              // Enable timers 0 and 1
  53   1              SCON=0x50;              // 10-bit async, enabled
  54   1      
C51 COMPILER V7.20   MAIN                                                                  03/19/2008 11:13:14 PAGE 2   

  55   1        TI=1;
  56   1      }
  57          
  58          uint8_t startsessionAPDU[] = { 0x80,0x84,0,0,8 };  // according to ACOS1
  59          //uint8_t startsessionAPDU[] = { 0xC0,0x84,0,0,6 };  // according to Smart Cards book pp.116
  60          //uint8_t startsessionAPDU[] = { 0x00,0x84,0,0,8 };  // according to ISO 7816
  61          //uint8_t startsessionAPDU[] = { 0x80,0x84,0,0,8,0,0,0,0,0,0,0,0,8 };
  62          
  63           void doTest(int slot)
  64          {
  65   1              uint8_t buff[512];
  66   1              uint8_t rbuff[512];
  67   1              int length;
  68   1              int16_t rlength;
  69   1              int i;
  70   1      
  71   1              dssc_selectcard(slot);
  72   1              i = dssc_powerup(POWERUP_ISO,POWERUP_5V);
  73   1              //i = dssc_powerup(POWERUP_EMV,POWERUP_5V);
  74   1       
  75   1              printf("Power up return: %d\n",i);
  76   1      
  77   1              if (i >= 0)
  78   1              {
  79   2                      length = dssc_getATRbuffer(buff,512);
  80   2      
  81   2                      printf("ATR:");
  82   2                      for (i = 0;i < length;i++)
  83   2                      {
  84   3                              printf(" %02bx",buff[i]);
  85   3                      }
  86   2                      puts("\n");
  87   2                      dssc_setNAD(0x00);
  88   2                      rlength = dssc_sendAPDU(startsessionAPDU,sizeof(startsessionAPDU),rbuff);
  89   2                      //rlength = dssc_sendAPDUT0(startsessionAPDU,sizeof(startsessionAPDU),rbuff);
  90   2                      //dssc_sendsblockIFSD(254);
  91   2                      //rlength = dssc_sendAPDUT1(startsessionAPDU,sizeof(startsessionAPDU),rbuff);
  92   2      
  93   2                      printf("APDU Response: %d\n",rlength);
  94   2                      for (i = 0;i < rlength;i++)
  95   2                              printf("%bX ",rbuff[i]);
  96   2              }
  97   1      
  98   1              printf("\r\n");
  99   1              dssc_powerdown();
 100   1      }
 101          
 102          void main(void)
 103          {
 104   1              int slot, tmp = 0;
 105   1              uint8_t val, temp;
 106   1              uint8_t LCD_Str[42];
 107   1      
 108   1              EA=0;
 109   1              serialSetup();
 110   1              puts("\n\nDS8007 Basic Test\n");
 111   1              val = dssc_readregister(CSR);
 112   1              printf("DS8007 Version: %bx\n",val>>4);
 113   1              dssc_init();
 114   1      
 115   1              printf("Compiled Crystal Frequency: %ld\n",CRYSTAL_FREQUENCY_8007);
 116   1      
C51 COMPILER V7.20   MAIN                                                                  03/19/2008 11:13:14 PAGE 3   

 117   1              // Initialize LCD Module, and display 2-line message.
 118   1              LCD_Init();
 119   1              strcpy(LCD_Str, "Dual Smart Card Int");         // Create 2nd line of LCD text
 120   1              tmp = LCD_Curpos(2,1);                                          // Position cursor @ 1 line 2
 121   1              if (tmp == 0) LCD_WRStr(LCD_Str);                       // Write string to LCD
 122   1              else printf("\n!! LCD cursor address out of range !!\n");
 123   1              strcpy(LCD_Str, "DS8007 MultiProtocol");        // Create first line of LCD text
 124   1              tmp = LCD_Curpos(1,1);                                          // Position cursor @ 1 line 1
 125   1              if (tmp == 0) LCD_WRStr(LCD_Str);                       // Write string to LCD
 126   1              else printf("\n!! LCD cursor address out of range !!\n");
 127   1              tmp = LCD_Curpos(2,20);                                         // Return cussor @ 20 line 2
 128   1      
 129   1      
 130   1              while (1)
 131   1              {
 132   2                      printf("\n\nWaiting for smartcard presence\n");
 133   2                      //val = dssc_readregister(MSR);
 134   2                      //printf("MSR: %bx\n",val);
 135   2                      while (1)
 136   2                      {
 137   3                      val = dssc_readregister(MSR);
 138   3                              if(temp != val){
 139   4                                      //printf("MSR: %bx\n",val);
 140   4                                      //printf("Status check - 1\n"); 
 141   4                                      temp = val;
 142   4                              }
 143   3                              if (val & MSR_PR1_MASK)
 144   3                  {
 145   4                                      slot = 1;
 146   4                                      //printf("Status check - 3\n");
 147   4                              break;
 148   4                      }
 149   3                      if (val & MSR_PR2_MASK)
 150   3                      {
 151   4                                      slot = 2;
 152   4                                      printf("Status check - 4\n");
 153   4                              break;
 154   4                          }
 155   3                      }
 156   2        
 157   2                      printf("Found smartcard in slot %d\n",slot);
 158   2      
 159   2                      doTest(slot);
 160   2      
 161   2                      printf("\r\n\r\nWaiting for smartcard removal from slot %d\n",slot);
 162   2                      do
 163   2                      {
 164   3                      val = dssc_readregister(MSR);
 165   3                      }
 166   2                      while(( (val&MSR_PR1_MASK) != 0) || ( (val&MSR_PR2_MASK) != 0) );
 167   2                      printf("Smartcard removed\n");
 168   2              }
 169   1              printf("Exiting\n");
 170   1              while (1);
 171   1      }
 172          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    604    ----
   CONSTANT SIZE    =    374    ----
   XDATA SIZE       =      5    1078
C51 COMPILER V7.20   MAIN                                                                  03/19/2008 11:13:14 PAGE 4   

   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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