DES算法部分
[mw_shl_code=c,true]/*
* des.c
*
* Created on: 2015-04-02
* Author: LFY
*/
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
typedef unsigned char u8;
typedef int S32;
void To2Bin(u8 p[8], S32 buf[64]) //将字节转换成二进制流
{
S32 i, k = 0;
S32 j;
for (i = 0; i < 8; i++)
{
j = 0x80;
for (; j; j >>= 1)
{
if (j & p)
{
buf[k++] = 1;
}
else
{
buf[k++] = 0;
}
}
}
}
S32 IP_Table[64] = //初始置换(IP)
{ 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, 61, 53,
45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7, 56, 48,
40, 32, 24, 16, 8, 0, 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44,
36, 28, 20, 12, 4, 62, 54, 46, 38, 30, 22, 14, 6 };
S32 E_Table[] = { //扩展变换E
31, 0, 1, 2, 3, 4, 3, 4, 5, 6, 7, 8, 7, 8, 9, 10, 11, 12, 11, 12, 13,
14, 15, 16, 15, 16, 17, 18, 19, 20, 19, 20, 21, 22, 23, 24, 23,
24, 25, 26, 27, 28, 27, 28, 29, 30, 31, 0 };
S32 S_Box[8][4][16] = { //8个s盒
{ { 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 }, { 0, 15, 7,
4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8 }, { 4, 1, 14, 8, 13,
6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0 }, { 15, 12, 8, 2, 4, 9, 1,
7, 5, 11, 3, 14, 10, 0, 6, 13 } },
{ { 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 }, { 3, 13, 4,
7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5 }, { 0, 14, 7, 11,
10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15 }, { 13, 8, 10, 1, 3, 15,
4, 2, 11, 6, 7, 12, 0, 5, 14, 9 } },
{ { 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 }, { 13, 7, 0,
9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1 }, { 13, 6, 4, 9, 8,
15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7 }, { 1, 10, 13, 0, 6, 9, 8,
7, 4, 15, 14, 3, 11, 5, 2, 12 } },
{ { 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 }, { 13, 8, 11,
5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9 }, { 10, 6, 9, 0, 12,
11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4 }, { 3, 15, 0, 6, 10, 1, 13,
8, 9, 4, 5, 11, 12, 7, 2, 14 } },
{ { 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9 }, { 14, 11, 2,
12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6 }, { 4, 2, 1, 11, 10,
13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14 }, { 11, 8, 12, 7, 1, 14, 2,
13, 6, 15, 0, 9, 10, 4, 5, 3 } },
{ { 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11 }, { 10, 15, 4,
2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8 }, { 9, 14, 15, 5, 2,
8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6 }, { 4, 3, 2, 12, 9, 5, 15,
10, 11, 14, 1, 7, 6, 0, 8, 13 } },
{ { 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1 }, { 13, 0, 11,
7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6 }, { 1, 4, 11, 13, 12,
3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2 }, { 6, 11, 13, 8, 1, 4, 10,
7, 9, 5, 0, 15, 14, 2, 3, 12 } },
{ { 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7 }, { 1, 15, 13,
8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2 }, { 7, 11, 4, 1, 9,
12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8 }, { 2, 1, 14, 7, 4, 10, 8,
13, 15, 12, 9, 0, 3, 5, 6, 11 } } };
S32 IP_1_Table[64] = //逆初始置换IP^-1
{ 39, 7, 47, 15, 55, 23, 63, 31, 38, 6, 46, 14, 54, 22, 62, 30, 37, 5,
45, 13, 53, 21, 61, 29, 36, 4, 44, 12, 52, 20, 60, 28, 35, 3,
43, 11, 51, 19, 59, 27, 34, 2, 42, 10, 50, 18, 58, 26, 33, 1,
41, 9, 49, 17, 57, 25, 32, 0, 40, 8, 48, 16, 56, 24 };
S32 P_Table[32] = //置换运算P
{ 15, 6, 19, 20, 28, 11, 27, 16, 0, 14, 22, 25, 4, 17, 30, 9, 1, 7, 23,
13, 31, 26, 2, 8, 18, 12, 29, 5, 21, 10, 3, 24 };
S32 PC_1[56] = { 56, 48, 40, 32, 24, 16,
8, //密钥置换PC_1
0, 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51,
43, 35, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5,
60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3 };
S32 PC_2[48] = //密钥置换PC_2
{ 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15,
6, 26, 19, 12, 1, 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32,
47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 };
void Replacement(S32 arry1[], S32 arry2[], S32 arry3[], S32 num)//置换函数(初始IP,逆初始IP,
{
S32 i, tmp;
for (i = 0; i < num; i++) {
tmp = arry2;
arry3 = arry1[tmp];
}
}
S32 move_times[16] = { 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 }; //对左移位的规定
void lif_move(S32 arry1[], S32 arry2[], S32 n) //左移位实现函数
{
S32 i;
for (i = 0; i < 28; i++) {
arry2 = arry1[(n + i) % 28];
}
}
S32 Son_Key[16][48]; //存放16轮子密钥
S32 Code_Buff[64]; //存放明文或密文
S32 L[17][32], R[17][32]; //存放加密过程中左右部分
void SubKey(S32 K0[64]) //子密钥产生函数
{
S32 i;
S32 j;
S32 K1[56], K2[56];
S32 pc_buf[17][28], pd_buf[17][28];
Replacement(K0, PC_1, K1, 56); //密钥置换PC_1
for (i = 0; i < 28; i++) //将PC_1输出的56比特分为左右两部分
{
pc_buf[0] = K1;
pd_buf[0] = K1[i + 28];
}
i = 0;
while (i < 16) {
lif_move(pc_buf, pc_buf[i + 1], move_times);
lif_move(pd_buf, pd_buf[i + 1], move_times);
for (j = 0; j < 28; j++) {
K2[j] = pc_buf[i + 1][j];
K2[j + 28] = pd_buf[i + 1][j];
}
Replacement(K2, PC_2, Son_Key, 48); //密钥置换PC_2
i++;
}
}
void S_compress(S32 arry[], S32 shc[]) //S盒压缩变换,其中数组shc存放经过s盒的结果
{
S32 h, l; //行,列
S32 sha[8]; //存放经过s盒的十进制结果
S32 i, j;
S32 temp[4];
for (i = 0; i < 8; i++) //s盒压缩变换
{
h = arry[(1 + (i * 6)) - 1] * 2 + arry[(6 + (i * 6)) - 1];
l = arry[(2 + (i * 6)) - 1] * 8 + arry[(3 + (i * 6)) - 1] * 4
+ arry[(4 + (i * 6)) - 1] * 2 + arry[(5 + (i * 6)) - 1];
sha = S_Box[h][l];
}
for (i = 0; i < 8; i++) {
for (j = 3; j >= 0; j--) {
temp[j] = sha % 2;
sha = sha / 2;
}
for (j = 0; j < 4; j++) {
shc[4 * i + j] = temp[j];
}
}
}
void To10(S32 a[], S32 b[], S32 n) //二进制转十进制
{
S32 i, j;
S32 temp;
S32 arry[16][4];
for (i = 0; i < n / 4; i++) {
for (j = 0; j < 4; j++) {
arry[j] = a[4 * i + j];
}
}
for (i = 0; i < n / 4; i++) {
temp = arry[0] * 8 + arry[1] * 4 + arry[2] * 2
+ arry[3] * 1;
b = temp;
}
}
void To102(S32 a[], S32 b[], S32 n) //二进制转十进制
{
S32 i, j;
S32 temp;
S32 arry[8][8];
S32 t = 1, k;
for (i = 0; i < n / 8; i++) {
for (j = 0; j < 8; j++) {
arry[j] = a[8 * i + j];
}
}
for (i = 0; i < n / 8; i++) {
temp = 0;
for (j = 7; j >= 0; j--) {
if (arry[j] == 1) {
t = 1;
for (k = 0; k < 7 - j; k++) {
t = t * 2;
}
temp += t;
}
}
b = temp;
}
}
void F_Function(S32 a[32], S32 b[32], S32 n) //F函数
{
S32 i;
S32 tmp[48];
S32 tep[32];
Replacement(a, E_Table, tmp, 48); //扩展变换E
for (i = 0; i < 48; i++) //与子密钥异或
{
tmp ^= Son_Key[n];
}
S_compress(tmp, tep); //压缩变换S
Replacement(tep, P_Table, b, 32); //置换运算P
}
void Encryption(S32 m0[64], S32 c1[64]) {
S32 i, k;
S32 arry[32];
S32 c0[64], m1[64];
Replacement(m0, IP_Table, m1, 64); //初始置换IP
for (i = 0; i < 32; i++) {
L[0] = m1;
R[0] = m1[i + 32];
}
k = 1;
while (k < 17) {
F_Function(R[k - 1], arry, k - 1);
for (i = 0; i < 32; i++) {
L[k] = R[k - 1];
R[k] = L[k - 1] ^ arry;
}
k++;
}
for (i = 0; i < 32; i++) {
c0 = R[16];
c0[i + 32] = L[16];
}
Replacement(c0, IP_1_Table, c1, 64); //逆初始置换
}
void changeKey(S32 a[16][48]) {
S32 i, j;
S32 tmp[16][48];
for (i = 0; i < 16; i++) {
for (j = 0; j < 48; j++) {
tmp[j] = a[j];
}
}
for (i = 0; i < 16; i++) {
for (j = 0; j < 48; j++) {
Son_Key[j] = tmp[15 - i][j];
}
}
}
void Decryption(S32 c1[], S32 m[]) {
S32 c0[64], t[64];
S32 i, k;
S32 arry[32];
changeKey(Son_Key);
Replacement(c1, IP_Table, c0, 64); //初始IP
for (i = 0; i < 32; i++) {
L[0] = c0;
R[0] = c0[i + 32];
}
k = 1;
while (k < 17) {
F_Function(R[k - 1], arry, k - 1);
for (i = 0; i < 32; i++) {
L[k] = R[k - 1];
R[k] = L[k - 1] ^ arry;
}
k++;
}
for (i = 0; i < 32; i++) {
t = R[16];
t[i + 32] = L[16];
}
Replacement(t, IP_1_Table, m, 64); //逆初始置换
}
void print_(u8 *s) //输出函数
{
S32 i;
S32 a[12], b[12], d[3][16];
S32 p[64], q[64];
for (i = 0; i < 32; i++) {
p = L[15];
p[32 + i] = R[15];
q = R[16];
q[i + 32] = L[16];
}
To10(Son_Key[14], a, 48);
To10(Son_Key[15], b, 48);
To10(Code_Buff, d[0], 64);
To10(p, d[1], 64);
To10(q, d[2], 64);
for (i = 0; i < 16; i++) {
if (i % 2 == 0) {
*(s + i / 2) = 16 * d[0] + d[0][i + 1];
}
}
}
S32 DES_Decrypt(u8 *code , u8 *result , u8 *key)
{
S32 m[64]; //m存放二进制明文/密文
S32 d[64]; //存放二进制密钥
To2Bin(code, m); //将8位密文转成64位bin
To2Bin(key, d); //将8位key转成64为bin
SubKey(d);
Decryption(m, Code_Buff); //将m解密放到c中
print_(result);
*(result + 8) = '\0';
return 1;
}
S32 DES_Encryption(u8 *result , u8 *key , u8 *code)
{
S32 mm[64]; //mm存放二进制明文/密文
S32 dd[64]; //dd存放二进制密钥
S32 d[16] ;
To2Bin(key, dd);
To2Bin(result, mm); //将明文转换成二进制流
SubKey(dd);
Encryption(mm, Code_Buff); //加密后放入c中
To10(Code_Buff, d, 64); //将每个c转成10进制16位放入d中
print_(code);
return 1;
}
S32 main(void)
{
u8 code[]={0x2F,0x30,0xA9,0x52,0xFC,0x3E,0x7B,0xFE};
u8 key[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
u8 result[20];
u8 result1[20];
u8 i=0;
DES_Decrypt(code , result , key) ;
printf("\r\n解密为\r\n");
for(i=0 ; i<8 ; i++)
{
printf("0x%02x ",result);
}
printf("\r\n加密为\r\n");
DES_Encryption(result , key , result1);
for(i=0 ; i<8 ; i++)
{
printf("0x%02x ",result1);
}
}[/mw_shl_code]
LKT加密IC通讯程序
[mw_shl_code=c,true]//===================================================================
// File Name : lkt.c
// Function : 模拟IO模拟对LKT进行通信,CLK源:timer4,pclk=66MHZ
// By : lfy
// Date : 03, 17, 2015
// Version : 0.0
// History :
//===================================================================
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
//=======================
//#include "core/includes.h" /* uC/OS interface */
#include "ucos_ii.h"
//=======================
#include "lcd.h"
#include "smdong.h"
#include "sm.h"
#include "smgn1.h"
#include "glib.h"
#include "smpage.h"
#include "HmiStart.h"
#include "def.h"
#include "initmain.h"
#include "smHzk16.h"
#include "math.h"
#include "usbin.h"
#include "MsgShow.h"
#include "DataTransmissionC.h"
#include "Timer.h"
#include "Macro_File.h"
#include "UpLoadRecipeData.h"
#include "Penetrate.h"
#include "rtc.h"
#include "w55fa93_gpio.h"
#include "common.h"
#include "lkt.h"
/**********************************************************
/*************************下面是系统命令包****************/
/**********************************************************
/*未提速:4M/372=10753bps---93us*/
/**************提速指令:SPEED=CLK/16=4M/16=250000bps---4us****/
u8 Raise_Speed_Older[]={0xff,0x10,0x96,0x79};
u8 Get_Random[]={0x00,0x84,0x00,0x00,0x02};//去2个随机数
/**********************************************************
/下面是DES/3DES加密后的密文调用函数,当前密钥为:XXXXXXXXXXXXXX
/**********************************************************/
/**********************************************************/
unsigned char LKT_Recive_Buff[RECIVE_DATA_CNT];
#pragma optimize=none
void Delay_30us(void)
{
volatile U32 i=30*26;
while(i)
i--;
}
#pragma optimize=none
void Delay_93us(void)
{
volatile U32 i=93*26;
while(i)
i--;
}
volatile U32 Loop_Cnt=0;
#pragma optimize=none
void Delay_1us(void)
{
volatile U32 i=1*26;
Loop_Cnt++;
while(i)
i--;
}
/*发送命令函数:,buf为命令包*/
void LKT_SendOlder(u8 *buf , u8 lenth )
{
u8 cnt,i=0 ,j ,t=0;
IO_OUT;
for(j=0 ; j<lenth ; j++)
{
cnt=0;
IO_L;
for(i=0 ; i<8 ; i++)
{
Delay_93us();
if(buf[t]&0x01)
{
IO_H;
cnt++;
}
else
{
IO_L;
}
buf[t]>>=1;
}
Delay_93us();
if(cnt%2)
{
IO_H;
}
else
{
IO_L;
}
Delay_93us();
IO_H;
//延时2个停止位
Delay_93us();
Delay_93us();
t++;
}
}
/*接收数据函数: num为个数*/
void LKT_RecvieData(u8 num )
{
u8 dat,i=0,j=0,t=0;
memset(LKT_Recive_Buff , 0 , RECIVE_DATA_CNT);
IO_IN;
for(j=0; j<num ; j++)
{
Loop_Cnt=0;
while(IO_DAT)
{
Delay_1us( );
if(Loop_Cnt>500000)
{
return;
}
}
dat=0x00;
Delay_30us();
for(i=0 ; i<8 ; i++)
{
Delay_93us();
dat>>=1;
if(IO_DAT)
{
dat|=0x80;
}
}
LKT_Recive_Buff[t]=dat;
t++;
// 最后三位(偶校验、2停止)用延时带过
Delay_93us();
Delay_93us();
Delay_93us();
}
}
void LKT_Rest(void)
{
LKT_REST_L;
delayy1(10);
LKT_REST_H;
}
/*程序下载拆分函数*/
/*
u8 Split_Older(const u8 *buff , u8 *outbuf )
{
u8 dat=0x00;
u8 i=0,j=0,k=0;
u8 *inbuf=buff;
u8 lenth=0;//strlen(inbuf);
for(j=0 ; j<lenth/2 ; j++)
{
dat=0x00;
if((inbuf[2*j]>='A')&&(inbuf[2*j]<='F'))
{
i=inbuf[2*j]-'A'+0x0a;
}
else
{
i=inbuf[2*j]-'0';
}
dat=(i<<4)&0xff;
if((inbuf[2*j+1]>='A')&&(inbuf[2*j+1]<='F'))
{
i=inbuf[2*j+1]-'A'+0x0a;
}
else
{
i=inbuf[2*j+1]-'0';
}
dat|=i;
outbuf[k++]=dat;
}
if(lenth%2
{
outbuf[k-1]>>=4;
}
return (k);
}
*/
/***********************************************
/*功能命令包*/
/***********************************************/
u8 Change_Password_Base[]={0xf0,0xf6,0x00,0x00,0x10};
u8 Change_Password[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x22,0x98,0x57,0x92,0x09,0x30,0x80};
/***********************************************
/*LKT程序下载,固定拆分5字节+后续字节*/
/***********************************************/
u8 pro1_base[]={0xF0,0xF6,0x00,0x00,0x08};
//u8 pro1[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
u8 pro1[]={0x18,0x22,0x98,0x57,0x92,0x09,0x30,0x80};
u8 pro2_base[]={0xF0,0xF4,0x40,0x00,0x40};
u8 pro2[]={0x8F,0x82,0x8E,0x83,0xA3,0xE0,0x70,0x03,0x12,0x40,0x0E,0x7F,0x01,0x22,0x8E,0x28,0x8F,0x29,0x8D,0x82,0x8C,0x83,0xA3,0x74,0x0F,0xF0,0x8D,0x82,0x8C,0x83,0xA3,0xA3,0x74,0xF3,0xF0,0x8D,0x82,0x8C,0x83,0xA3,0xA3,0xA3,0x74,0xCC,0xF0,0x8D,0x82,0x8C,0x83,0x74,0x03,0xF0,0x22,0x7E,0x04,0x7F,0x80,0x7C,0x04,0x7D,0x81,0x12,0x40,0x00};
u8 pro3_base[]={0xF0,0xF4,0x40,0x40,0x08};
u8 pro3[]={0x80,0xFE,0x75,0x81,0x29,0x02,0x40,0x35};
//u8 pro4_base[]={0xF0,0xF6,0x00,0x01,0x08};//获取算法压缩码
u8 pro4_base[]={0xF0,0xF6,0x00,0x02,0x08};//校验算法压缩码密文
//u8 pro4[]={0x28,0xAF,0xDA,0xDF,0xA7,0x67,0xF2,0x8E};//压缩码密文
u8 pro4[]={0x2F,0x30,0xA9,0x52,0xFC,0x3E,0x7B,0xFE};
/*程序下载*/
void LKT_DownLoad_Pro(void)
{
LKT_SendOlder(pro1_base ,5);
LKT_RecvieData(1);
sysprintf("back=0x%02x-----",LKT_Recive_Buff[0]);
Delay_93us();
LKT_SendOlder(pro1 ,8);
LKT_RecvieData(3);
sysprintf("back=0x%02x , 0x%02x\r\n",LKT_Recive_Buff[0],LKT_Recive_Buff[1]);
sysprintf("back=0x%02x \r\n",LKT_Recive_Buff[2]);
Delay_93us();
Delay_93us();
LKT_SendOlder(pro2_base ,5);
LKT_RecvieData(1);
Delay_93us();
sysprintf("back=0x%02x-----",LKT_Recive_Buff[0]);
LKT_SendOlder(pro2 ,64);
delayy1(1);
LKT_RecvieData(2);
sysprintf("back=0x%02x , 0x%02x\r\n",LKT_Recive_Buff[0],LKT_Recive_Buff[1]);
Delay_93us();
Delay_93us();
LKT_SendOlder(pro3_base ,5);
LKT_RecvieData(1);
Delay_93us();
sysprintf("back=0x%02x-----",LKT_Recive_Buff[0]);
LKT_SendOlder(pro3 ,8);
LKT_RecvieData(2);
sysprintf("back=0x%02x , 0x%02x\r\n",LKT_Recive_Buff[0],LKT_Recive_Buff[1]);
Delay_93us();
Delay_93us();
LKT_SendOlder(pro4_base ,5);
LKT_RecvieData(1);
Delay_93us();
sysprintf("back=0x%02x-----",LKT_Recive_Buff[0]);
LKT_SendOlder(pro4 ,8);
LKT_RecvieData(2);
sysprintf("back=0x%02x , 0x%02x\r\n",LKT_Recive_Buff[0],LKT_Recive_Buff[1]);
Delay_93us();
Delay_93us();
/*LKT_SendOlder(pro4_base ,5);
LKT_RecvieData(11);
sysprintf("算法压缩码为:\r\n");
sysprintf("back=0x%02x , 0x%02x\r\n",LKT_Recive_Buff[0],LKT_Recive_Buff[1]);
sysprintf("back=0x%02x , 0x%02x\r\n",LKT_Recive_Buff[2],LKT_Recive_Buff[3]);
sysprintf("back=0x%02x , 0x%02x\r\n",LKT_Recive_Buff[4],LKT_Recive_Buff[5]);
sysprintf("back=0x%02x , 0x%02x\r\n",LKT_Recive_Buff[6],LKT_Recive_Buff[7]);
sysprintf("back=0x%02x , 0x%02x\r\n",LKT_Recive_Buff[8],LKT_Recive_Buff[9]);
sysprintf("back=0x%02x \r\n",LKT_Recive_Buff[10]);
while(1);*/
}
void LKT4101_Init(void)
{
/*打开RST上拉,关闭IO上拉(外部上拉)*/
GPIOB_PUEN|=(1<<3);
// GPIOD_PUEN&=~(1<<13);
GPIOB_FUN&=~(3<<6);
GPIOD_FUN&=~(3<<26);
LKT_REST_OUT;
IO_IN;
LKT_Rest();
LKT_RecvieData(17);
sysprintf("Reset_Back\r\n");
sysprintf("0x%02x , 0x%02x , 0x%02x , 0x%02x\r\n",LKT_Recive_Buff[0],LKT_Recive_Buff[1],LKT_Recive_Buff[2],LKT_Recive_Buff[3]);
LKT_SendOlder(Get_Random,5);
LKT_RecvieData(4);
sysprintf("GetRandom\r\n");
sysprintf("0x%02x , 0x%02x ",LKT_Recive_Buff[0],LKT_Recive_Buff[1]);
sysprintf("0x%02x , 0x%02x ",LKT_Recive_Buff[2],LKT_Recive_Buff[3]);
sysprintf("0x%02x \r\n",LKT_Recive_Buff[4]);
Delay_93us();
Delay_93us();
//LKT_DownLoad_Pro();
}
[/mw_shl_code]
|