⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readermodule.lst

📁 Use this program to decode the Manchester Code of the RFID. Validate the accessibility of detected c
💻 LST
📖 第 1 页 / 共 5 页
字号:
 643   1      }
 644          /***************************************************************************************************
 645          Handle buzzer task
 646          ****************************************************************************************************/
 647          void process_buzzer(void)
 648          {
 649   1              if (Flags.DoorOpen)
 650   1                    ClearBuzz();
 651   1              else if (!buzzer_type)
 652   1              {
 653   2                      BUZZER = OFF;
 654   2                      ClearBuzz();
 655   2                      return;
 656   2              }       
 657   1              else
 658   1              {       
 659   2                       if (++buzz_counter >=BUZZCOUNTER * 2 * buzz_duration)// 200// BUZZCOUNTER * buzz_duration*2)
 660   2                      {
 661   3                              buzzer_type --;
 662   3                              buzz_counter = 1;
 663   3                      }
 664   2      
 665   2                      if (buzzer_type & 0x01)
C51 COMPILER V7.06   READERMODULE                                                          09/05/2006 01:45:27 PAGE 12  

 666   2                              BUZZER = ON;//ON;//12/13/2005 10:52PM
 667   2                      else
 668   2                              BUZZER = OFF;   
 669   2                  
 670   2               }
 671   1      }
 672          /************************************************************************************
 673          I2C start for EEPROM 24C64C
 674          Dont forget to define the PIN for SCL and SDA
 675          *************************************************************************************/
 676          void I2C_Start(void)
 677          {
 678   1              SCL=HIGH;
 679   1              SDA=HIGH;
 680   1              SDA=LOW;
 681   1              SCL=LOW;
 682   1      }
 683          /************************************************************************************
 684          I2C stop for EEPROM 24C64C
 685          *************************************************************************************/
 686          void I2C_Stop(void)
 687          {
 688   1              SDA = LOW;
 689   1              SCL = HIGH;
 690   1              SDA=HIGH;
 691   1              //Delay_us(1);  //11/3/2005 4:56PM
 692   1      }
 693          /********************************************************
 694          Function        :Shift out a byte to the AT24Cxx, most significant bit first.
 695                          :SCL, SDA expected low on entry. Return with SCL low.
 696          Remarks         :retun 0-success, 1-success                     
 697          *********************************************************/
 698          char I2C_Write(unsigned char byte)
 699          {
 700   1              unsigned char i;        
 701   1              
 702   1              for(i=0; i <8; i++)
 703   1              {               
 704   2                      SDA=(byte<<i) & 0x80; //shift 1 bit out and store in temp               
 705   2                      SCL=HIGH;       //to clock the data in  
 706   2                      SCL=LOW;                
 707   2              }
 708   1      
 709   1              SDA = HIGH;
 710   1              SCL = HIGH;
 711   1              i=SDA;
 712   1              SCL=LOW;
 713   1              return i;       //return 0 -success
 714   1                              //return 1-fail
 715   1              
 716   1      }
 717          /***************************************************************************************************
 718          Function        :Shift in a byte from the AT24Cxx, most significant bit first.
 719                          :SCL expected low on entry. Return with SCL low.
 720          ***************************************************************************************************/
 721          unsigned char I2C_Read(void)
 722          {
 723   1              char i;
 724   1              unsigned char bitin=0, bytein=0;
 725   1              
 726   1              for(i=0; i<8; i++)
 727   1              {               
C51 COMPILER V7.06   READERMODULE                                                          09/05/2006 01:45:27 PAGE 13  

 728   2                      SDA=HIGH;
 729   2                      SCL=HIGH;
 730   2                      bitin=SDA;
 731   2                      bytein|=bitin<<(7-i);
 732   2                      SCL=LOW; 
 733   2                      bitin=0;                                
 734   2              }
 735   1              return bytein;
 736   1      }
 737          /*************************************************************************************************
 738          Function        :Clock out an acknowledge bit (low).
 739                          :SCL expected low on entry. Return with SCL, SDA low.
 740          *************************************************************************************************/
 741          /*
 742          void ACK(void)//ACK
 743          {
 744                  SDA=LOW;        
 745                  SCL=HIGH;       
 746                  SCL=LOW;        
 747          }
 748          */
 749          /*************************************************************************************************
 750          Functon         :Clock out a negative acknowledge bit (high).
 751                          :SCL expected low on entry. Return with SCL low, SDA high.
 752          **************************************************************************************************/
 753          void NAK(void)  //no ACK
 754          {
 755   1              SDA=HIGH;
 756   1              SCL=HIGH;
 757   1              SCL=LOW;        
 758   1      }
 759          /**************************************************************************************************
 760          Write to I2C EEPROM
 761          ***************************************************************************************************/
 762          char write_eeprom_bytes(unsigned int add, unsigned char dataout)
 763          {
 764   1              idata unsigned char addressbyte;
 765   1              
 766   1              addressbyte=high_byte(add);
 767   1              
 768   1              I2C_Start();
 769   1              
 770   1              if(I2C_Write(0xA0))
 771   1                      return 0;       
 772   1              
 773   1              if(I2C_Write(addressbyte)) //send address high byte
 774   1                      return 0;
 775   1              
 776   1              if(I2C_Write((unsigned char) add))
 777   1                      return 0;                       
 778   1              
 779   1              if(I2C_Write(dataout))
 780   1                      return 0;
 781   1                      
 782   1              I2C_Stop();
 783   1              Delay_ms(3);
 784   1      
 785   1              return 1;
 786   1      }
 787          /**************************************************************************************************
 788          Read from  I2C EEPROM
 789          ***************************************************************************************************/   
