門禁的配件差不多買回來了。at89s52要二十塊,24c02要十塊,7805要5塊,洞洞板一小塊要十塊,id讀卡器45塊。唉,什么都貴死了。
光這個的價格就可以買個好的單門門禁了。但是制作的樂趣卻是買不到的,
上次的IIC和韋根26的程序從這里打開:http://www.zg4o1577.cn/mcu/1231.html
累啊!腦力勞動比體力勞動要累多了!寫得并調式好幾個程序花了我不少精力,打字都嫌累了,貼上幾個程序:
/*//////////////////////////////////// 函數原型: 函數說明:串口接收中斷 版本:V1.0.0 程序員:LIY12586 ////////////////////////////////////*/ void ser() interrupt 4 { RI=0; z=SBUF; ai=1; } /*//////////////////////////////////// 函數原型:void sound(uchar a) 函數說明:蜂鳴器發聲,a為需要發出多少次DIDI音 版本:V1.0.0 程序員:LIY12586 ////////////////////////////////////*/ void sound(uchar a) { uchar x,y; for(;a>0;a--) { for(x=255;x>0;x--) { beep=0; for(y=150;y>0;y--) beep=1; beep=0; } ysms(500); } } void ysms(unsigned int x) { unsigned int a; unsigned int b; for(a=x;a>0;a--) { for(b=50;b>0;b--); } } /*//////////////////////////////////// 函數原型:void inscard(void) 函數說明:存入卡號到EEPROM 版本:V1.0.0 程序員:LIY12586 ////////////////////////////////////*/ void inscard(void) { while(1) { if(re()) { if(iscard()==0)//如果沒有這卡號/ { uchar a,b; b=ckdz(); //查找空置/ for(a=3;a<6;a++) { wt24c(b,WG[a]); ys100us(1000); b++; } // wt24c(0,b); ys100us(1000); sound(1); break; } sound(2); break; } if(key()==12) { sound(1); break; } } } /*//////////////////////////////////// 函數原型:void delcard(void) 函數說明:從EEPROM中刪除卡號 版本:V1.0.0 程序員:LIY12586 ////////////////////////////////////*/ void delcard(void) { while(1) { if(re()) { if(iscard()!=0) //如果有這張卡號/ { uchar a,b; b=iscard(); //查找空置/ for(a=0;a<3;a++) { wt24c(b,0xff); ys100us(1000); b=b+1; } // wt24c(0,b); ys100us(1000); sound(1); break; } sound(2); break; } if(key()==12) { sound(2); break; } } } /*//////////////////////////////////// 函數原型:uchar iscard(void) 函數說明:查找是否有此卡 版本:V1.0.0 程序員:LIY12586 ////////////////////////////////////*/ uchar iscard(void) { uchar a,b; for(a=8;a<128;a++) { if(rd24c(a)==WG[3]) { a++; if(rd24c(a)==WG[4]) { a++; if(rd24c(a)==WG[5]) { b=a-2; return b; } } } if(a==127)return 0; } } /*//////////////////////////////////// 函數原型:uchar ckdz(void) 函數說明:查找EEPROM的空白位置地址 版本:V1.0.0 程序員:LIY12586 ////////////////////////////////////*/ uchar ckdz(void)//查空地址/ { uchar a,b,c; for(a=2;a<126;a++) { c=a; c++; if(rd24c(a)==0xff) { a++; if(rd24c(a)==0xff) { a++; if(rd24c(a)==0xff) { b=a-2; return b; } } } if(c==126)return 0xff; } } /*//////////////////////////////////// 函數原型:void readcard(void) 函數說明:讀卡正確 版本:V1.0.0 程序員:LIY12586 ////////////////////////////////////*/ void readcard(void) { if(re()) { if(iscard()!=0) { SEND(&WG[0]); open(); }sound(2); } } /*//////////////////////////////////// 函數原型:void open(void) 函數說明:打開 版本:V1.0.0 程序員:LIY12586 ////////////////////////////////////*/ void open(void) { //out=0; SEND(&WG[0]); sound(1); ysms(10000); //out=1; }