📄 stccoinbox.lst
字号:
854 1 Stop();
855 1 if((WaitWriteEnd() == FALSE))
856 1 {
857 2 return FALSE;
858 2 }
C51 COMPILER V7.06 STCCOINBOX 11/10/2007 10:37:46 PAGE 15
859 1 //Delay100us(100);
860 1 return TRUE;
861 1 }
862
863 /********************************************
864 内部函数,输出ACK ,每个字节传输完成,输出ack=0,结束读书据,ack=1;
865 ********************************************/
866 void WriteACK(uchar ack)
867 {
868 1 bSda=ack;
869 1 Delay();
870 1 bScl=1;
871 1 Delay();
872 1 bScl=0;
873 1 }
874 /********************************************
875 内部函数,等待ACK
876 ********************************************/
877 void WaitACK()
878 { uchar errtime=20;
879 1 bSda=1;
880 1 Delay(); /*读ACK*/
881 1 bScl=1;
882 1 Delay();
883 1 while(bSda)
884 1 { errtime--;
885 2 if(!errtime) Stop();
886 2 }
887 1 bScl=0;
888 1 Delay();
889 1 }
890 /********************************************
891 内部函数.输出数据字节
892 入口:B=数据
893 ********************************************/
894 void writebyte(uchar wdata)
895 {
896 1 uchar nCnt;
897 1 for(nCnt=0;nCnt<8;nCnt++)
898 1 {
899 2 if(wdata&0x80) bSda=1;
900 2 else bSda=0;
901 2 wdata<<=1;
902 2 bScl=1;
903 2 Delay();
904 2 bScl=0;
905 2 }
906 1 WaitACK(); //I2C器件或通讯出错,将会退出I2C通讯
907 1 }
908
909 /********************************************
910 内部函数.输入数据
911 出口:B
912 ********************************************/
913 uchar Readbyte()
914 {
915 1 uchar nCnt,bytedata;
916 1 bSda=1;
917 1 for(nCnt=0;nCnt<8;nCnt++)
918 1 {
919 2 bScl=1;
920 2 bytedata<<=1;
C51 COMPILER V7.06 STCCOINBOX 11/10/2007 10:37:46 PAGE 16
921 2 bytedata|=bSda;
922 2 bScl=0;
923 2 Delay();
924 2 }
925 1 return(bytedata);
926 1 }
927 /********************************************
928 输出数据->pcf8563
929 ********************************************/
930 void writeData(uchar address,uchar mdata)
931 {
932 1 Start();
933 1 writebyte(0xa2); /*写命令*/
934 1 writebyte(address); /*写地址*/
935 1 writebyte(mdata); /*写数据*/
936 1 Stop();
937 1 }
938
939 /********************************************
940 输入数据<-pcf8563
941 ********************************************/
942 uchar ReadData(uchar address) /*单字节*/
943 { uchar rdata;
944 1 Start();
945 1 writebyte(0xa2); /*写命令*/
946 1 writebyte(address); /*写地址*/
947 1 Start();
948 1 writebyte(0xa3); /*读命令*/
949 1 rdata=Readbyte();
950 1 WriteACK(1);
951 1 Stop();
952 1 return(rdata);
953 1 }
954
955 void ReadData1(uchar address,uchar count,uchar * buff) /*多字节*/
956 { uchar nCnt;
957 1 Start();
958 1 writebyte(0xa2); /*写命令*/
959 1 writebyte(address); /*写地址*/
960 1 Start();
961 1 writebyte(0xa3); /*读命令*/
962 1 for(nCnt=0;nCnt<count;nCnt++)
963 1 {
964 2 buff[nCnt]=Readbyte();
965 2 if(nCnt<count-1) WriteACK(0);
966 2 }
967 1 WriteACK(1);
968 1 Stop();
969 1 }
970 /********************************************
971 内部函数,读入时间到内部缓冲区
972 ********************************************/
973 void P8563_Read()
974 { uchar idata time[7];
975 1 ReadData1(0x02,0x07,time);
976 1 g8563_Store[0]=time[0]&0x7f;//&0x7f; /*秒*/
977 1 g8563_Store[1]=time[1]&0x7f;//time[1]&0x7f; /*分*/
978 1 g8563_Store[2]=time[2]&0x3f; /*小时*/
979 1 g8563_Store[3]=time[3]&0x3F; /*日*/
980 1 g8563_Store[4]=time[4]&0x07; /*星期*/
981 1 g8563_Store[5]=time[5]&0x1F; /*月*/
982 1 g8563_Store[6]=time[6]&0xFF; /*年*/
C51 COMPILER V7.06 STCCOINBOX 11/10/2007 10:37:46 PAGE 17
983 1 }
984 /********************************************
985 读入时间到内部缓冲区----外部调用
986 ********************************************/
987 void P8563_gettime()
988 {
989 1 P8563_Read();
990 1 if(g8563_Store[0]==0)
991 1 P8563_Read(); /*如果为秒=0,为防止时间变化,再读一次*/
992 1 }
993 /********************************************
994 写时间修改值
995 ********************************************/
996 void P8563_settime()
997 {
998 1 uchar nCnt;
999 1 for(nCnt=3;nCnt<=5;nCnt++) { writeData(nCnt,g8563_Store[nCnt-2]); }
1000 1 writeData(7,g8563_Store[5]);
1001 1 writeData(8,g8563_Store[6]);
1002 1 }
1003 /********************************************
1004 P8563的初始化-----外部调用
1005 ********************************************/
1006 void P8563_init()
1007 {
1008 1 // uchar nCnt;
1009 1 if((ReadData(0xa)&0x3f)!=0x8) /*检查是否第一次启动,是则初始化时间*/
1010 1 {
1011 2 //for(nCnt=0;nCnt<=3;nCnt++) g8563_Store[nCnt]=c8563_Store[nCnt]; /*初始化时间*/
1012 2 P8563_Read();
1013 2 P8563_settime();
1014 2 writeData(0x0,0x00);
1015 2 //writeData(0xa,0x8); /*8:00报警*/
1016 2 //writeData(0x1,0x12); /*报警有效*/
1017 2 writeData(0xd,0x00);
1018 2 }
1019 1 }
1020
1021
1022 /**************************PCF8563**************************************/
1023 /////////////////////////////////////////////////////////
1024
1025 void lcd(void)
1026 {
1027 1 ////////////////
1028 1 if(bDotShow == FALSE) //FALSE//TRUE
1029 1 { DotOff; }
1030 1 else
1031 1 { DotOn; }
1032 1 if((nSpareMoney < nCoinSetValue)&&(T_Status==0)&&(keystatus==0))
1033 1 {
1034 2 if(bShowMoneyTotalPermit==1)
1035 2 {
1036 3 No_DispParameter;MoneyTotalOn;Delay();
1037 3 }
1038 2 else
1039 2 {
1040 3 No_DispParameter;
1041 3 Delay();
1042 3 TimeOn;// MoneyOn;
1043 3 DotOn;
1044 3 }
C51 COMPILER V7.06 STCCOINBOX 11/10/2007 10:37:46 PAGE 18
1045 2 }
1046 1 if(nSpareMoney >= nCoinSetValue)
1047 1 {
1048 2 No_DispParameter;
1049 2 Delay();
1050 2 TimeOn;
1051 2 }
1052 1 if(bPassWordPermit)No_DispParameter;
1053 1 //////////////////////////////////////
1054 1 switch ( nDisCount )
1055 1 {
1056 2 case 0:
1057 2 nLcdDisplay1 = Lcddis[0];
1058 2 nLcdDisplay2 = Lcddis[0];
1059 2 nLcdDisplay2 >>= 4;
1060 2 LcdSendData(0,nLcdDisplay1);
1061 2 LcdSendData(1,nLcdDisplay2);
1062 2 nDisCount = 1;
1063 2 break;
1064 2 case 1:
1065 2 nLcdDisplay1 = Lcddis[1];
1066 2 nLcdDisplay2 = Lcddis[1];
1067 2 nLcdDisplay2 >>= 4;
1068 2 LcdSendData(2,nLcdDisplay1);
1069 2 LcdSendData(3,nLcdDisplay2);
1070 2 nDisCount = 2;
1071 2 break;
1072 2 case 2:
1073 2 nLcdDisplay1 = Lcddis[2];
1074 2 nLcdDisplay2 = Lcddis[2];
1075 2 nLcdDisplay2 >>= 4;
1076 2 LcdSendData(4,nLcdDisplay1);
1077 2 LcdSendData(5,nLcdDisplay2);
1078 2 nDisCount = 3;
1079 2 break;
1080 2 case 3:
1081 2 nLcdDisplay1 = Lcddis[3];
1082 2 nLcdDisplay2 = Lcddis[3];
1083 2 nLcdDisplay2 >>= 4;
1084 2 LcdSendData(6,nLcdDisplay1);
1085 2 LcdSendData(7,nLcdDisplay2);
1086 2 nDisCount = 4;
1087 2 break;
1088 2 case 4:
1089 2 nLcdDisplay1 = Lcddis[4];
1090 2 nLcdDisplay2 = Lcddis[4];
1091 2 nLcdDisplay2 >>= 4;
1092 2 LcdSendData(8,nLcdDisplay1);
1093 2 LcdSendData(9,nLcdDisplay2);
1094 2 nDisCount = 5;
1095 2 break;
1096 2 case 5:
1097 2 nLcdDisplay1 = Lcddis[5];
1098 2 nLcdDisplay2 = Lcddis[5];
1099 2 nLcdDisplay2 >>= 4;
1100 2 LcdSendData(10,nLcdDisplay1);
1101 2 LcdSendData(11,nLcdDisplay2);
1102 2 nDisCount = 6;
1103 2 break;
1104 2 case 6:
1105 2 nLcdDisplay1 = Lcddis[6];
1106 2 nLcdDisplay2 = Lcddis[6];
C51 COMPILER V7.06 STCCOINBOX 11/10/2007 10:37:46 PAGE 19
1107 2 nLcdDisplay2 >>= 4;
1108 2 LcdSendData(12,nLcdDisplay1);
1109 2 LcdSendData(13,nLcdDisplay2);
1110 2 nDisCount = 7;
1111 2 break;
1112 2 case 7:
1113 2 nLcdDisplay1 = Lcddis[7];
1114 2 nLcdDisplay2 = Lcddis[7];
1115 2 nLcdDisplay2 >>= 4;
1116 2 LcdSendData(14,nLcdDisplay1);
1117 2 LcdSendData(15,nLcdDisplay2);
1118 2 nDisCount = 8;
1119 2 break;
1120 2 case 8:
1121 2 nLcdDisplay1 = Lcddis[8];
1122 2 nLcdDisplay2 = Lcddis[8];
1123 2 nLcdDisplay2 >>= 4;
1124 2 LcdSendData(16,nLcdDisplay1);
1125 2 LcdSendData(17,nLcdDisplay2);
1126 2 nDisCount = 9;
1127 2 break;
1128 2 case 9:
1129 2 nLcdDisplay1 = Lcddis[9];
1130 2 nLcdDisplay2 = Lcddis[9];
1131 2 nLcdDisplay2 >>= 4;
1132 2 LcdSendData(18,nLcdDisplay1);
1133 2 LcdSendData(19,nLcdDisplay2);
1134 2 nDisCount = 10;
1135 2 break;
1136 2 case 10:
1137 2 nLcdDisplay1 = Lcddis[10];
1138 2 nLcdDisplay2 = Lcddis[10];
1139 2 nLcdDisplay2 >>= 4;
1140 2 LcdSendData(20,nLcdDisplay1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -