main.c

来自「基于Arm Developer suite 1.2开发」· C语言 代码 · 共 122 行

C
122
字号

#include "71x_lib.h"
#include <string.h>
#include "SmartCard.h"
#define TEST  6
#define LED_INIT() (GPIO_Config(GPIO1, 3, GPIO_OUT_PP))
#define LED_ON() (GPIO1->PD &= ~2) 
#define LED_OFF() (GPIO1->PD |= 2 )
#define LED2_ON() (GPIO1->PD &= ~1) 
#define LED2_OFF() (GPIO1->PD |= 1 )
#define PWR_INIT() (GPIO_Config(GPIO0, 1 << 3, GPIO_OUT_PP))
#define PWR_ON() (GPIO0->PD |= 1 << 3)
#define PWR_OFF() (GPIO0->PD &= ~(1 << 3))
#define REMOVE() GPIO_Config(GPIO0, 1 << 14, GPIO_INOUT_WP);

vu32  TimerCount;                   
__irq void FIQ_Handler(void)
{
	TIM_FlagClear(TIM0, TIM_TOF);
	TimerCount++;
	EIC_FIQPendingBitClear(T0TIMI_FIQChannel);
}

void delay()
{
int i;
for(i=0;i<4000;i++);
}




int main()
{
    int ret;
    int i;
    u8 responce[40];
    u8 responce2[40];
    u8 responce3[40];
    u8 responce4[40];
    u8 responce5[40];
    u8 responce6[40];
    u16 Data[40];
    u16 gp;
    
    int len;
    PWR_INIT();
	PWR_ON();	
	REMOVE();
	LED_INIT();
	LED_ON();
	LED2_ON();	

	RCCU_Div2Config (ENABLE);  		  	         //OSC input is divided by 2
	RCCU_PLL1Config (RCCU_Mul_16, RCCU_Div_1);  //RCLK = 48MHz
	RCCU_RCLKSourceConfig (RCCU_PLL1_Output);    
	RCCU_MCLKConfig(RCCU_DEFAULT);		       //MCLK=48MHz
	RCCU_PCLKConfig(RCCU_DEFAULT);		  	  //PCLK2=24MHz APB2 periph
	RCCU_FCLKConfig(RCCU_DEFAULT);		  	  //PCLK1=24MHz APB1 periph (fast)
   /*    
	RCCU->CFR = 0x8008;// Enable DIV2 & select CLK2 as RCLK 4/2=2M
	RCCU->CCR = 0;
	//RCCU->PLL1CR = 0x57;		// Switch off PLL1
	//PCU->PLL2CR = 0x57;		// 旁路PLL关闭,PLL2输入频率(HCLK)3-5MHz,PLL倍频为12
    RCCU_MCLKConfig(RCCU_DEFAULT);// Configure MCLK = RCLK
    RCCU_FCLKConfig(RCCU_DEFAULT);// Configure FCLK = RCLK 
    RCCU_PCLKConfig(RCCU_DEFAULT);// Configure PCLK = RCLK
    RCCU_PLL1Config(RCCU_Mul_16, RCCU_Div_1);// Configure the PLL1(*16, /2 or /1)
  */
    TIM_Init(TIM0);//内部时钟分频系数,定时器输入时钟频率为 31+1
	TIM_PrescalerConfig(TIM0, 31);//1s(4M PCLK2) F=F(PCLK2)/(CC[7:0]+1)=F/32 
	//TIM_PrescalerConfig(TIM0, 7);
	TIM_ITConfig(TIM0, TIM_TO_IT, ENABLE);//FFFF*32=2^(16+5)=2^21=2M=4M/2             
	TIM_CounterConfig(TIM0, TIM_START);
	EIC_FIQChannelConfig(T0TIMI_FIQChannel, ENABLE);
	EIC_FIQConfig(ENABLE);
	memset(&responce[0], 0xFF, 40);
	memset(&responce2[0], 0xFF, 40);
	
	
	rst_IC(responce);     //ICC复位响应
	
	
	//rst_ESAM(responce2);     //ESAM复位响应
	
	switch(TEST)
			{  
				case 1:    /*test1:对已存在MF或DF的ESAM进行select操作,察看ESAM文件构成*/
				    ret = ESC_Command(0x00, 0x84, 0x00, 0x00,0x00,0x00,0x04,responce, &len);   //取4bytes随机数
					memset(&responce[0], 0xFF, 40);
					responce[0] = 0x3f;
				    responce[1] = 0x00;
				 	ret = ESC_Command(0x00, 0xA4, 0x00, 0x00, 2, responce, 64, responce, &len);   //select MF
				 	memset(&responce[0], 0xFF, 40);
				 	responce[0] = 0xDf;
				    responce[1] = 0x01;
				 	ret = ESC_Command(0x00, 0xA4, 0x00, 0x00, 2, responce, 64, responce, &len);   //select DF 01 
				 	break; 
				   
				case 2:   /* test2:擦除MF,完成后停止 */
				 	memset(&responce[0], 0xFF, 40);
					responce[0] = 0x3f;
				    responce[1] = 0x00;
				 	ret = ESC_Command(0x00, 0xA4, 0x00, 0x00, 2, responce, 64, responce, &len);   //select MF
				 	responce[0] = 0x3f;
				    responce[1] = 0x00;
				    ret = ESC_Command(0x80, 0x0e, 0x00, 0x00,0x02, responce, 64, responce, &len);   //Erase MF,注意必须在Select MF之后运行
				    break; 
				   
				case 3:  /* test3:对已擦除的ESAM的,getchallege ,select操作 */
				    ret = ESC_Command(0x00, 0x84, 0x00, 0x00,0x00,0x00,0x04,responce, &len);   //取4bytes随机数
				    memset(&responce[0], 0xFF, 40);
					responce[0] = 0x3f;
				    responce[1] = 0x00;
				 	ret = ESC_Command(0x00, 0xA4, 0x00, 0x00, 2, responce, 64, responce, &len);   //select MF(是否存在)
				    memset(&responce[0], 0xFF, 40);
				    responce[0] = 0xDf;
				    responce[1] = 0x01;
				 	ret = ESC_Command(0x00, 0xA4, 0x00, 0x00, 2, responce, 64, responce, &len);   //select DF 01(是否存在)
				 	break; 
				  
				case 4:   /*test4

⌨️ 快捷键说明

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