密码锁设计 下载本文

附录: a、器件清单

器件名称 规格型号 编号 数量 备注 22

b、源程序

#include #include #include #include #define LCM_Data P0

#define uchar unsigned char #define uint unsigned int #define w 4 sbit key = P2^0; sbit alam = P2^1; sbit open_led=P2^2; sbit lcd1602_rs=P2^5; sbit lcd1602_rw=P2^6; sbit lcd1602_en=P2^7; sbit Scl=P3^4; sbit Sda=P3^5; sbit xianshi = P3^7; bit operation=0; bit pass=0; bit mmsd=0;

void Delay5Ms(void) {

unsigned int TempCyc = 5552; while(TempCyc--); }

void Delay400Ms(void) {

unsigned char TempCycA = 5; unsigned int TempCycB; while(TempCycA--) {

TempCycB=7269; while(TempCycB--); } }

bit ReInputEn=0;

23

河南工业职业技术学院

bit s3_keydown=0; bit key_disable=0;

unsigned char countt0,second; void Delay5Ms(void);

static unsigned char tmp2=80; unsigned char m,d,sjmbz=0;

unsigned char code a[]={0xFE,0xFD,0xFB,0xF7};

unsigned char code name[] = {%unsigned char code Correct[] = {%unsigned char code Error[] = {\ unsigned char code suijishu[] = {\ unsigned char code set[] = {\ unsigned char code sjp[] = {%unsigned char code start_line[] = {%unsigned char code codepass[] = {%unsigned char code LockOpen[] = {\ unsigned char code SetNew[] = {%unsigned char code Input[] = {\ unsigned char code ResetOK[] = {%unsigned char code Er_try[] = {%unsigned char code again[] = {%unsigned char code initword[] = {%unsigned char InputData[4]; unsigned char CurrentPassword[4]={1,3,1,4}; unsigned char TempPassword[4]; unsigned char N=0; unsigned char cun[1]; unsigned char C=3; unsigned char ErrorCont; unsigned char CorrectCont; unsigned char ReInputCont;

unsigned char code initpassword[4]={0,0,0,0}; void mDelay(uint t) {

uchar i; while(t--) {

24

河南工业职业技术学院

for(i=0;i<125;i++) {;} } }

void Nop(void) {

_nop_(); _nop_(); _nop_(); _nop_(); }

void Start(void) {

Sda=1; Scl=1; Nop(); Sda=0; Nop(); }

void Stop(void) {

Sda=0; Scl=1; Nop(); Sda=1; Nop(); }

void Ack(void) {

Sda=0; Nop(); Scl=1; Nop(); Scl=0; }

void NoAck(void) {

25