test.c
上传用户:wanlida60
上传日期:2022-03-09
资源大小:1928k
文件大小:16k
源码类别:

RFID编程

开发平台:

C/C++

  1. #include <mega8.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <delay.h>
  5. #include <lcd.h>
  6. #asm
  7.    .equ __lcd_port=0x18 ;PORTB
  8. #endasm
  9. unsigned char buff[14],counter=0,showlcd[20],flag=0,cardnumber=0,rightflag=0,c=0,counterled=0,usartcounter=0,mainflag=0,i=0;
  10. eeprom unsigned char card1[14],card2[14],card3[14],card4[14],card5[14],card6[14],card7[14],card8[14],card9[14],card10[14];
  11. // External Interrupt 0 service routine
  12. interrupt [USART_RXC] void usart_rx_isr(void)
  13. {
  14.         buff[usartcounter]=UDR;
  15.         if(usartcounter==13)
  16.         {
  17.                 mainflag=1;
  18.                 usartcounter=0;
  19.         }       
  20.         else if(usartcounter!=13) usartcounter++;
  21. }
  22. interrupt [EXT_INT0] void ext_int0_isr(void)
  23. {
  24.         delay_ms(200);
  25.         cardnumber++;
  26.         itoa(cardnumber,showlcd);
  27.         if(cardnumber<11)
  28.         {
  29.                 lcd_clear();
  30.                 lcd_putsf("  Set to save n    in Slot");
  31.                 delay_ms(500);
  32.                 lcd_clear();
  33.                 lcd_putsf("      #  #");
  34.                 lcd_gotoxy(7,0);
  35.                 lcd_puts(showlcd);
  36.                 delay_ms(500);
  37.               
  38.         }
  39.         else if(cardnumber>=11)
  40.         {       
  41.                 c=cardnumber-10;
  42.                 itoa(c,showlcd);
  43.                 lcd_clear();
  44.                 lcd_putsf("  Set to clear n     Slot");
  45.                 delay_ms(500);
  46.                 lcd_clear();
  47.                 lcd_putsf("      #  #");
  48.                 lcd_gotoxy(7,0);
  49.                 lcd_puts(showlcd);
  50.                 delay_ms(500);
  51.          
  52.         }
  53.         if(cardnumber>20)cardnumber=0;
  54. }
  55. // External Interrupt 1 service routine
  56. interrupt [EXT_INT1] void ext_int1_isr(void)
  57. {
  58.         delay_ms(200);
  59.         lcd_clear();
  60.         lcd_putsf("Waiting For Card");
  61.         for(counter=0;counter<14;counter++)
  62.         {
  63.                 buff[counter]=getchar();
  64.         }
  65.         lcd_clear();
  66.         lcd_putsf("OK");
  67.         delay_ms(200);
  68.         switch(cardnumber)
  69.         {
  70.             case 1:
  71.                 for(counter=0;counter<14;counter++)
  72.                 {
  73.                     card1[counter]=buff[counter];
  74.                     lcd_clear();
  75.                     lcd_putsf("Saved in slot 1");
  76.                     delay_ms(200);
  77.                    
  78.                 }
  79.                 break;
  80.             case 2:
  81.                 for(counter=0;counter<14;counter++)
  82.                 {
  83.                     card2[counter]=buff[counter];
  84.                     lcd_clear();
  85.                     lcd_putsf("Saved in slot 2");
  86.                     delay_ms(200);
  87.                 }
  88.                 break;
  89.             case 3:
  90.                 for(counter=0;counter<14;counter++)
  91.                 {
  92.                     card3[counter]=buff[counter];
  93.                     lcd_clear();
  94.                     lcd_putsf("Saved in slot 3");
  95.                     delay_ms(200);
  96.                 }
  97.                 break;    
  98.             case 4:
  99.                 for(counter=0;counter<14;counter++)
  100.                 {
  101.                     card4[counter]=buff[counter];
  102.                     lcd_clear();
  103.                     lcd_putsf("Saved in slot 4");
  104.                     delay_ms(200);
  105.                 }
  106.                 break;    
  107.              case 5:
  108.                 for(counter=0;counter<14;counter++)
  109.                 {
  110.                     card5[counter]=buff[counter];
  111.                     lcd_clear();
  112.                     lcd_putsf("Saved in slot 5");
  113.                     delay_ms(200);
  114.                 }
  115.                 break;
  116.             case 6:
  117.                 for(counter=0;counter<14;counter++)
  118.                 {
  119.                     card6[counter]=buff[counter];
  120.                     lcd_clear();
  121.                     lcd_putsf("Saved in slot 6");
  122.                     delay_ms(200);
  123.                 }
  124.                 break;
  125.             case 7:
  126.                 for(counter=0;counter<14;counter++)
  127.                 {
  128.                     card7[counter]=buff[counter];
  129.                     lcd_clear();
  130.                     lcd_putsf("Saved in slot 7");
  131.                     delay_ms(200);
  132.                 }
  133.                 break;    
  134.             case 8:
  135.                 for(counter=0;counter<14;counter++)
  136.                 {
  137.                     card8[counter]=buff[counter];
  138.                     lcd_clear();
  139.                     lcd_putsf("Saved in slot 8");
  140.                     delay_ms(200);
  141.                 }
  142.                 break;        
  143.              case 9:
  144.                 for(counter=0;counter<14;counter++)
  145.                 {
  146.                     card9[counter]=buff[counter];
  147.                     lcd_clear();
  148.                     lcd_putsf("Saved in slot 9");
  149.                     delay_ms(200);
  150.                 }
  151.                 break;
  152.             case 10:
  153.                 for(counter=0;counter<14;counter++)
  154.                 {
  155.                     card10[counter]=buff[counter];
  156.                     lcd_clear();
  157.                     lcd_putsf("Saved in slot 10");
  158.                     delay_ms(200);
  159.                 }
  160.                 break;
  161.             case 11:
  162.                 for(counter=0;counter<14;counter++)
  163.                 {
  164.                     card1[counter]=0;
  165.                     lcd_clear();
  166.                     lcd_putsf("cleared slot 1");
  167.                     delay_ms(200);
  168.                    
  169.                 }
  170.                 break; 
  171.             case 12:
  172.                 for(counter=0;counter<14;counter++)
  173.                 {
  174.                     card2[counter]=0;
  175.                     lcd_clear();
  176.                     lcd_putsf("cleared slot 2");
  177.                     delay_ms(200);
  178.                    
  179.                 }
  180.                 break; 
  181.             case 13:
  182.                 for(counter=0;counter<14;counter++)
  183.                 {
  184.                     card3[counter]=0;
  185.                     lcd_clear();
  186.                     lcd_putsf("cleared slot 3");
  187.                     delay_ms(200);
  188.                    
  189.                 }
  190.                 break; 
  191.             case 14:
  192.                 for(counter=0;counter<14;counter++)
  193.                 {
  194.                     card4[counter]=0;
  195.                     lcd_clear();
  196.                     lcd_putsf("cleared slot 4");
  197.                     delay_ms(200);
  198.                    
  199.                 }
  200.                 break; 
  201.             case 15:
  202.                 for(counter=0;counter<14;counter++)
  203.                 {
  204.                     card5[counter]=0;
  205.                     lcd_clear();
  206.                     lcd_putsf("cleared slot 5");
  207.                     delay_ms(200);
  208.                    
  209.                 }
  210.                 break; 
  211.             case 16:
  212.                 for(counter=0;counter<14;counter++)
  213.                 {
  214.                     card6[counter]=0;
  215.                     lcd_clear();
  216.                     lcd_putsf("cleared slot 6");
  217.                     delay_ms(200);
  218.                    
  219.                 }
  220.                 break; 
  221.             case 17:
  222.                 for(counter=0;counter<14;counter++)
  223.                 {
  224.                     card7[counter]=0;
  225.                     lcd_clear();
  226.                     lcd_putsf("cleared slot 7");
  227.                     delay_ms(200);
  228.                    
  229.                 }
  230.                 break; 
  231.             case 18:
  232.                 for(counter=0;counter<14;counter++)
  233.                 {
  234.                     card8[counter]=0;
  235.                     lcd_clear();
  236.                     lcd_putsf("cleared slot 8");
  237.                     delay_ms(200);
  238.                    
  239.                 }
  240.                 break;                               
  241.             case 19:
  242.                 for(counter=0;counter<14;counter++)
  243.                 {
  244.                     card9[counter]=0;
  245.                     lcd_clear();
  246.                     lcd_putsf("cleared slot 9");
  247.                     delay_ms(200);
  248.                    
  249.                 }
  250.                 break; 
  251.             case 20:
  252.                 for(counter=0;counter<14;counter++)
  253.                 {
  254.                     card10[counter]=0;
  255.                     lcd_clear();
  256.                     lcd_putsf("cleared slot 20");
  257.                     delay_ms(200);
  258.                    
  259.                 }
  260.                 break;  
  261.         }
  262.        
  263. }
  264. void main(void)
  265. {
  266. PORTB=0x00;
  267. DDRB=0x00;
  268. PORTC=0x00;
  269. DDRC=0xff;
  270. PORTD=0xff;
  271. DDRD=0x00;
  272. // External Interrupt(s) initialization
  273. // INT0: On
  274. // INT0 Mode: Low level
  275. // INT1: On
  276. // INT1 Mode: Low level
  277. GICR|=0xC0;
  278. MCUCR=0x00;
  279. GIFR=0xC0;
  280. // Timer(s)/Counter(s) Interrupt(s) initialization
  281. TIMSK=0x00;
  282. // USART initialization
  283. // Communication Parameters: 8 Data, 1 Stop, No Parity
  284. // USART Receiver: On
  285. // USART Transmitter: Off
  286. // USART Mode: Asynchronous
  287. // USART Baud Rate: 9600
  288. UCSRA=0x00;
  289. UCSRB=0x90;
  290. UCSRC=0x86;
  291. UBRRH=0x00;
  292. UBRRL=0x33;
  293. // LCD module initialization
  294. lcd_init(16);
  295. // Global enable interrupts
  296. #asm("sei")
  297. while (1)
  298.       {
  299.         lcd_clear();
  300.         lcd_putsf("ASMZ Group");
  301.         delay_ms(200);
  302.         lcd_clear();
  303.         lcd_putsf("ASMZ Group.");
  304.         delay_ms(200);
  305.         lcd_clear();
  306.         lcd_putsf("ASMZ Group..");
  307.         delay_ms(200);
  308.         lcd_clear();
  309.         lcd_putsf("ASMZ Group...");
  310.         delay_ms(200);
  311.         lcd_clear();
  312.         for(counter=0;counter<14;counter++)
  313.         {
  314.             buff[counter]=0;
  315.         }
  316.         
  317.         while(mainflag==0)
  318.         {
  319.                 
  320.                 
  321.                 lcd_putsf("Pass Your Cardn>");
  322.                 delay_ms(50);
  323.                 lcd_clear();
  324.                 lcd_putsf("Pass Your Cardn>>");
  325.                 delay_ms(50);
  326.                 lcd_clear();
  327.                 lcd_putsf("Pass Your Cardn>>>");
  328.                 delay_ms(50);
  329.                 lcd_clear();
  330.                 for(i=0;i<16;i++)
  331.                 {
  332.                         lcd_putsf("Pass Your Card");
  333.                         lcd_gotoxy(i,1);
  334.                         lcd_putsf(">>>>");
  335.                         delay_ms(50);
  336.                         lcd_clear();
  337.                         
  338.                 }
  339.                 lcd_putsf("Pass Your Cardn               <"); 
  340.                 delay_ms(50);
  341.                 
  342.                 for(i=16;i>0;i--)
  343.                 {
  344.                         lcd_putsf("Pass Your Card");
  345.                         lcd_gotoxy(i,1);
  346.                         lcd_putsf("<<<<");
  347.                         delay_ms(50);
  348.                         lcd_clear();
  349.                         
  350.                 }
  351.                 lcd_putsf("Pass Your Cardn<<<"); 
  352.                 delay_ms(50);
  353.                 lcd_clear();       
  354.                 lcd_putsf("Pass Your Cardn<<"); 
  355.                 delay_ms(50);
  356.                 lcd_clear();
  357.                 lcd_putsf("Pass Your Cardn<"); 
  358.                 delay_ms(50);
  359.                 lcd_clear();
  360.                 
  361.         }
  362.       
  363.         mainflag=0;
  364.         for(counter=0;counter<14;counter++)
  365.         {
  366.             if(buff[counter]==card1[counter]) flag++;
  367.         }
  368.         if(flag==14)
  369.         
  370.         {
  371.         lcd_clear();
  372.         lcd_putsf("card1");
  373.         PORTC.2=1;
  374.         for(counterled=0;counterled<5;counterled++)
  375.         {
  376.                 PORTC.5=~PORTC.5;
  377.                 delay_ms(400);
  378.         }
  379.         PORTC.2=0;
  380.         PORTC.5=0;
  381.         rightflag=1;
  382.         }
  383.         flag=0;
  384.         for(counter=0;counter<14;counter++)
  385.         {
  386.             if(buff[counter]==card2[counter])flag++;
  387.         }
  388.         if(flag==14)
  389.         {
  390.         lcd_clear();
  391.         lcd_putsf("card2");
  392.         PORTC.2=1;
  393.         for(counterled=0;counterled<5;counterled++)
  394.         {
  395.                 PORTC.5=~PORTC.5;
  396.                 delay_ms(400);
  397.         }
  398.         PORTC.2=0;
  399.         PORTC.5=0;
  400.         rightflag=1;
  401.         }
  402.         flag=0;
  403.         for(counter=0;counter<14;counter++)
  404.         {
  405.             if(buff[counter]==card3[counter])flag++;
  406.         }
  407.         if(flag==14)
  408.         {
  409.         lcd_clear();
  410.         lcd_putsf("card3");
  411.         PORTC.2=1;
  412.         for(counterled=0;counterled<5;counterled++)
  413.         {
  414.                 PORTC.5=~PORTC.5;
  415.                 delay_ms(400);
  416.         }
  417.         PORTC.2=0;
  418.         PORTC.5=0;
  419.         rightflag=1;
  420.         }
  421.         flag=0;
  422.         for(counter=0;counter<14;counter++)
  423.         {
  424.             if(buff[counter]==card4[counter])flag++;
  425.         }
  426.         if(flag==14)
  427.         {
  428.         lcd_clear();
  429.         lcd_putsf("card4");
  430.         PORTC.2=1;
  431.         for(counterled=0;counterled<5;counterled++)
  432.         {
  433.                 PORTC.5=~PORTC.5;
  434.                 delay_ms(400);
  435.         }
  436.         PORTC.2=0;
  437.         PORTC.5=0;
  438.         rightflag=1;
  439.         }
  440.         flag=0;
  441.         for(counter=0;counter<14;counter++)
  442.         {
  443.             if(buff[counter]==card5[counter])flag++;
  444.         }
  445.         if(flag==14)
  446.         {
  447.         lcd_clear();
  448.         lcd_putsf("card5");
  449.         PORTC.2=1;
  450.         for(counterled=0;counterled<5;counterled++)
  451.         {
  452.                 PORTC.5=~PORTC.5;
  453.                 delay_ms(400);
  454.         }
  455.         PORTC.2=0;
  456.         PORTC.5=0;
  457.         rightflag=1;
  458.         }
  459.         flag=0;
  460.         for(counter=0;counter<14;counter++)
  461.         {
  462.             if(buff[counter]==card6[counter])flag++;
  463.         }
  464.         if(flag==14)
  465.         {
  466.         lcd_clear();
  467.         lcd_putsf("card6");
  468.         PORTC.2=1;
  469.         for(counterled=0;counterled<5;counterled++)
  470.         {
  471.                 PORTC.5=~PORTC.5;
  472.                 delay_ms(400);
  473.         }
  474.         PORTC.2=0;
  475.         PORTC.5=0;
  476.         rightflag=1;
  477.         }
  478.         flag=0;
  479.         for(counter=0;counter<14;counter++)
  480.         {
  481.             if(buff[counter]==card7[counter])flag++;
  482.         }
  483.         if(flag==14)
  484.         {
  485.         lcd_clear();
  486.         lcd_putsf("card7");
  487.         PORTC.2=1;
  488.         for(counterled=0;counterled<5;counterled++)
  489.         {
  490.                 PORTC.5=~PORTC.5;
  491.                 delay_ms(400);
  492.         }
  493.         PORTC.2=0;
  494.         PORTC.5=0;
  495.         rightflag=1;
  496.         }
  497.         flag=0;
  498.         for(counter=0;counter<14;counter++)
  499.         {
  500.             if(buff[counter]==card8[counter])flag++;
  501.         }
  502.         if(flag==14)
  503.         {
  504.         lcd_clear();
  505.         lcd_putsf("card8");
  506.         PORTC.2=1;
  507.         for(counterled=0;counterled<5;counterled++)
  508.         {
  509.                 PORTC.5=~PORTC.5;
  510.                 delay_ms(400);
  511.         }
  512.         PORTC.2=0;
  513.         PORTC.5=0;
  514.         rightflag=1;
  515.         }
  516.         flag=0;
  517.         for(counter=0;counter<14;counter++)
  518.         {
  519.             if(buff[counter]==card9[counter])flag++;
  520.         }
  521.         if(flag==14)
  522.         {
  523.         lcd_clear();
  524.         lcd_putsf("card9");
  525.         PORTC.2=1;
  526.         for(counterled=0;counterled<5;counterled++)
  527.         {
  528.                 PORTC.5=~PORTC.5;
  529.                 delay_ms(400);
  530.         }
  531.         PORTC.2=0;
  532.         PORTC.5=0;
  533.         rightflag=1;
  534.         }
  535.         flag=0;
  536.         for(counter=0;counter<14;counter++)
  537.         {
  538.             if(buff[counter]==card8[counter])flag++;
  539.         }
  540.         if(flag==14)
  541.         {
  542.         lcd_clear();
  543.         lcd_putsf("card10");
  544.         PORTC.2=1;
  545.         for(counterled=0;counterled<5;counterled++)
  546.         {
  547.                 PORTC.5=~PORTC.5;
  548.                 delay_ms(400);
  549.         }
  550.         PORTC.2=0;
  551.         PORTC.5=0;
  552.         rightflag=1;
  553.         }
  554.         flag=0;
  555.         
  556.         
  557.         if(rightflag==0)
  558.         {
  559.         lcd_clear();
  560.         lcd_putsf("  Do not Match");
  561.         for(counterled=0;counterled<10;counterled++)
  562.         {
  563.                 PORTC.4=~PORTC.4;
  564.                 delay_ms(100);
  565.         }
  566.         lcd_clear();
  567.         lcd_putsf(" But The Cardn   id is >>");
  568.         for(counterled=0;counterled<5;counterled++)
  569.         {
  570.                 PORTC.4=~PORTC.4;
  571.                 delay_ms(100);
  572.         }
  573.         lcd_clear();
  574.         lcd_puts(buff);
  575.         delay_ms(1000);
  576.         PORTC.4=0;
  577.         }
  578.         
  579.         
  580.       rightflag=0;        
  581.       };
  582. }