C51 COMPILER V7.06   READERMODULE                                                          09/05/2006 01:45:27 PAGE 14  

 790          unsigned char get_eeprom_bytes (unsigned int add)
 791          {
 792   1              unsigned char addressbyte, datain;
 793   1              
 794   1              addressbyte=high_byte(add);     
 795   1              I2C_Start();    
 796   1      
 797   1              I2C_Write(0xa0);
 798   1              I2C_Write(addressbyte); 
 799   1              I2C_Write((unsigned char) add);
 800   1              I2C_Start();    
 801   1              I2C_Write(0xa1);
 802   1              datain=I2C_Read();      
 803   1              NAK();          //send negative ack
 804   1              I2C_Stop();
 805   1              return datain;
 806   1      }
 807          /**************************************************************************************************
 808          Read the next following bytes
 809          remarks :Dont have to send address again(the fastest way to read bytes) !
 810          ***************************************************************************************************/
 811          unsigned char get_eeprom_bytes1 (void)
 812          {
 813   1              unsigned char datain;
 814   1      
 815   1              I2C_Start();    
 816   1              I2C_Write(0xA1);        
 817   1              datain=I2C_Read();
 818   1              NAK();          //send negative ack
 819   1              I2C_Stop();     
 820   1              
 821   1              return datain;
 822   1      }
 823          /***************************************************************************************************
 824          Page write- write from a given page number
 825          ****************************************************************************************************/
 826          /*
 827          char write_block(unsigned char page, unsigned char *dataout, char count)
 828          {
 829                  idata unsigned int startaddr;
 830                  unsigned char i, addressbyte;
 831                  
 832                  startaddr=page*32;
 833                  addressbyte=high_byte(startaddr);
 834                          
 835                  I2C_Start();
 836                  if(I2C_Write(0xA0))
 837                          return 0;       
 838                  
 839                  if(I2C_Write(addressbyte)) //send address high byte
 840                          return 0;
 841                  
 842                  if(I2C_Write((unsigned char) startaddr))
 843                                  return 0;       
 844                  
 845                          
 846                  for(i=0;i<count;i++)
 847                  {       
 848                          if(I2C_Write(dataout[i]))
 849                                  return 0;
 850                  }
 851                  I2C_Stop();
C51 COMPILER V7.06   READERMODULE                                                          09/05/2006 01:45:27 PAGE 15  

 852                  Delay_ms(2);
 853          
 854                  return 1;
 855          }
 856          */
 857          /**********************************************************************************8
 858          write from a given start address
 859          ***********************************************************************************/
 860          char write_block(unsigned int startaddr, unsigned char *dataout, char count)
 861          {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -