📄 sfj1.c
字号:
#include <reg51.h>
#include <absacc.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define _Nop() _nop_()
#define TRUE 1
#define FALSE 0
#define CNTR XBYTE[0x7F00]
#define COMD XBYTE[0x7F01]
#define STUS XBYTE[0x7F02]
#define INTR XBYTE[0x7F03]
#define ACOD XBYTE[0x7F04]
#define ACMK XBYTE[0x7F05]
#define BTR0 XBYTE[0x7F06]
#define BTR1 XBYTE[0x7F07]
#define OCTR XBYTE[0x7F08]
#define TXBID0 XBYTE[0x7F0A]
#define TXBID1 XBYTE[0x7F0b]
#define TXBDATA0 XBYTE[0x7F0C]
#define TXBDATA1 XBYTE[0x7F0D]
#define TXBDATA2 XBYTE[0x7F0E]
#define TXBDATA3 XBYTE[0x7F0F]
#define TXBDATA4 XBYTE[0x7F10]
#define TXBDATA5 XBYTE[0x7F11]
#define TXBDATA6 XBYTE[0x7F12]
#define TXBDATA7 XBYTE[0x7F13]
#define RXR0 XBYTE[0x7F14]
#define RXR1 XBYTE[0x7F15]
#define RXRDATA1 XBYTE[0x7F16]
#define RXRDATA2 XBYTE[0x7F17]
#define RXRDATA3 XBYTE[0x7F18]
#define RXRDATA4 XBYTE[0x7F19]
#define RXRDATA5 XBYTE[0x7F1A]
#define RXRDATA6 XBYTE[0x7F1B]
#define RXRDATA7 XBYTE[0x7F1C]
#define RXRDATA8 XBYTE[0x7F1D]
#define MODE XBYTE[0x7F1F]
sfr WDTC=0x9F;
sfr SCONF=0xBF;
sbit ACC0=ACC^0; sbit ACC1=ACC^1; sbit ACC2=ACC^2; sbit ACC3=ACC^3;
sbit ACC4=ACC^4; sbit ACC5=ACC^5; sbit ACC6=ACC^6; sbit ACC7=ACC^7;
ulong earnmoney,earnmoneytemp;
uint earnmoneytemp1;
uchar keyvalue,numkeyvalue;
uchar idata receivebuf[13];
uchar idata displaybuf[16];
uint inputdata[14];
uchar inputpoint;
uint delayl;
uchar idata Num_Buf[5]={0x00,0x00,0x00,0x00,0x00};
uchar Rst_Buf;
bdata uchar a,b;
bdata uchar senddata;
sbit sendbit_0=senddata^0;
uchar i;
uchar j;
uchar ramaddress;
bit Find_Head,Find_Success,ack,Set_Success;
bit presskey,keydoflag,serialflag;
bit pointbit,firstnumflag;
bit cancelstatus;
bit lightflag,countok;
bit workflag,inttimer0;
uchar pointwhere,pointnew;
uchar SYS_STATE;
uchar Serial_Buf_Num,Serial_Buf_NumSum;
uchar Serial_Buf[13];
uchar X_Sum;
uchar T_Cnt;
uint havemoney;
uint setmoney;
bit timeflag,flashflag;
bit moneyflag;
uchar enablesend;
uchar enableauto,currentkind;
uchar receiveflag;
uchar machinestatus;
uchar nodeaddress,sendorder;
uint spendmoney;
uint kindmoney;
uchar idata Sendbuf[4];
uchar dispshift;
uchar flashcount;
uint totalmoney;
uchar serialsend;
bit addflag;
bit searchflag,oldkeyflag;
bit clearflag;
bit flagkeyd;
uchar behindnum;
uchar pointnum3;
uchar flashi;
sbit a_0=a^0; sbit a_1=a^1; sbit a_2=a^2; sbit a_3=a^3;
sbit a_4=a^4; sbit a_5=a^5; sbit a_6=a^6; sbit a_7=a^7;
sbit b_0=b^0; sbit b_1=b^1; sbit b_2=b^2; sbit b_3=b^3;
sbit b_4=b^4; sbit b_5=b^5; sbit b_6=b^6; sbit b_7=b^7;
sbit ALARM=P1^0; sbit sda=P1^1; sbit scl=P1^2; sbit f2led=P1^3;
sbit f1led=P1^4; sbit kindled=P1^5; sbit countled=P1^6; sbit autoled=P1^7;
sbit LOAD=P2^0; sbit DIN=P2^1; sbit CLK=P2^2; sbit P2_3=P2^3;
sbit P2_7=P2^7;
sbit P3_0=P3^0; sbit P3_1=P3^1; sbit key=P3^2; sbit P3_3=P3^3;
sbit dat=P3^4; sbit clk=P3^5; sbit P3_6=P3^6; sbit P3_7=P3^7;
void cansend(void);
void canreceive(void);
void Rst_Wdog(void);
void dispmoney(void);
void numkey(void);
void Start();
void Stop();
void Ack_NoAck(bit askbit);
void SendByte(uchar c);
uchar RcvByte();
bit IRcvStr(uchar sla,uchar suba,uchar *s,uchar no);
bit ISendStr(uchar sla,uchar suba,uchar *s,uchar no);
void delay(uchar time);
void write728x(uchar reg_add, uchar write_data);
uchar read728x(uchar reg_add);
void send_byte(uchar send_byte);
void repeatdisplay(void);
uchar receive_byte(void);
void pointon(void);
void pointoff(void);
void inputmoney(void);
void oldstatus(void);
void send(uchar buf[],uchar len);
uchar Rec_xorsum(uchar buf[],uchar len);
uchar idata pointonvalue[8]={0x27,0x2f,0x37,0x3f,0x67,0x6f,0x77,0x7f};
uchar code pointoffvalue[8]={0xa7,0xaf,0xb7,0xbf,0xe7,0xef,0xf7,0xff};
void main(void)
{
Rst_Buf=SCONF;
if((Rst_Buf&0x80)==0) WDTC=0x85;
else { Rst_Buf=SCONF;
SCONF=Rst_Buf&0x7f;
Rst_Buf=WDTC;
WDTC=Rst_Buf|0x20;
WDTC=0x85;
}
EA=0; ALARM=1; IE=0x00; IP=0x10;
TMOD=0x21; TH1=0xE8; TL1=0xE8;
TH0=-50000/256; TL0=-50000%256;
ET0=1; TR1=1; ES=1; IT0=1; EX0=1;
PCON=0x00; SCON=0x70;
EA=1;
for (delayl=0;delayl<25000;delayl++);
Rst_Wdog();
write728x(0x12,0x80);
timeflag=0; flashcount=0; TR0=1;
moneyflag=0;
keyvalue=45; numkeyvalue=30;
keydoflag=0; Serial_Buf_Num=0;
ramaddress=0xf0;
IRcvStr(0xa0,ramaddress,&receivebuf,1);
nodeaddress=receivebuf[0];
receivebuf[4]=receivebuf[0]/10;
receivebuf[5]=receivebuf[0]%10;
CNTR=0x01;
ACC=CNTR;
while(ACC0!=1) {CNTR=0x01; ACC=CNTR;}
ACOD=nodeaddress;
ACMK=0x80;
BTR0=0x09;
BTR1=0x1c;
OCTR=0x1a;
CNTR=0x00;
ACC=CNTR;
while(ACC0!=0) {CNTR=0; ACC=CNTR;}
ramaddress=0xd0;
IRcvStr(0xa0,ramaddress,&receivebuf,3);
earnmoney=receivebuf[0]*65536+receivebuf[1]*256+receivebuf[2];
earnmoneytemp=earnmoney;
SYS_STATE=0;
presskey=0;
machinestatus=4;
enablesend=1;
pointbit=1; totalmoney=0; firstnumflag=1;
displaybuf[0]=0x0f;
displaybuf[1]=0x1f; displaybuf[2]=0x2f; displaybuf[3]=0x3f;
displaybuf[4]=0x40+receivebuf[4]; displaybuf[5]=0x50+receivebuf[5];
displaybuf[6]=0x60+0x0f; displaybuf[7]=0x70+0x0f;
repeatdisplay();
for(i=0;i<16;i++)
write728x(0x14,displaybuf[i]);
for(i=0;i<3;i++)
{for(delayl=0;delayl<25000;delayl++) ;
Rst_Wdog();
}
displaybuf[0]=0x0d;displaybuf[1]=0x14; displaybuf[4]=0x4f; displaybuf[5]=0x5f;
pointon(); autoled=1; countled=0; kindled=1; f1led=1; f2led=1;
flashflag=1; addflag=0; flagkeyd=0;
while(1)
{Rst_Wdog();
if(inttimer0==1)
{if(timeflag==1)
{if(++T_Cnt>=5){
T_Cnt=0;
timeflag=0;
if(machinestatus!=5)
{flashflag=1;
pointon();
}
enablesend=1;
ES=1;
TR1=1;
write728x(0x14,0x3f);
write728x(0x14,0xbf);
}
}
if(flashflag==1)
{TR0=0; flashcount=flashcount+1;
if(flashcount==5)
{displaybuf[2]=0x2f;displaybuf[3]=0x3f;displaybuf[4]=0x4a; displaybuf[5]=0x5f; displaybuf[6]=0x6f; displaybuf[7]=0x7f;
}
else if(flashcount==10)
{displaybuf[2]=0x2f;displaybuf[3]=0x3f;displaybuf[4]=0x4f; displaybuf[5]=0x5a; displaybuf[6]=0x6f; displaybuf[7]=0x7f;
}
else if(flashcount==15)
{displaybuf[2]=0x2f;displaybuf[3]=0x3f;displaybuf[4]=0x4f; displaybuf[5]=0x5f; displaybuf[6]=0x6a; displaybuf[7]=0x7f;
}
else if(flashcount>=20)
{displaybuf[2]=0x2f;displaybuf[3]=0x3f;displaybuf[4]=0x4f; displaybuf[5]=0x5f; displaybuf[6]=0x6f; displaybuf[7]=0x7a;
flashcount=0;
}
if(flashcount%5==0)
{repeatdisplay();
for(flashi=0;flashi<16;flashi++)
write728x(0x14,displaybuf[flashi]);
}
TR0=1;
}
inttimer0=0;
}
if(presskey==1||oldkeyflag==1)
{if(presskey==1)
{keyvalue=read728x(0x13);
if (keyvalue==0) {keyvalue=36;}
else if((keyvalue>=9)&&(keyvalue<=11)) numkeyvalue=keyvalue-8;
else if((keyvalue>=17)&&(keyvalue<=19)) numkeyvalue=keyvalue-13;
else if((keyvalue>=25)&&(keyvalue<=27)) numkeyvalue=keyvalue-18;
else if (keyvalue==34) {numkeyvalue=0;}
if(keyvalue!=35) clearflag=0;
if ((keyvalue==2)&&(searchflag==0))
{keyvalue=56; ALARM=1;
}
else if ((keyvalue==3)&&(searchflag==0))
{keyvalue=56; ALARM=1;
}
presskey=0; ALARM=0;
}
else if(oldkeyflag==1)
oldkeyflag=0;
if(keyvalue==1)
{pointoff();
receivebuf[3]=(uchar)(earnmoneytemp/100000);
earnmoneytemp=earnmoneytemp-receivebuf[3]*100000;
receivebuf[4]=(uchar)(earnmoneytemp/10000);
earnmoneytemp1=(uint)(earnmoneytemp-receivebuf[4]*10000);
receivebuf[5]=(uchar)(earnmoneytemp1/1000);
earnmoneytemp1=(ulong)(earnmoneytemp1-receivebuf[5]*1000);
receivebuf[6]=(uchar)(earnmoneytemp1/100);
earnmoneytemp1=(ulong)(earnmoneytemp1-receivebuf[6]*100);
receivebuf[7]=(uchar)(earnmoneytemp1/10);
receivebuf[8]=(uchar)(earnmoneytemp1%10);
if(receivebuf[3]==0)
{receivebuf[3]=0x0f;
if((receivebuf[5]==0)&&(receivebuf[4]==0)) receivebuf[5]=0x0f;
if(receivebuf[4]==0) receivebuf[4]=0x0f;
}
displaybuf[0]=0x0f; displaybuf[1]=0x1f;
displaybuf[2]=0x20+receivebuf[3]; displaybuf[3]=0x30+receivebuf[4];
displaybuf[4]=0x40+receivebuf[5]; displaybuf[5]=0x50+receivebuf[6];
displaybuf[6]=0x60+receivebuf[7]; displaybuf[7]=0x70+receivebuf[8];
repeatdisplay();
for(i=0;i<16;i++)
write728x(0x14,displaybuf[i]);
write728x(0x18,0x2f); write728x(0x18,0x6f);
flashflag=0; searchflag=1;
}
else if((keyvalue==2)&&(searchflag==1))
{oldstatus();
}
else if((keyvalue==3)&&(searchflag==1))
{clearflag=1;
}
else if(keyvalue==8)
{autoled=1; countled=0; kindled=1; f1led=1; f2led=1;
enablesend=1; SYS_STATE=0;
displaybuf[0]=0x0d; displaybuf[1]=0x14; displaybuf[2]=0x2f; displaybuf[3]=0x3f;
displaybuf[4]=0x4f; displaybuf[5]=0x5f; displaybuf[6]=0x6a; displaybuf[7]=0x7f;
repeatdisplay();
for(i=0;i<16;i++)
write728x(0x14,displaybuf[i]);
pointon();
machinestatus=4; pointbit=1; totalmoney=0;
addflag=0; searchflag=0; flagkeyd=0;
flashflag=1;
firstnumflag=1;
if(workflag==1) {workflag=0; timeflag=1; }
}
else if(keyvalue==16)
{autoled=1; countled=1; kindled=0; f1led=1; f2led=1;
enablesend=1; SYS_STATE=0;
displaybuf[0]=0x0d; displaybuf[1]=0x13; displaybuf[2]=0x2f; displaybuf[3]=0x3f;
displaybuf[4]=0x4f; displaybuf[5]=0x5f; displaybuf[6]=0x6a; displaybuf[7]=0x7f;
repeatdisplay();
for(i=0;i<16;i++)
write728x(0x14,displaybuf[i]);
pointon(); flashflag=1;
searchflag=0; flagkeyd=0;
machinestatus=3;
if(workflag==1)
{workflag=0;
timeflag=1;
}
}
else if(keyvalue==36)
{machinestatus=5;
autoled=0;
countled=1;
kindled=1;
f1led=1;
f2led=1;
enablesend=1;
flashflag=0;
SYS_STATE=0;
flagkeyd=0;
pointoff();
IRcvStr(0xa0,2,&receivebuf,2);
spendmoney=(uint)(receivebuf[0]*256+receivebuf[1]);
pointbit=1;
//behindnum=0;
firstnumflag=1;
displaybuf[0]=0x0d; displaybuf[1]=0x15; displaybuf[2]=0x2f;
dispmoney();
searchflag=0;
if(workflag==1)
{workflag=0;
timeflag=1;
}
}
else if((keyvalue==20)&&(receiveflag!=3))
{
if(machinestatus==3)
{flashflag=0;
pointoff();
displaybuf[0]=0x0d; displaybuf[1]=0x13; displaybuf[2]=0x2a; displaybuf[3]=0x3f;
displaybuf[4]=0x4f; displaybuf[5]=0x5f; displaybuf[6]=0x6f; displaybuf[7]=0x7f;
repeatdisplay();
for(i=0;i<16;i++)
write728x(0x14,displaybuf[i]);
enableauto=1;
}
else if((machinestatus==4)&&(flashflag==0))
{
numkey();
}
}
else if(keyvalue==12)
{if(searchflag==1)
{oldstatus();
searchflag=0;
}
if((cancelstatus==1)&&(flashflag==0))
{pointoff();
displaybuf[3]=havemoney/10000;
displaybuf[4]=(havemoney-displaybuf[3]*10000)/1000;
displaybuf[5]=(havemoney-displaybuf[3]*10000-displaybuf[4]*1000)/100;
displaybuf[6]=(havemoney-displaybuf[3]*10000-displaybuf[4]*1000-displaybuf[5]*100)/10;
displaybuf[7]=havemoney%10;
if((displaybuf[3]==0)&&(displaybuf[4]==0)) displaybuf[4]=0x0f;
if(displaybuf[3]==0) displaybuf[3]=0x0f;
write728x(0x18,0x2f); write728x(0x18,0x6f);
displaybuf[3]=0x30+displaybuf[3]; displaybuf[4]=0x40+displaybuf[4]; displaybuf[5]=0x50+displaybuf[5];
displaybuf[6]=0x60+displaybuf[6]; displaybuf[7]=0x70+displaybuf[7];
repeatdisplay();
for(i=0;i<16;i++)
write728x(0x14,displaybuf[i]);
cancelstatus=0;
pointbit=1;
firstnumflag=1;
kindmoney=0;
totalmoney=0;
receivebuf[4]=0;
}
else if((cancelstatus==0)&&(flashflag==0))
{
havemoney=0;
searchflag=0;
workflag=0;
if(machinestatus==3)
{displaybuf[0]=0x0d; displaybuf[1]=0x13; displaybuf[2]=0x2f; displaybuf[3]=0x3f;
repeatdisplay();
for(i=0;i<16;i++)
write728x(0x14,displaybuf[i]);
enableauto=0;
kindmoney=0;
timeflag=1;
receiveflag=0;
}
else if((machinestatus==4)&&(flagkeyd==0))
{displaybuf[0]=0x0d;
displaybuf[1]=0x14;
pointbit=1;
displaybuf[2]=0x2f; displaybuf[3]=0x3f; displaybuf[4]=0x4f; displaybuf[5]=0x5f;
displaybuf[6]=0x6f; displaybuf[7]=0x7f;
repeatdisplay();
for(i=0;i<16;i++)
write728x(0x14,displaybuf[i]);
flashflag=1;
for(j=0;j<8;j++)
{write728x(0x18,pointonvalue[j]);
}
firstnumflag=1;
receiveflag=0;
timeflag=1;
}
}
if(machinestatus==5)
{pointoff();
pointbit=1;
firstnumflag=1;
IRcvStr(0xa0,2,&receivebuf,2);
spendmoney=(uint)(receivebuf[0]*256+receivebuf[1]);
dispmoney();
}
}
else if(keyvalue==35)
{if((machinestatus==4)&&(countok==1))
{
inputmoney();
inputdata[inputpoint]=setmoney;
if(inputpoint==0)
{totalmoney=setmoney;
}
else
{
for(i=0;i<=inputpoint;i++)
{if(inputdata[i]==1)
{inputdata[i+1]=inputdata[i+1]/100;
inputdata[i-1]=inputdata[i-1]*inputdata[i+1];
for(j=i;j<=inputpoint;j++)
inputdata[j]=inputdata[j+2];
inputpoint=inputpoint-2;
}
}
for(i=0;i<=inputpoint;i++)
{totalmoney=totalmoney+inputdata[i];
}
spendmoney=totalmoney;
dispmoney();
ALARM=1;
for(delayl=0;delayl<25000;delayl++) ;
Rst_Wdog();
}
moneyflag=0;
firstnumflag=1;
pointbit=1;
behindnum=0;
if((totalmoney>0)&&(totalmoney<30000))
{countok=0;
receivebuf[4]=totalmoney/10000;
receivebuf[5]=(totalmoney-receivebuf[4]*10000)/1000;
receivebuf[6]=(totalmoney-receivebuf[4]*10000-receivebuf[5]*1000)/100;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -