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

RFID编程

开发平台:

C/C++

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