ÉÂÎ÷Àí¹¤Ñ§Ôº±ÏÒµÉè¼Æ
¸½ ¼ C Ô´³ÌÐò
#include \#include \#include \#include \#include \#include \#include \#include \#include \#include \
void init_all(void) //³õʼ»¯ {
EA = 0; //¹Ø×ÜÖÐ¶Ï init_timer(); //¶¨Ê±Æ÷³õʼ»¯ init_uart(); //´®¿Ú³õʼ»¯ init_rc522(); //RC522³õʼ»¯ lcd_init(); //LCD³õʼ»¯
EEPROM_READ(0,Card_SN_BUF,4);//EEPROM³õʼ»¯,È¡³ö¼Ç¼µÄ¿¨ºÅ EEPROM_READ(7,KEY_BUF,8);//EEPROM³õʼ»¯,È¡³ö¼Ç¼µÄÃÜÂë
send_bytes(Card_SN_BUF,4); EA = 1; //¿ª×ÜÖÐ¶Ï }
void main(void) //Ö÷º¯Êý {
INT8U key;
Delay_ms(50); //ÈÃÓ²¼þÎȶ¨
init_all(); //Ö´Ðгõʼ»¯º¯Êý relay_OFF(); //¹Ø¼ÌµçÆ÷ LED_BLINK_1(); //led test beep1(); //beep test display(0,0,0); //ÏÔʾ³õʼ»¯ while(1) {
key=key_scan(); //°´¼ü²Ù×÷ if(key==12)
if(states>0) states--;
else states=0; //ÉÏÒ»¹¦ÄÜ
µÚ 32 Ò³ ¹² 61 Ò³
ÉÂÎ÷Àí¹¤Ñ§Ôº±ÏÒµÉè¼Æ
if(key==13)
if(++states>3) states=3; //ÏÂÒ»¹¦ÄÜ
ctrl_process(); //½øÈëRC522²Ù×÷ }
void time0() interrupt 1 //¶¨Ê±Æ÷ÖжÏ1 {
TH0=(65536-50000)/256; //¸ø¶¨Ê±Æ÷1¸³³õÖµ TL0=(65536-50000)%6; //¸ø¶¨Ê±Æ÷1¸³³õÖµ if(flag_m==1) {counts1++;}
if(counts1>150){counts1=0;beep1();} //count1=20ÊǼÆÊýÒ»Ã룬150´ó¸Å7.5Ãë if(l2==1){beep1();}
} }
#include \#include \#include \#include \#include \#include \#include \#include \#include \#include \#include \
INT8U states=0;//״̬»ú
INT8U Card_type[2], //¿¨Æ¬ÀàÐÍ Card_SN[4]={0},//IC¿¨ºÅ
Card_SN_BUF[4]={0xff,0xff,0xff,0xff},//¿¨ºÅµÇ¼Ç»º³åÇø KEY_BUF[8]={'0','0','0','0','0','0','0','0'}; INT8U bPass = 0; bWarn = 0;
void uart_over( void ) //´®¿ÚÊý¾Ý»¹Ô {
UartCount = 0; UartStart = FALSE; UartComp = FALSE; }
void pass( void ) {
beep1();
Delay_ms(2000);//Èÿ¨Æ¬À뿪 LED_BLINK_1();
µÚ 33 Ò³ ¹² 61 Ò³
ÉÂÎ÷Àí¹¤Ñ§Ôº±ÏÒµÉè¼Æ
}
void warn(void) {
LED_BLINK_2(); }
INT8U IC_READ( void ) {
INT8U ID_ASC[8],i;
if( PcdRequest( PICC_REQIDL, Card_type ) != MI_OK )//Ñ°ÌìÏßÇøÄÚδ½øÈëÐÝÃß״̬µÄ¿¨£¬·µ»Ø¿¨Æ¬ÀàÐÍ 2×Ö½Ú {
if( PcdRequest( PICC_REQIDL, Card_type ) != MI_OK )//Ñ°ÌìÏßÇøÄÚδ½øÈëÐÝÃß״̬µÄ¿¨£¬·µ»Ø¿¨Æ¬ÀàÐÍ 2×Ö½Ú {
return FALSE; } }
if( PcdAnticoll( Card_SN ) != MI_OK ) //·À³åײ£¬·µ»Ø¿¨µÄÐòÁкŠ4×Ö½Ú {
bWarn = 1;
return FALSE; }
bPass = 1;
send_bytes(Card_type,2); send_bytes(Card_SN,4);
for(i=0;i<4;i++) //¿¨IDºÅת»¯³ÉASCII {
if(Card_SN[i]/16>9) ID_ASC[i*2]=Card_SN[i]/16+'7'; else ID_ASC[i*2]=Card_SN[i]/16+'0';
if(Card_SN[i]>9) ID_ASC[i*2+1]=Card_SN[i]+'7'; else ID_ASC[i*2+1]=Card_SN[i]+'0'; }
display2(3,0,\ÏÔʾ¿¨ºÅ display2(3,2,ID_ASC,8);
return TRUE; }
µÚ 34 Ò³ ¹² 61 Ò³
ÉÂÎ÷Àí¹¤Ñ§Ôº±ÏÒµÉè¼Æ
void ctrl_process( void ) {
INT8U i,key_count,key_value=16,table[8]=\
if(states!=statesbuf) //״̬¸Ä±ä£¬ÇåÆÁ {
display_clear_line(2); display_clear_line(3); statesbuf=states; }
switch(states) {
case 0: //IC¿¨¶Á¿¨ÊäÈë display(1,0,1); if(IC_READ()) {
if ((Card_SN[0]==Card_SN_BUF[0]) &&(Card_SN[1]==Card_SN_BUF[1]) &&(Card_SN[2]==Card_SN_BUF[2]) &&(Card_SN[3]==Card_SN_BUF[3])) {
relay_ON();//µÆ¿ª¹Ø display(2,0,5); }
else display(2,0,6); relay_OFF(); }
break;
case 1:
display(1,0,2); //ÃÜÂëÊäÈë display2(3,0,table,8); key_count=0; while(1) {
key_value=key_scan(); if(key_value==12) {
states--; return; }
µÚ 35 Ò³ ¹² 61 Ò³