📄 tcpip.c
字号:
///////////////////////////////////////////////
//****************HZKK***********************//
//
// TCP/IP TEST V1.0
// Author: Data: 2006-02-18
//
//*******************************************//
///////////////////////////////////////////////
#include "absacc.h"
#include "reg52.h"
#include "intrins.h"
#include "SOCKET1.h"
///////////*******************************************************
void main(void)
{
u_int aa=60000;
int len=0;
u_char state=0;
u_char ii,zone=0 ;
SOCKET s;
s=0;
caliwrfg=0; //cali flag
realtstfg=0;
tcpinitfg=0; //tcp
// scale574b=0;
prginition();
/* while(1)
{_nop_();
}
//
initW3100A(); //port,rest,
InitNetConfig(); //ip
s = 0;
socket(s, SOCK_STREAM, Source_port, 0); ///sock_stream=tcp protocol
NBlisten(s) ; */ //server
//EX1=0 ;
// firenextsp(0x02,0x00,0x00) ;
////////////********************main cycle;
while(1)
{_nop_();
startnewsch();
if(((hvstarsch(0)&0x80)==0x00)&&((hvstarsch(1)&0x80)==0x00)&&((hvstarsch(2)&0x80)==0x00)&&((hvstarsch(3)&0x80)==0x00))
{readtime() ; //calculate time
invertbcdcode();
calcutime(); //
if(caliwrfg8==0x00)
{
testrealdat();
if((XBYTE[add245]&0x40)==0x40)
{
compaelectr();
compatime();
dowithdegre();
}
getpcpauf();
getpcpause();
getpcresume();
changecctocv();
changeccc();
changeccd();
changeall();
changnextcy();
// dispprg();
/////
for(zone=0;zone<zonex;zone++)
{
assemstatus(zone);
if((XBYTE[add245]&0x80)==0x80)
{
calcu2da(zone);
}
buildref(zone);
refrstatus(zone);
}
// pc stop end
if((XBYTE[add245]&0x40)==0x40)
{while(pccomutm>120) //5 min
{for(zone=0;zone<zonex;zone++)
{
sleepall(zone);
}
XBYTE[driadds]=noselect; // disp
_nop_();
XBYTE[dridata]=0x55; //sleep
_nop_();
XBYTE[driadds]=lightdis; //0x97
_nop_();
XBYTE[driadds]=noselect;
pcbreakfg=0x01; //pccomutm
}
if(pcbreakfg!=0)
{
for(zone=0;zone<zonex;zone++)
{statufg(zone)=0x01;
refrstatus(zone);
}
dispprg();
pcbreakfg=0x00;
}
} //pc stop end
}
}
_nop_();
if(closechfg==1) //
{closechxx();
}
if(startchfg==1)
{startchxx();
}
if(realtstfg!=0) //cali
{testcalid();
}
if(caliwrfg!=0) //write at28256
{wrtat256() ;
readat256() ; //
}
delayx(2);
if(timebk(15)==0x5a)
{ initon1390int();
timebk(15)=0x00;
}
_nop_();
/////
//
// if(schendfg(zz)!=0x88) //for cali
// {
/* if(tcpinitfg!=0)
{ Int7_En();
initW3100A(); //port,rest,
s = 0;
InitNetConfig(); //ip
s = 0;
socket(s, SOCK_STREAM, Source_port, 0); ///sock_stream=tcp protocol
NBlisten(s) ; //server
tcpinitfg=0;
} */
}
}
////
void prginition(void)
{uchar zz,ic=0;
uint ii=0;
IE=0;
TCON=0;
///////////////////////////////////////ser int
TMOD=0x20;
TH1=0xff;
TL1=0xff;
PCON=0x80;
SCON=0xe0;//串口方式3,SM2=1,REN=1;//
P1=0x6a ;//0X18; //P1.4=1,P1.3=1 =IN
ET0=0;
EX0=0 ; //OPEN EXTERAL INTX0 FOR POWER
EX1=1 ;
TR1=1;
//ES=1;
ES=0;
EA=0;
m691e=0;
en489=0;
SM2=1;
REN=0;
rets=1;
P1=0x00 ;//0X18; //P1.4=1,P1.3=1 =IN
sdi=1;
drdy=1;
//cs1390=1;
//cs1255=1;
for(zz=0;zz<zonex;zz++)
{
sleepall(zz);
}
//en489=0;
XBYTE[driadds]=noselect; // disp
_nop_();
XBYTE[dridata]=0x55; //sleep 02=red ;03=no,01=green ,00=shuang
_nop_();
XBYTE[driadds]=lightdis; //0x97
_nop_();
XBYTE[driadds]=noselect;
/////////
XBYTE[driadds]=0xff ;
XBYTE[dridata]=0x00 ;// xiao scale //scale574b; //0x80; //d7=1=3a scale574b
_nop_();
XBYTE[driadds]=scale574 ;//scldata; //
_nop_();
_nop_();
XBYTE[driadds]=0xff ;
delay(10000) ;
en509=1;
EA=0;
delay(100);
inition1255() ;
read1255() ;
EA=1;
// }
delay(100);
initon1390();
readtime() ; //calculate time
invertbcdcode();
calcutime(); //
//testrealdat(); //READY DATA FOR PC
/*
RamSource_IP[0]=192;
RamSource_IP[1]=168;
RamSource_IP[2]=123;
RamSource_IP[3]=89;
Source_port=8000;
for(ii=0;ii<4;ii++) //ready sendok
{sendok[ii]=RamSource_IP[ii];
}
sendok[4]=0x33;
sendok[5]=0x88;
ii=6;
temp1bytem1=sumex_Result(sendok,ii);
sendok[6]=temp1bytem1x[3];
sendok[7]=temp1bytem1x[2];
sendok[8]=temp1bytem1x[1];
sendok[9]=temp1bytem1x[0];
for(ii=0;ii<4;ii++) //ready sender
{sender[ii]=RamSource_IP[ii];
}
sender[4]=0x11;
sender[5]=0x44;
ii=6;
temp1bytem1=sumex_Result(sender,ii);
sender[6]=temp1bytem1x[3];
sender[7]=temp1bytem1x[2];
sender[8]=temp1bytem1x[1];
sender[9]=temp1bytem1x[0];
///////////////
Destination_IP[0]=192;
Destination_IP[1]=168;
Destination_IP[2]=123;
Destination_IP[3]=11;
Destination_port=1000;
RamGateway_IP[0]=192;
RamGateway_IP[1]=168;
RamGateway_IP[2]=123;
RamGateway_IP[3]=1;
//
NetparameterRamSubnet_Mask_Value[0]=255;
NetparameterRamSubnet_Mask_Value[1]=255;
NetparameterRamSubnet_Mask_Value[2]=255;
NetparameterRamSubnet_Mask_Value[3]=0;
RamMac_address[0]=0x00;
RamMac_address[1]=0xe0;
RamMac_address[2]=0x03;
RamMac_address[3]=0x09;
RamMac_address[4]=0x07;
RamMac_address[5]=0x03 ; //0x02;
//
timeout1[0]=timela;
timeout1[1]=timeha;
rets=0;
delay(20000) ; */
_nop_();
plostway=0;
lostpstatus=0x66;
RI=0;
SM2=1;
REN=1;
ES=1;
EA=1;
delay(1000);
//plostfag[0]=0x09;
//clrmen();
///////
while(plostway!=0)
{XBYTE[driadds]=noselect; // disp
_nop_();
XBYTE[dridata]=0xff; //no
_nop_();
XBYTE[driadds]=lightdis; //0x97
_nop_();
XBYTE[driadds]=noselect;
testrealdat(); ///////
//delay(5000);
XBYTE[driadds]=noselect; // disp
_nop_();
XBYTE[dridata]=0x55; //sleep
_nop_();
XBYTE[driadds]=lightdis; //0x97
_nop_();
XBYTE[driadds]=noselect;
delay(30000);
}
EA=0;
ii=0;
for(ic=6;ic<15;ic++)
{if(plostfag(ic)==0xa0+ic)
ii+=1; //ii=0x33;
else
{ii=0x00; ///clr men
}
}
if(ii>=0x08)
{
if(plostway==0x01)
ii=0x33; //=01 ,go on 05 =clr
else
ii=0x00;
}
else
ii=0x00;
if(ii==0x33)
{XBYTE[driadds]=0xff ; //wr d and x scale;
XBYTE[dridata]=scale574b; //0x80; //d7=1=3a scale574b
_nop_();
XBYTE[driadds]=scale574 ;//scldata; //
_nop_();
_nop_();
XBYTE[driadds]=0xff ;
for(zz=0;zz<zonex;zz++)
{
if(schendfg(zz)!=0x88)
{refccfg(zz)=0x01;
refcdfg(zz)=0x01;
statufg(zz)=0x01;
for(ic=0;ic<channel;ic++)
da2frefg(zz+ic)=0x01;
assemstatus(zz);
buildref(zz);
refrstatus(zz);
delay(1000);
for(ic=0;ic<channel;ic++)
claimdeg(zz+ic)=0x00;
for(ic=0;ic<channel;ic++)
pause0(zz+ic)=0x00;
}
_nop_();
} //zone
dispprg();
delay(20000);
REN=0;
ES=0;
lostpstatus=0x00;
calcutime();
testrealdat(); ///////
REN=1;
ES=1;
}//if(ii=0x33)
////////
else
{_nop_();
clrmen(); ///clr men
}
_nop_();
for (ic=0;ic<16;ic++)
{ plostfag(ic)=0xa0+ic;
}
//
//
caliwrfg=0; //cali flag
realtstfg=0; //realtstfg=1;
tcpinitfg=0; //tcp
caliwrfg8=0x00;
EX0=1 ; //OPEN EXTERAL INTX0 FOR POWER
EX1=0 ;
RI=0;
SM2=1;
REN=1;
ES=1;
EA=1;
sdi=1;
drdy=1;
}
/*
///////////////////////////////////////////////////
void Int7(void) interrupt 2 //using 2
{
u_char status,s,y,zc,zn;
u_char state=0;
u_char sysstate=0;
u_long aa=3000;
uint len;
uint leny;
s=0;
Int7_Ds(); // INT7 DISABLE
status = INT_REG;
while (status) {
if (status & 0x01)
{ // channel 0 interrupt(sysinit, sockinit, established, closed, timeout, send_ok, recv_ok)
I_STATUS[0] = INT_STATUS(0);
INT_REG = 0x01;
if(I_STATUS[0]==0x04)
{
///&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& P3.3=INT1 chekint1
while (aa--)
{
_nop_();
s=0;
checkint1(); //check int1
state = select(s, SEL_CONTROL);
switch(state)
{
case SOCK_ESTABLISHED: // status established connection
if(sysstate==0)
{
if ((len = select(s, SEL_RECV)) > 0) // Check to receive data
{
if (len > MAX_BUF_SIZE) // When receiving larger data than system buffer,it's processed buffer sized data first.
len = MAX_BUF_SIZE;
len = recv(s, dst_buf, len);
// serilight=0;
// serialsend(dst_buf,len);
// serilight=1;
_nop_();
sysstate=1;
// send(s, dst_buf,len);
//////////
temp1bytem4=sum_Result(dst_buf,len);
if((dst_buf[len-4]==temp1bytem4x[3])&&(dst_buf[len-3]==temp1bytem4x[2])&&(dst_buf[len-2]==temp1bytem4x[1])&&(dst_buf[len-1]==temp1bytem4x[0]))
{switch(dst_buf[7]) //command,0xa0 ,0x50
{case 0xa0:
for(leny=0;leny<len-8;leny++)
nwtm(leny)=dst_buf[leny+8];
leny=10;
send(s, sendok,leny);
break;
// set_time();break;
case 0xa4: //sch
for(leny=0;leny<len-8;leny++)
{//sch_buf[leny]=dst_buf[leny+8];
y=(dst_buf[8+4]&0x03); //sch zone num.
schbuf(y+leny)=dst_buf[leny+10];
hvnewsch(y)=dst_buf[2+8]; //schbuf(zz+0);//0x1; sch type
newschfg(y)=0;
}
_nop_();
leny=10;
send(s, sendok,leny);
_nop_();
// snedokmake();
//leny=12;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -