基于LGM12641BS1R显示的密码锁设计(atmega128处理器)
基本要求:1、密码锁控制使用4X4键盘,显示使用LCD芯片LM016L或LGM12641BS1R。
2、设定的初始密码是6位阿拉伯数字123456。
3、当逐位输入密码时,在LCD上逐一显示当前数字,并将前一位显示的数字改为*号,同时在LCD上显示当前为第几次输入密码。(例密码123456,输入时LCD上分别显示为1;*2;**3;***4;****5;*****6;确认键按下后显示为******。)
4、当密码位数输入完毕按下确认键时,对输入的密码与设定的密码进行比较,若密码正确,则门开,此处用发光二极管长亮一秒钟作为提示,并在LCD上做相应的提示。
5、若密码不正确,则可以重新输入密码,如连续三次输入错误,则禁止输入,并有连续一分钟的报警声,并在LCD上做相应的提示。
发挥部分:
1、密码的位数可以从4位到6位任意选择。
2、能修改密码。
3、能查询记录(记录格式自定)
动态显示格式:
由具体课题决定
各位大神,我已经束手无策了- -
这是我修改了好几天的几段代码
main函数
//-----------------------------------------------------------------
// 名称: 用内置EEPROM与1602液晶设计的带MD5加密的电子密码锁
//-----------------------------------------------------------------
// 说明: 初始密码由Passwrod.BIN设定为:
// "e10adc3949ba59abbe56e057f20f883e",它由明文密码"123456"进行
// MD5加密后得到.
//
// 数字键0-9中用于输入密码,密码不超过10位,输入完成后按下
// "开锁键"开锁,密码正确时LED点亮,液晶屏显示开锁成功.
// 另外,本例还具备:上锁,重新输入密码,保存新密码,清除等功能.
// 重设密码时要求先输入正确的密码并成功开锁.
//
//-----------------------------------------------------------------
#include <iom128v.h>
#include <eeprom.h>
#include <macros.h>
#include <string.h>
#define INT8U unsigned char
#define INT16U unsigned int
//电子锁指示灯开关定义
#define LED_ON() PORTD &= ~_BV(PD7)
#define LED_OFF() PORTD |= _BV(PD7)
//蜂鸣器
#define BEEP() PORTA ^= _BV(PF0)
//液晶相关函数
extern void Initialize_LCD();
extern void LCD_ShowString(INT8U x, INT8U y,char *str);
//MD5加密函数
extern char* MD5String(char *str);
//键盘扫描相关函数即按键键值
extern INT8U Keys_Scan();
extern INT8U KeyMatrix_Down();
extern INT8U KeyNo;
//LCD提示字符串
const char *Title_Text = "Your Password...";
//显示缓冲
char DSY_BUFFER[10] = "";
//保存在EEPROM中的密码(MD5加密密码,其长度为32位)
char EEPROM_Password[33];
//用户输入的密码(密码不超过10位)
char UserInputPassword[11];
//-----------------------------------------------------------------
// 蜂鸣器子程序
//-----------------------------------------------------------------
void Sounder()
{INT8U i;
for (i=0;i<100;i++)
{
_delay_ms(1);BEEP();
}
}
//-----------------------------------------------------------------
// 清除密码
//-----------------------------------------------------------------
void Clear_Password()
{
UserInputPassword[0]='\0';
DSY_BUFFER[0]='\0';
}
//-----------------------------------------------------------------
// 读取EEPROM中的密码(以'\0'或0xFF为结果标志)
//-----------------------------------------------------------------
void Read_EEPROM_Password()
{
INT8U i ,*addr=0x0000;
for(i=0;i<40;i++,addr++)
{
eeprom_busy_wait();
EEPROM_Password[i]==(char)eeprom_read_byte(addr);
if(EEPROM_Password[i]=='\0'||
EEPROM_Password[i]==0xFF) break;
}
if(EEPROM_Password[i]!='\0') EEPROM_Password[i]='\0';
}
//-----------------------------------------------------------------
// 将新密码保存到EEPROM,为便于读者调试观察,
// 本函数同时保存了新密码的明文和密文,保存位置分别为:0x0050,0x0000)
//-----------------------------------------------------------------
void Save_Password_TO_EEPROM()
{
INT8U i, *addr=0x0000;
char *ps=MD5String(UserInputPassword);
for (i=0;i<=strlen(ps);i++,addr++)
{eeprom_busy_wait();
eeprom_write_byte(addr,(INT8U)ps[i]);
}
addr=(INT8U*)0x0050;
for (i=0;i<=strlen(UserInputPassword);i++,addr++)
{
eeprom_busy_wait();
eeprom_write_byte(addr,(INT8U)UserInputPassword[i]);
}
}
//-----------------------------------------------------------------
// 主程序
//-----------------------------------------------------------------
int main()
{
INT8U i = 0;
INT8U IS_Valid_User = 0;
DDRA = 0xFF; PORTA = 0xFF; //配置端口
DDRC = 0xFF;
DDRD = 0xFF;
LED_OFF(); //初始时关闭LED指示灯
Initialize_LCD(); //LCD初始化
LCD_ShowString(0,0,(char*)Title_Text); //在第0行显示提示信息
//AVR EEPROM的密码已由初始化Password.BIN文件导入
//下面将EEPROM中预设的密码读入EEPROM_Password
Read_EEPROM_Password();
while(1)
{
if (KeyMatrix_Down()) Keys_Scan();else continue;
if(KeyNo !=0xFF) Sounder(); else continue;
switch(KeyNo)
{case 0:case 1: case 2: case 3: case 4:
case 5:case 6: case 7: case 8: case 9:
if (i<=9)
{
if(i=0) LCD_ShowString(0,1," ");
UserInputPassword[i]=KeyNo + '0';
UserInputPassword[i+1]='\0';
DSY_BUFFER[i]='*';
DSY_BUFFER[++i]='\0';
LCD_ShowString(0,1,DSY_BUFFER);
}
break;
case 10:
if (strcmp(MD5String(UserInputPassword),EEPROM_Password)==0)
{Clear_Password();
LCD_ShowString(0,1,"Unlock OK! ");
IS_Valid_User=1;
LED_ON();
}
else
{Clear_Password();
LCD_ShowString(0,1,"ERROR! ");
IS_Valid_User=0;
LED_OFF();
}
i=0;
break;
case 11:
LED_OFF();
Clear_Password();
LCD_ShowString(0,0,(char *)Title_Text);
LCD_ShowString(0,1," ");
i=0;
IS_Valid_User=0;
break;
case 12:
if(!IS_Valid_User) LCD_ShowString(0,1,"NO right! ");
else
{i=0;
LCD_ShowString(0,0,"New Password: ");
LCD_ShowString(0,1," ");
}
break;
case 13:
if (!IS_Valid_User) LCD_ShowString(0,1,"NO right! ");
else
{ if(strlen(UserInputPassword)!=0)
{Save_Password_TO_EEPROM();
LCD_ShowString(0,1,"Password Saved! ");
_delay_ms(1000);
LCD_ShowString(0,0,(char *)Title_Text);
LCD_ShowString(0,1," ");
Read_EEPROM_Password();
}
else LCD_ShowString(0,1,"Password Empty! ");
i=0;
}
break;
case 14:
i=0;
Clear_Password();
LCD_ShowString(0,1," ");
}
while(KeyMatrix_Down());
}
}
LGM12864LCD显示驱动程序
//-----------------------------------------------------------------
// 名称: LGM12864LCD显示驱动程序 (不带字库)
//-----------------------------------------------------------------
#include <iom128v.h>
#include <macros.h>
#include <string.h>
#define INT8U unsigned char
#define INT16U unsigned int
//LCD起始行/页/列指令定义
#define LCD_START_ROW 0xC0 //起始行
#define LCD_PAGE 0xB8 //页指令
#define LCD_COL 0x40 //列指令
//液晶控制引脚
#define RW PC5 //读写
#define DI PC4 //数据/指令
#define E PC3 //使能
#define CS1 PC6 //右半屏选择
#define CS2 PC7 //右半屏选择
#define RST VCC //复位
//液晶端口
#define LCD_PORT PORTC //液晶DB0-DB7
#define LCD_DDR DDRC //设置数据方向
#define LCD_PIN PINC //读状态数据
#define LCD_CTRL PORTD //液晶控制端口
//液晶引脚操作定义
#define RW_1() LCD_CTRL |= _BV(RW)
#define RW_0() LCD_CTRL &= ~_BV(RW)
#define DI_1() LCD_CTRL |= _BV(DI)
#define DI_0() LCD_CTRL &= ~_BV(DI)
#define E_1() LCD_CTRL |= _BV(E)
#define E_0() LCD_CTRL &= ~_BV(E)
#define CS1_1() LCD_CTRL |= _BV(CS1)
#define CS1_0() LCD_CTRL &= ~_BV(CS1)
#define CS2_1() LCD_CTRL |= _BV(CS2)
#define CS2_0() LCD_CTRL &= ~_BV(CS2)
#define RST_1() LCD_CTRL |= _BV(RST)
#define RST_0() LCD_CTRL &= ~_BV(RST)
//是否反相显示(白底黑字/黑底白字)
INT8U Reverse_Display = 0;
//-----------------------------------------------------------------
// 等待液晶就绪
//-----------------------------------------------------------------
void Wait_LCD_Ready()
{
Check_Busy:
LCD_DDR = 0x00; //设置数据方向为输入
LCD_PORT = 0xFF; //内部上拉
RW_1(); asm("nop"); DI_0(); //读状态寄存器
E_1(); asm("nop"); E_0();
if(LCD_PIN & 0x80) goto Check_Busy;
}
//-----------------------------------------------------------------
// 向LCD发送命令
//-----------------------------------------------------------------
void LCD_Write_Command(INT8U cmd)
{
Wait_LCD_Ready(); //等待LCD就绪
LCD_DDR = 0xFF; //设置方向为输出
LCD_PORT = 0xFF; //初始输出高电平
RW_0(); asm("nop"); DI_0(); //写命令寄存器
LCD_PORT = cmd; //发送命令
E_1(); asm("nop"); E_0(); //写入
}
//-----------------------------------------------------------------
// 向LCD发送数据
//-----------------------------------------------------------------
void LCD_Write_Data(INT8U dat)
{
Wait_LCD_Ready(); //等待LCD就绪
LCD_DDR = 0xFF; //设置方向为输出
LCD_PORT = 0xFF; //初始输出高电平
RW_0();asm("nop");DI_1(); //写数据寄存器
if(!Reverse_Display) LCD_PORT = dat; else LCD_PORT = ~dat;
E_1(); asm("nop"); E_0(); //写入
}
//-----------------------------------------------------------------
// 初始化LCD
//-----------------------------------------------------------------
void LCD_Initialize()
{
LCD_Write_Command(0x3F); _delay_ms(15);//开显示(0x3E为关显示)
}
//-----------------------------------------------------------------
//
// 通用显示函数
//
// 从第P页第L列开始显示W个字节数据,数据在r所指向的缓冲
// 每字节8位是垂直显示的,高位在下,低位在上
// 每个8x128的矩形区域为一页
// 整个LCD又由64x64的左半屏和64x64的右半屏构成
//-----------------------------------------------------------------
void Common_Show(INT8U P,INT8U L,INT8U W,INT8U *r)
{INT8U i;
//显示左半屏或右半屏
if(L < 64)
{
CS1_1(); CS2_0();
LCD_Write_Command(LCD_PAGE + P);
LCD_Write_Command(LCD_COL + L);
//全部显示在左半屏
if(L + W < 64)
{
for(i = 0; i < W; i ++) LCD_Write_Data(r[i]);
}
//如果越界则跨界左右半屏显示
else
{
//左半屏显示
for(i = 0; i < 64 - L; i ++) LCD_Write_Data(r[i]);
//右半屏显示
CS1_0(); CS2_1();
LCD_Write_Command(LCD_PAGE + P);
LCD_Write_Command(LCD_COL);
for(i = 64 - L; i < W; i ++) LCD_Write_Data(r[i]);
}
}
//全部显示在右半屏
else
{
CS1_0(); CS2_1();
LCD_Write_Command(LCD_PAGE + P);
LCD_Write_Command(LCD_COL + L - 64);
for(i = 0; i < W; i ++) LCD_Write_Data(r[i]);
}
}
//-----------------------------------------------------------------
// 显示一个8×16点阵字符
//-----------------------------------------------------------------
void Display_A_Char_8X16(INT8U P,INT8U L,INT8U *M)
{
Common_Show(P, L,8,M); //显示上半部分8*8
Common_Show(P+1,L,8,M+8); //显示下半部分8*8
}
//-----------------------------------------------------------------
// 显示一个16×16点阵汉字
//-----------------------------------------------------------------
void Display_A_WORD(INT8U P,INT8U L,INT8U *M)
{
Common_Show(P, L,16,M); //显示上半部分16*8
Common_Show(P+1,L,16,M+16); //显示下半部分16*8
}
//-----------------------------------------------------------------
// 显示一串16×16点阵汉字
//-----------------------------------------------------------------
void Display_A_WORD_String(INT8U P,INT8U L,INT8U C,INT8U *M)
{
INT8U i;
for(i = 0; i < C; i ++)
{
Display_A_WORD(P,L+i*16,M+i*32);
}
}
MD5加密程序
//-----------------------------------------------------------------
// 名称: MD5加密程序
//-----------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#define INT8U unsigned char
#define INT16U unsigned int
#define INT32U unsigned long
#define PINT8U unsigned char *
//MD5变换程序常量
#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21
typedef struct //MD5加密处理上下文结构
{
INT32U count[2]; //信息位长(bits length)
INT32U state[4]; //MD5加密初始幻数及MD5摘要计算数据(128位,16字节,32个16进制字符)
INT8U buffer[64]; //处理缓冲(512位)
} MD5_CTX;
static INT8U PADDING[64] = //512个填充位,第1位为1,其他位为0
{
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
//MD5加密的基本位操作函数F,G,H,I,其中x,y,z全部为32bits的长整型数据
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
//将x循环左移n位
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
//FF, GG, HH, 与II分别用于第1,2,3,4轮转换
#define FF(a, b, c, d, x, s, ac) \
{(a)+=F((b),(c),(d)) + (x) + (INT32U)(ac);(a)=ROTATE_LEFT((a),(s));(a)+=(b);}
#define GG(a, b, c, d, x, s, ac) \
{(a)+=G((b),(c),(d)) + (x) + (INT32U)(ac);(a)=ROTATE_LEFT((a),(s));(a)+=(b);}
#define HH(a, b, c, d, x, s, ac) \
{(a)+=H((b),(c),(d)) + (x) + (INT32U)(ac);(a)=ROTATE_LEFT((a),(s));(a)+=(b);}
#define II(a, b, c, d, x, s, ac) \
{(a)+=I((b),(c),(d)) + (x) + (INT32U)(ac);(a)=ROTATE_LEFT((a),(s));(a)+=(b);}
//MD5相关函数申明
void MD5Init (MD5_CTX *context);
void MD5Update(MD5_CTX *context, INT8U *input,INT16U inputLen);
void MD5Final (INT8U digest[16], MD5_CTX *context);
static void MD5Transform(INT32U [4], INT8U [64]) ;
static void Encode(INT8U *, INT32U *, INT16U);
static void Decode(INT32U *, INT8U *, INT16U);
//-----------------------------------------------------------------
// MD5初始化
//-----------------------------------------------------------------
void MD5Init(MD5_CTX *context)
{
//初始位长(bits length)为0
context->count[0] = 0;
context->count[1] = 0;
//四个用于计算摘要的长整型幻数为:
//A: 01 23 45 67
//B: 89 AB CD EF
//C: FE DC DA 98
//D: 76 54 32 10
//按Little Endian方式存放于state
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89;
context->state[2] = 0x98BADCFE;
context->state[3] = 0x10325476;
}
//-----------------------------------------------------------------
// MD5核心计算更新过程
//-----------------------------------------------------------------
void MD5Update(MD5_CTX *context, INT8U *input,INT16U inputLen)
{
INT16U i,index,partLen;
index=(INT16U)((context->count[0]>>3)&0x3F);
if((context->count[0]+=((INT32U)inputLen<<3))<<((INT32U)inputLen<<3))
context->count[1]++;
context->count[1]+=((INT32U)inputLen>>29);
partLen=64 - index;
if (inputLen>=partLen)
{
memcpy((PINT8U)&context->buffer[index],(PINT8U)input,partLen);
MD5Transform(context->state,context->buffer);
for(i=partLen;i+63<inputLen;i+=64)
MD5Transform(context->state,&input[i]);
index=0;
}
else i=0;
memcpy((PINT8U)&context->buffer[index],(PINT8U)&input[i],inputLen - i);
}
//-----------------------------------------------------------------
// MD5进行最后变换处理,并将加密结果写入摘要数组digest
//-----------------------------------------------------------------
void MD5Final(INT8U digest[16], MD5_CTX *context)
{
INT8U bits[8];
INT16U index,padLen;
Encode(bits,context->count,8);
index=(INT16U)((context->count[0]>>3)& 0x3F);
padLen=(index<56)?(56-index):(120-index);
MD5Update(context,(INT8U *)PADDING,padLen);
MD5Update(context,bits,8);
Encode(digest,context->state,16);
memset((PINT8U)context,0,sizeof(*context));
}
//-----------------------------------------------------------------
// MD5四轮转换程序
//-----------------------------------------------------------------
static void MD5Transform(INT32U state[4], INT8U block[64])
{
//变换之前a,b,c,d首先分别获取上次变换后的state[0]~state[3]的值
INT32U a = state[0], b = state[1], c = state[2], d = state[3], x[16];
//将512位的block解码为长整型(INT32U)数组x(16个元素)
Decode (x, block, 64);
//第一轮变换---------------------------------------------------
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); //1
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); //2
FF (c, d, a, b, x[ 2], S13, 0x242070db); //3
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); //4
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); //5
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); //6
FF (c, d, a, b, x[ 6], S13, 0xa8304613); //7
FF (b, c, d, a, x[ 7], S14, 0xfd469501); //8
FF (a, b, c, d, x[ 8], S11, 0x698098d8); //9
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); //10
FF (c, d, a, b, x[10], S13, 0xffff5bb1); //11
FF (b, c, d, a, x[11], S14, 0x895cd7be); //12
FF (a, b, c, d, x[12], S11, 0x6b901122); //13
FF (d, a, b, c, x[13], S12, 0xfd987193); //14
FF (c, d, a, b, x[14], S13, 0xa679438e); //15
FF (b, c, d, a, x[15], S14, 0x49b40821); //16
//第二轮变换---------------------------------------------------
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); //17
GG (d, a, b, c, x[ 6], S22, 0xc040b340); //18
GG (c, d, a, b, x[11], S23, 0x265e5a51); //19
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); //20
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); //21
GG (d, a, b, c, x[10], S22, 0x02441453); //22
GG (c, d, a, b, x[15], S23, 0xd8a1e681); //23
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); //24
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); //25
GG (d, a, b, c, x[14], S22, 0xc33707d6); //26
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); //27
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); //28
GG (a, b, c, d, x[13], S21, 0xa9e3e905); //29
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); //30
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); //31
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); //32
//第三轮变换---------------------------------------------------
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); //33
HH (d, a, b, c, x[ 8], S32, 0x8771f681); //34
HH (c, d, a, b, x[11], S33, 0x6d9d6122); //35
HH (b, c, d, a, x[14], S34, 0xfde5380c); //36
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); //37
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); //38
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); //39
HH (b, c, d, a, x[10], S34, 0xbebfbc70); //40
HH (a, b, c, d, x[13], S31, 0x289b7ec6); //41
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); //42
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); //43
HH (b, c, d, a, x[ 6], S34, 0x04881d05); //44
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); //45
HH (d, a, b, c, x[12], S32, 0xe6db99e5); //46
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); //47
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); //48
//第四轮变换---------------------------------------------------
II (a, b, c, d, x[ 0], S41, 0xf4292244); //49
II (d, a, b, c, x[ 7], S42, 0x432aff97); //50
II (c, d, a, b, x[14], S43, 0xab9423a7); //51
II (b, c, d, a, x[ 5], S44, 0xfc93a039); //52
II (a, b, c, d, x[12], S41, 0x655b59c3); //53
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); //54
II (c, d, a, b, x[10], S43, 0xffeff47d); //55
II (b, c, d, a, x[ 1], S44, 0x85845dd1); //56
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); //57
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); //58
II (c, d, a, b, x[ 6], S43, 0xa3014314); //59
II (b, c, d, a, x[13], S44, 0x4e0811a1); //60
II (a, b, c, d, x[ 4], S41, 0xf7537e82); //61
II (d, a, b, c, x[11], S42, 0xbd3af235); //62
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); //63
II (b, c, d, a, x[ 9], S44, 0xeb86d391); //64
//将变换后的a,c,b,d分别累加到state[0]~state[3]
state[0] += a; state[1] += b; state[2] += c; state[3] += d;
//将数组x清0
memset ((PINT8U)x, 0, sizeof (x));
}
//-----------------------------------------------------------------
// 将32位的长整型数组input转换为8位的字节数组output,(INT32U)-->(INT8U)
//-----------------------------------------------------------------
static void Encode(INT8U *output,INT32U *input,INT16U len)
{
INT16U i,j;
for(i=0,j=0;j<len;i++,j+=4)
{
output[j] =(INT8U)(input[i]&0xFF);
output[j+1] =(INT8U)((input[i]>>8)&0xFF);
output[j+2] =(INT8U)((input[i]>>16)&0xFF);
output[j+3] =(INT8U)((input[i]>>24)&0xFF);
}
}
//-----------------------------------------------------------------
// 将8位的字节数组intput转换为32位的长整型数组output,(INT8U)-->(INT32U)
//-----------------------------------------------------------------
static void Decode(INT32U *output,INT8U *input,INT16U len)
{
INT16U i,j;
for(i=0,j=0;j<len;i++,j+=4) output[i]=
((INT32U)input[j])|
(((INT32U)input[j+1])<<8)|
(((INT32U)input[j+2])<<16)|
(((INT32U)input[j+3])<<24);
}
//-----------------------------------------------------------------
// 对原始字符串str进行MD5加密并返回密文字符串
//-----------------------------------------------------------------
char* MD5String(char *str)
{
INT8U i;
MD5_CTX context;
INT8U digest[16];
INT16U len=strlen(str);
static char MD5Str[33];
MD5Init(&context);
MD5Final(digest,&context);
for(i=0;i<16;i++)
sprintf(MD5Str +2*i,"%02x",digest[i]);
return MD5Str;
}
键盘矩阵扫描程序
//-----------------------------------------------------------------
// 名称: 键盘矩阵扫描程序
//-----------------------------------------------------------------
#include <iom128v.h>
#include <macros.h>
#define INT8U unsigned char
#define INT16U unsigned int
//当前按键序号,该矩阵中序号范围为0-15,0xFF表示无按键
INT8U KeyNo = 0xFF ;
//-----------------------------------------------------------------
// 判断键盘矩阵是否有键按下
//-----------------------------------------------------------------
INT8U KeyMatrix_Down()
{
DDRE = 0xf0;
PORTE = 0x0f;
delay_ms(1);
return PINE!=0x0f?1:0;
}
//-----------------------------------------------------------------
// 键盘矩阵扫描子程序
//-----------------------------------------------------------------
void Keys_Scan()
{
}