📄 readermodule.lst
字号:
862 1 //idata unsigned int startaddr;
863 1 unsigned char i, addressbyte;
864 1
865 1 //startaddr=page*32;
866 1 addressbyte=high_byte(startaddr);
867 1
868 1 I2C_Start();
869 1 if(I2C_Write(0xA0))
870 1 return 0;
871 1
872 1 if(I2C_Write(addressbyte)) //send address high byte
873 1 return 0;
874 1
875 1 if(I2C_Write((unsigned char) startaddr))
876 1 return 0;
877 1
878 1
879 1 for(i=0;i<count;i++)
880 1 {
881 2 if(I2C_Write(dataout[i]))
882 2 return 0;
883 2 }
884 1 I2C_Stop();
885 1 Delay_ms(2);
886 1
887 1 return 1;
888 1 }
889
890 void ShowErrInMainEntered (void)
891 {
892 1 //put_c('s');
893 1 beepbeep(3);
894 1 Flags.WaitingKey = 1;
895 1 key_count = 0; //kk 25-6-06
896 1 ReloadKeyTimeOut();
897 1
898 1 }
899
900 /************************************************************************************
901 Function :Install this cardno into card database(eeprom)
902 Remarks :searching for database, if card found then reinstall
903 :return 1-successfully install, 0-failed, due to oversize
904 ************************************************************************************/
905 unsigned char InstallThisCard(void)
906 {
907 1 unsigned int cpos;
908 1 unsigned char wr=0;
909 1 unsigned char buf[5];
910 1 unsigned int i; //12/19/2005 10:47PM
911 1
912 1
913 1 if(FindThisCard())//if card already exist, then its must be install new pin in
C51 COMPILER V7.06 READERMODULE 09/05/2006 01:45:27 PAGE 16
914 1 {
915 2 wr=1;
916 2 cpos=cardpos;
917 2 card_exist=1;
918 2 }
919 1 else //if new card so it is the first time install, Pin is set to 0xff
920 1 {
921 2 if(!Flags.EmptySign)
922 2 {
923 3 i=START_CARD_ADD;
924 3 }
925 2 else
926 2 i=cardpos_last;
927 2
928 2
929 2 lockoutcount=0;
930 2 for(cpos=i; cpos<=MAX_CARD_ADD; cpos+=4)
931 2 {
932 3 if(get_eeprom_bytes(cpos)==0xff)
933 3 {
934 4 wr=1;
935 4 gcrec.Lockcount=0;
936 4 break;
937 4 }
938 3 }
939 2
940 2 if(cpos>MAX_CARD_ADD)
941 2 return 0;
942 2 /* //working part, disable on 12/19/2005 10:46PM
943 2 cpos=32;
944 2 lockoutcount=0;
945 2 while(cpos<=MAX_CARD_PAGE)
946 2 {
947 2 if(get_eeprom_bytes(cpos)==0xff) //0xff is the empty byte
948 2 {
949 2 wr=1;
950 2 gcrec.Lockcount=0;
951 2 break;
952 2 }
953 2 cpos+=4;
954 2 }
955 2
956 2 if(cpos>MAX_CARD_PAGE)
957 2 return 0;
958 2 */
959 2 }
960 1
961 1 if(wr)
962 1 {
963 2 //jah version
964 2 if(cpos>cardpos_last)
965 2 {
966 3 cardpos_last=cpos;
967 3 Flags.EmptySign=1;
968 3 }
969 2
970 2 fillintbuffer(buf, 4, cardpos_last);
971 2 buf[4]=0;
972 2 CommPutStr(buf);
973 2
974 2
975 2 write_block(cpos, &gcrec.CardNo[0], 3);
C51 COMPILER V7.06 READERMODULE 09/05/2006 01:45:27 PAGE 17
976 2
977 2 cpos+=1;
978 2
979 2 cpos+=1;
980 2
981 2 cpos+=1;
982 2 write_eeprom_bytes (cpos, lockoutcount);
983 2
984 2 /*
985 2 //put_c('F');
986 2 write_eeprom_bytes (cpos, gcrec.CardNo[0]); //2
987 2 //put_c(gcrec.CardNo[2]);
988 2 cpos+=1;
989 2 //put_c('C');
990 2 write_eeprom_bytes (cpos, gcrec.CardNo[1]);
991 2 //put_c(gcrec.CardNo[1]);
992 2 cpos+=1;
993 2 //put_c('K');
994 2 write_eeprom_bytes (cpos, gcrec.CardNo[2]); //1
995 2 //put_c(gcrec.CardNo[0]);
996 2 cpos+=1;
997 2 write_eeprom_bytes (cpos, lockoutcount);
998 2 */
999 2 return 1;
1000 2 }
1001 1 return 0;
1002 1 }
1003 /*******************************************************************************************
1004 Function :Delete this cardno from card database
1005 Remarks : and delete it by setting all byte to 0xff
1006 return :1-card exist and succefully deleted. 0-card no exist, cannot delete
1007 ********************************************************************************************/
1008 unsigned char DeleteThisCard (void)
1009 {
1010 1 if(FindThisCard ())
1011 1 {
1012 2 write_eeprom_bytes (cardpos, 0xff);
1013 2 cardpos+=1;
1014 2 write_eeprom_bytes (cardpos, 0xff);
1015 2 cardpos+=1;
1016 2 write_eeprom_bytes (cardpos, 0xff);
1017 2 cardpos+=1;
1018 2 write_eeprom_bytes (cardpos, 0xff);
1019 2
1020 2 return 1;
1021 2 }
1022 1 return 0;
1023 1 }
1024 unsigned char JoinNibbletoChar (char* str)
1025 {
1026 1 return (((str[0] << 4) & 0xf0) + str[1]);
1027 1 }
1028 char Process_Card(void)
1029 {
1030 1 char i=0;
1031 1 unsigned long idata cno;
1032 1 if(CardDataIn)
1033 1 {
1034 2 SHD=SLEEP; //12/4/2005 9:36AM
1035 2 /*
1036 2 for(i=0;i<=9;i++)
1037 2 {
C51 COMPILER V7.06 READERMODULE 09/05/2006 01:45:27 PAGE 18
1038 2 if(cardbytein[i]<=0x09) put_c(cardbytein[i]+0x30);
1039 2 else put_c(cardbytein[i]+0x37);
1040 2
1041 2 }
1042 2 put_c('K');
1043 2 */
1044 2 cno = (long) (JoinNibbletoChar (&cardbytein[8]));
1045 2 cno +=((long) (JoinNibbletoChar (&cardbytein[6]))) * 256L;
1046 2 cno +=((long) (JoinNibbletoChar (&cardbytein[4]))* 65536L);
1047 2 if(cno>=1000000L) cno = cno - ((cno / 1000000L)*1000000L); //kk get thru after long been
1048 2 longtos (gcrec.CardNo, &cno); //perplexed by the old way 23/10/04
1049 2 CommPutStr(gcrec.CardNo);
1050 2 Flags.gnewcard = 1;
1051 2 CardDataIn=0;
1052 2 SHD=WAKEUP; //12/4/2005 9:36AM
1053 2 return 1;
1054 2 }
1055 1 return 0;
1056 1 }
1057 void initmcu(void)
1058 {
1059 1 /*------------------------------------------------
1060 1 Setup the serial port for 19200 baud at 14.7456MHz.
1061 1 ------------------------------------------------*/
1062 1 TMOD=0x00; //clear all
1063 1 PCON =0x80; // 0x80 Baudrate double
1064 1 SCON = 0x40; //0x50 /* SCON: mode 1, 8-bit UART, enable rcvr */
1065 1 TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
1066 1 TH1 = 0xF5;// 20Mhz 9600 //252; /* TH1: reload value for 19200 baud @ 16MHz */
1067 1 TR1 = 1; /* TR1: timer 1 run */
1068 1 TI = 1; /* TI: set TI to send first char of UART */
1069 1 ES =0; //1
1070 1
1071 1 //Timer 0, Mode 2 Interrupt configuration
1072 1 //TMOD |=0x02; //set timer0, 8 bit auto reload
1073 1 //TH0 = -146; /* 200us */
1074 1 //TL0 = -146; //interrupt every 25 clock signal (8us each)
1075 1 TMOD |=0x01; // 16 bits timer selected
1076 1 TH0 = 0xff;//(65536 - 146) / 256;
1077 1 TL0 = 0x84;//-123;//(65536 - 146) % 256;
1078 1 ET0 = 1; /* Enable Timer 0 Interrupts */
1079 1 TR0 = 0; /* Start Timer 0 Running */
1080 1 /*-----------------------------------------------
1081 1 Configure INT0 (external interrupt 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -