密码锁设计

河南工业职业技术学院

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

void Send(uchar Data) { uchar BitCounter=8; uchar temp; do { temp=Data; Scl=0; Nop(); if((temp&0x80)==0x80) Sda=1; else Sda=0; Scl=1; temp=Data<<1; Data=temp; BitCounter--; } while(BitCounter); Scl=0; }

uchar Read(void) {

uchar temp=0; uchar temp1=0;

uchar BitCounter=8; Sda=1; do{ Scl=0; Nop(); Scl=1;

26

河南工业职业技术学院

Nop(); if(Sda)

temp=temp|0x01; else

temp=temp&0xfe; if(BitCounter-1) {

temp1=temp<<1; temp=temp1; }

BitCounter--; }

while(BitCounter); return(temp); }

void WrToROM(uchar Data[],uchar Address,uchar Num) {

uchar i;

uchar *PData; PData=Data;

for(i=0;i

Start(); Send(0xa0); Ack();

Send(Address+i); Ack();

Send(*(PData+i)); Ack(); Stop();

mDelay(20); } }

void RdFromROM(uchar Data[],uchar Address,uchar Num) {

uchar i;

uchar *PData;

27

河南工业职业技术学院

PData=Data;

for(i=0;i

Start(); Send(0xa0); Ack();

Send(Address+i); Ack(); Start(); Send(0xa1); Ack();

*(PData+i)=Read(); Scl=0; NoAck(); Stop(); } }

#define yi 0x80

#define er 0x80+0x40 void delay(uint xms) {

uint x,y;

for(x=xms;x>0;x--) for(y=110;y>0;y--); }

write_1602com(uchar com) {

lcd1602_rs=0; lcd1602_rw=0; P0=com; delay(1); lcd1602_en=1; delay(1); lcd1602_en=0; }

write_1602dat(uchar dat) {

28

河南工业职业技术学院

lcd1602_rs=1; lcd1602_rw=0; P0=dat; delay(1);

lcd1602_en=1; delay(1); lcd1602_en=0; }

void lcd_init(void) {

write_1602com(0x38); write_1602com(0x0c); write_1602com(0x06); write_1602com(0x01); }

unsigned char coding(unsigned char m) {

unsigned char k;

switch(m) {

case (0x18): k=1;break; case (0x28): k=2;break; case (0x48): k=3;break; case (0x88): k='A';break; case (0x14): k=4;break; case (0x24): k=5;break; case (0x44): k=6;break; case (0x84): k='B';break; case (0x12): k=7;break; case (0x22): k=8;break; case (0x42): k=9;break; case (0x82): k='C';break; case (0x11): k='*';break; case (0x21): k=0;break; case (0x41): k='#';break; case (0x81): k='D';break;

29

联系客服:779662525#qq.com(#替换为@)