?? card.h
字號:
#include <x25045.h>
typedef struct{
uchar type;
eth_address dst_mac;
ulong dst_ip; /*要發送的IP地址*/
ulong timer;
uint length;
}conf;
eth_address xdata card_mac;
ulong xdata alert_ip;
ulong xdata gate_ip;
ulong xdata local_ip;
ulong xdata mask;
//ulong xdata card_mm;
uchar xdata *mac;
conf xdata curr_conf;
uint xdata REMO_PORT,LOCAL_PORT;
uint xdata baudrate;
extern uchar xdata *seristart;
extern uchar xdata *seriend;
void init_card(void);
void com_init(void);
void cope_eth(void);
/*網絡數據處理程序*/
void cope_serial(void);
/*串口數據處理程序*/
static uint xdata totalnum,sendnum,recenum;
send_packet(uint length);/*發送數據到串口*/
ulong ulong32(uchar dta1,uchar dta2,uchar dta3,uchar dta4)
{
return(dta1*0x1000000+dta2*0x10000+dta3*0x100+dta4);
}
uchar code setinit[]={'C','X','Q','O','K', 192,168,1,6, 192,168,1,100 ,0,192,168,1,6,36 ,0x1f,0x40,0x23,0x28,0x09,0x60,192,168,1,10,255,255,255,0};
void init_card(void)
{
uchar temp;
uint tempint;
uchar xdata *addr;
for(temp=0;temp<6;temp++)
{
mac[temp]=readbyte(temp);
}
/*參數設置完畢 */
if((mac[0]!='C')||(mac[1]!='X')||(mac[2]!='Q')||(mac[3]!='O')||(mac[4]!='K'))
{
for(temp=0;temp<33;temp++)
{
writebyte(setinit[temp],temp);
}
}
local_ip=ulong32(readbyte(5),readbyte(6),readbyte(7),readbyte(8));
gate_ip=ulong32(readbyte(9),readbyte(10),readbyte(11),readbyte(12));
REMO_PORT = readbyte(19)*0x100+readbyte(20);
LOCAL_PORT = readbyte(21)*0x100 + readbyte(22);
baudrate = readbyte(23)*0x100 + readbyte(24);
alert_ip=ulong32(readbyte(25),readbyte(26),readbyte(27),readbyte(28));
mask = ulong32(readbyte(29),readbyte(30),readbyte(31),readbyte(32));
// gate_ip=ulong32(readbyte(13),readbyte(14),readbyte(15),readbyte(16));
for(temp=0;temp<6;temp++)//mac
{
mac[temp]=readbyte(13+temp);
}
card_mac=*(eth_address xdata *)mac;
/*init com fifo*/
ES = 0;
seristart = SERI_RECE_ADDR;
seriend = SERI_RECE_ADDR;
recenum = 0;
ES = 1;
}
void com_init(void)
{
TMOD=0x21;
SCON=0x58;
PCON=0x00;//baud rate is 4800
switch(baudrate)
{
case 1200:
TL1=0xe8;
TH1=0xe8;//baud rate is 1200 (11.059MHZ)
break;
case 2400:
TL1=0xf4;
TH1=0xf4;//baud rate is 2400 (11.059MHZ)
break;
case 4800:
TL1=0xfa;
TH1=0xfa;//baud rate is 4800 (11.059MHZ)
break;
case 9600:
TL1=0xfd;
TH1=0xfd;//baud rate is 9600 (11.059MHZ)
break;
}
TR1=1;
ES =1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -