AUXR = 0X03; buzzer_moment(); init_cpu_io(); init_var(); feed_dog(); soft_reset_rc500(); feed_dog(); init_rc500(); init_rtc(); init_cpu(); g_task1 = 0x01; while(1) { feed_dog(); if( (g_task1&0x01) == 0x01) { if(flag_soft_rc500) { flag_soft_rc500 = 0; soft_reset_rc500(); init_rc500(); } g_task1 &= ~0x01; g_state_rc500 = 1; config_rc500_request(); } if( (g_task1&0x02) == 0x02) { g_task1 &= ~0x02; g_state_rc500 = 2; config_rc500_anticollision(); } if( (g_task1&0x04) == 0x04) { g_task1 &= ~0x04; g_state_rc500 = 3; get_rc500_card_serial(); buzzer_on_moment(); g_led_on(); g_card_left = CONST_CARD_OFF; if( !data_equal() ) { copy_data(); //get_pin_master_or_general_card(); wiegand_send_type = 1; switch( wiegand_send_type ) { case 0x00: //rc500_rst = 1; convert_rc500_serial_no_wiegand34(); wiegand_send(34,rc500_serial_no); //g_led_on(); //buzzer_on_moment(); break; case 0x01: //rc500_rst = 1; convert_rc500_serial_no_wiegand26(); wiegand_send(26,rc500_serial_no); //g_led_on(); //buzzer_on_moment(); break; case 0x02: //rc500_rst = 1; convert_rc500_serial_no_wiegand26_site_code(); wiegand_send(26,rc500_serial_no); // g_led_on(); // buzzer_on_moment(); break; case 0x03: config_rc500_select_card(); break; case 0x04: //rc500_rst = 1; convert_rc500_serial_no_wiegand44(); wiegand_send(44,rc500_serial_no); //g_led_on(); //buzzer_on_moment(); break; case 0x05: //rc500_rst = 1; convert_rc500_serial_no_wiegand34(); wiegand_send(32,rc500_serial_no); //g_led_on(); //buzzer_on_moment(); break; case 0x06: //rc500_rst = 1; convert_rc500_serial_no_wiegand34(); wiegand_send(40,rc500_serial_no); // g_led_on(); //buzzer_on_moment(); break; } } else { g_task1 |= 0x01; } } if( (g_task1&0x08) == 0x08) { g_task1 &= ~0x08; g_state_rc500 = 4; config_rc500_pcd_loadkey(); // ok } if( (g_task1&0x10) == 0x10) { g_task1 &= ~0x10; g_state_rc500 = 5; config_rc500_picc_authenticate1(); } if( (g_task1&0x20) == 0x20) { g_task1 &= ~0x20; g_state_rc500 = 6; config_rc500_picc_authenticate2(); } if( (g_task1&0x40) == 0x40) { g_task1 &= ~0x40; g_state_rc500 = 7; config_rc500_read_picc_data(); } if( (g_task1&0x80) == 0x80) { g_task1 &= ~0x80; get_rc500_data_block(); //rc500_rst = 1; // --------ADD 3------------- g_led_on(); //wiegand_send_ye(rc500_serial_no[0],&rc500_serial_no[1]); wiegand_send(rc500_serial_no[0],&rc500_serial_no[1]); buzzer_on_moment(); } } } //--------------------------------------------------------- void rc500_interrupt (void) interrupt 0 using 1 { cs_rc500 = 0; if( (interruptrq&0x20) == 0x20 ) // irq_timeout { g_task1 |= 0x01; command = PCD_IDLE; } else if( g_state_rc500==4 ) { if( (errorflag&0x17)==0x00 ) g_task1 |= 0x10; else g_task1 |= 0x01; command = PCD_IDLE; } else if( g_state_rc500==5 ) { if( (errorflag&0x17)==0x00 ) g_task1 |= 0x20; else g_task1 |= 0x01; command = PCD_IDLE; } else if( g_state_rc500==6 ) { if( (errorflag&0x17)==0x00 && (control&0x08)==0x08) g_task1 |= 0x40; else g_task1 |= 0x01; command = PCD_IDLE; } else if( (interruptrq&0x08) == 0x08 ) // irq_rx { control |= 0x04; switch( g_state_rc500 ) { case 1: if( (errorflag&0x17)==0x00 && fifolength==0x02 ) g_task1 |= 0x02; else g_task1 |= 0x01; break; case 2: if( (errorflag&0X17)==0x00 && fifolength==0x05 ) g_task1 |= 0x04; else g_task1 |= 0x01; break; case 3: if( (errorflag&0x17)==0x00 && fifolength==0x01 ) g_task1 |= 0x08; else g_task1 |= 0x01; break; case 7: if( (errorflag&0x17)==0x00 && fifolength==0x10 ) g_task1 |= 0x80; else g_task1 |= 0x01; break; default : g_task1 |= 0x01; break; } command = PCD_IDLE; } else { g_task1 |= 0x01; command = PCD_IDLE; } cs_rc500 = 1; } //-------------------------------------------------------------------------- |