📄 iccpdir.lst
字号:
730 1
731 1 // preparing for transmiting and receiving
732 1 RxWorking = 0;
733 1 TxParity = 0;
734 1 TxNotRx = 0;
735 1
C51 COMPILER V8.00 ICCPDIR 04/23/2009 15:56:19 PAGE 13
736 1 //
737 1 ICCUSEREJECT = 1; // disable eject card
738 1 ICCUSERCLS = 1; // set to input mode
739 1 ICCUSEROVLD = 1; // set to input mode
740 1 ICCIO = 1; // set to input mode
741 1 ICCRST = 0; //
742 1 USERRST = 0;
743 1
744 1 // set transmit and receive interrupt
745 1 SetIntPri(IE1_VECTOR, 3);
746 1
747 1 IT1 = 1; // 下降沿触发
748 1 }
749
750 // power on/off user card and enable/disable clock output
751 void IccUserPower(bit en)
752 {
753 1 // disable clock out
754 1 ICCUSERSCLK = 0;
755 1 ICCUSERCLKC = 0;
756 1
757 1 if(en)
758 1 {
759 2 // VCC on
760 2 ICCUSERVCCC = 0;
761 2 }
762 1 else
763 1 {
764 2 // RST = 0
765 2 USERRST = 0;
766 2 // VCC off
767 2 ICCUSERVCCC = 1;
768 2 }
769 1 }
770
771
772 ///////////////////////////////////////////
773 // for user card mechanical interface
774
775 bit IccUserTest(void)
776 {
777 1 return ICCUSERCLS;
778 1 }
779
780 // eject card
781 bit IccUserEject(void)
782 {
783 1 unsigned char i;
784 1
785 1 ICCUSERCLKC = 0;
786 1 for(i=0; i<6; i++)
787 1 {
788 2 ICCUSEREJECT = 0;
789 2 delay(80);
790 2 ICCUSEREJECT = 1;
791 2 if(!ICCUSERCLS)
792 2 return 1;
793 2 delay(50);
794 2 }
795 1
796 1 return 0;
797 1 }
C51 COMPILER V8.00 ICCPDIR 04/23/2009 15:56:19 PAGE 14
798
799 // get overload status
800 bit IccUserOverLoad(void)
801 {
802 1 static unsigned int ovtime = 0;
803 1
804 1 if(ICCUSEROVLD)
805 1 {
806 2 ovtime = GetTickCount();
807 2 return 0;
808 2 }
809 1 else
810 1 {
811 2 if(GetTickCount() - ovtime >= 20)
812 2 {
813 3 // power off and eject card
814 3 IccUserPower(0);
815 3 IccUserEject();
816 3 return 1;
817 3 }
818 2 else
819 2 return 0;
820 2 }
821 1 }
822
823 // write some bytes and read some bytes
824 bit IccSyncWRWithACK(void *wbuf, int wlen, void *rbuf, int rlen)
825 {
826 1 int i;
827 1
828 1 // start
829 1 IccSyncStart();
830 1
831 1 // write
832 1 for(i=0; i<wlen; i++)
833 1 {
834 2 if(!IccSyncPutCharWaitACK(((unsigned char *)wbuf)[i]))
835 2 return 0;;
836 2 }
837 1
838 1 // read
839 1 if(rlen > 0)
840 1 {
841 2 for(i=0; i<rlen-1; i++)
842 2 {
843 3 // get char and send ACK
844 3 ((unsigned char *)rbuf)[i] = IccSyncGetCharSendACK(1);
845 3 }
846 2 // get last char and send NACK
847 2 ((unsigned char *)rbuf)[i] = IccSyncGetCharSendACK(0);
848 2 }
849 1
850 1 // stop
851 1 IccSyncStop();
852 1
853 1 return 1;
854 1 }
855
856 /*
857 // write some bytes and read some bytes
858 void IccSyncWR(void *wbuf, int wlen, void *rbuf, int rlen)
859 {
C51 COMPILER V8.00 ICCPDIR 04/23/2009 15:56:19 PAGE 15
860 int i;
861
862 // start
863 IccSyncStart();
864
865 // write
866 for(i=0; i<wlen; i++)
867 {
868 IccSyncPutChar(((unsigned char *)wbuf)[i]);
869 }
870
871 // read
872 if(rlen > 0)
873 {
874 for(i=0; i<rlen; i++)
875 {
876 ((unsigned char *)rbuf)[i] = IccSyncGetChar();
877 }
878 }
879
880 // stop
881 IccSyncStop();
882 }
883 */
884
885 // start communication with card
886 void IccSyncStart(void)
887 {
888 1 IccDisable();
889 1
890 1 ICCUSERSCLK = 1; // SCL = 1;
891 1 dummy();
892 1 ICCIO = 0; // SDA = 0;
893 1 ICCUSERSCLK = 0; // SCL = 0;
894 1 }
895
896 // stop communication with card
897 void IccSyncStop(void)
898 {
899 1 ICCIO = 0; // SDA = 0;
900 1 dummy();
901 1 ICCUSERSCLK = 1;
902 1 dummy();
903 1 ICCIO = 1;
904 1 dummy();
905 1 ICCUSERSCLK = 0;
906 1 }
907
908 // write a char to card and wait for ACK/NAK
909 bit IccSyncPutCharWaitACK(unsigned char ch)
910 {
911 1 unsigned char ci;
912 1 bit fret = 1;
913 1
914 1 IccDisable();
915 1
916 1 // send data
917 1 for(ci=0; ci<8; ci++)
918 1 {
919 2 ch <<= 1;
920 2 ICCIO = CY;
921 2 ICCUSERSCLK = 1;
C51 COMPILER V8.00 ICCPDIR 04/23/2009 15:56:19 PAGE 16
922 2 dummy();
923 2 ICCUSERSCLK = 0;
924 2 }
925 1
926 1 // read ACK
927 1 ICCIO = 1;
928 1 ICCUSERSCLK = 1;
929 1 dummy();
930 1 if(ICCIO)
931 1 {
932 2 // NAK!
933 2 fret = 0;
934 2 }
935 1
936 1 // clear SCLK
937 1 ICCUSERSCLK = 0;
938 1
939 1 return fret;
940 1 }
941
942 // read a char from card and write ACK/NAK
943 unsigned char IccSyncGetCharSendACK(bit fack)
944 {
945 1 unsigned char ci;
946 1 unsigned char ch = 0;
947 1
948 1 IccDisable();
949 1
950 1 // read data
951 1 for(ci=0; ci<8; ci++)
952 1 {
953 2 ICCUSERSCLK = 1;
954 2 ch <<= 1;
955 2 if(ICCIO)
956 2 ch |= 0x01;
957 2 ICCUSERSCLK = 0;
958 2 }
959 1
960 1 // send ack or nak
961 1 ICCIO = ~fack;
962 1 ICCUSERSCLK = 1;
963 1 dummy();
964 1 ICCUSERSCLK = 0;
965 1 ICCIO = 1;
966 1
967 1 // return
968 1 return ch;
969 1 }
970
971 void IccSyncPutChar(unsigned char ch)
972 {
973 1 unsigned char ci;
974 1
975 1 IccDisable();
976 1
977 1 for(ci=0; ci<8; ci++)
978 1 {
979 2 ch >>= 1;
980 2 ICCIO = CY;
981 2 ICCUSERSCLK = 1;
982 2 dummy();
983 2 ICCUSERSCLK = 0;
C51 COMPILER V8.00 ICCPDIR 04/23/2009 15:56:19 PAGE 17
984 2 }
985 1 }
986
987 // read a char from card
988 unsigned char IccSyncGetChar(void)
989 {
990 1 unsigned char ci;
991 1 unsigned char ch = 0;
992 1
993 1 IccDisable();
994 1
995 1 ICCUSERSCLK = 0;
996 1
997 1 for(ci=0; ci<8; ci++)
998 1 {
999 2 ICCUSERSCLK = 1;
1000 2 ch >>= 1;
1001 2 if(ICCIO)
1002 2 ch |= 0x80;
1003 2 ICCUSERSCLK = 0;
1004 2 }
1005 1 return ch;
1006 1 }
1007
1008 // reset
1009 int IccSyncReset(void *buf)
1010 {
1011 1 unsigned char ci, bi;
1012 1 unsigned char ch = 0;
1013 1
1014 1 ICCUSERSCLK = 0;
1015 1 ICCUSERCLKC = 0;
1016 1
1017 1 IccDisable();
1018 1
1019 1 ICCIO = 1; // set to input mode
1020 1 USERRST = 0;
1021 1 dummy();
1022 1 USERRST = 1;
1023 1 dummy();
1024 1 ICCUSERSCLK = 1;
1025 1 dummy();
1026 1 ICCUSERSCLK = 0;
1027 1 USERRST = 0;
1028 1
1029 1 for(bi=0; bi<4; bi++)
1030 1 {
1031 2 for(ci=0; ci<8; ci++)
1032 2 {
1033 3 ICCUSERSCLK = 1;
1034 3 ch >>= 1;
1035 3 if(ICCIO)
1036 3 ch |= 0x80;
1037 3 ICCUSERSCLK = 0;
1038 3 }
1039 2 ((unsigned char *)buf)[bi] = ch;
1040 2 }
1041 1 return 4;
1042 1 }
1043
1044 // polling the complete of a processing
1045 bit IccSyncPollingIO(unsigned int tm)
C51 COMPILER V8.00 ICCPDIR 04/23/2009 15:56:19 PAGE 18
1046 {
1047 1 unsigned int starttime = GetTickCount();
1048 1
1049 1 do
1050 1 {
1051 2 ICCUSERSCLK = 0;
1052 2 dummy();
1053 2 ICCUSERSCLK = 1;
1054 2 if(GetTickCount() - starttime >= tm)
1055 2 return 0;
1056 2
1057 2 }while(!ICCIO);
1058 1
1059 1 return 1;
1060 1 }
1061
1062 // send a clock puls
1063 void IccSyncClock(void)
1064 {
1065 1 ICCUSERSCLK = 1;
1066 1 dummy();
1067 1 ICCUSERSCLK = 0;
1068 1 }
1069
1070 /*
1071 void IccSPIWrite(void *buf, int len)
1072 {
1073
1074 }
1075
1076 void IccSPIRead(void *buf, int len)
1077 {
1078
1079 }
1080 */
1081
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2575 ----
CONSTANT SIZE = 4 ----
XDATA SIZE = 7 39
PDATA SIZE = ---- ----
DATA SIZE = 15 19
IDATA SIZE = 64 ----
BIT SIZE = 5 4
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -