打印

请教:各位大虾帮忙看一下这段程序

[复制链接]
1390|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
liuw_zh|  楼主 | 2007-6-21 16:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
se, RC500, rc, AN, ST
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;
}
//--------------------------------------------------------------------------

相关帖子

沙发
liuw_zh|  楼主 | 2007-6-21 16:23 | 只看该作者

疑问

这是读卡程序,为什么只有在重新上电后才能读卡

使用特权

评论回复
板凳
liuw_zh|  楼主 | 2007-6-21 16:29 | 只看该作者

疑问

可能问题出在哪里??

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

9

主题

21

帖子

0

粉丝